Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HCC docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Holland Computing Center
HCC docs
Merge requests
!44
Horrible JavaScript search redirector, mk 2
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Horrible JavaScript search redirector, mk 2
redir
into
master
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
John Thiltges
requested to merge
redir
into
master
6 years ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
Turns out that no magic is needed. Just dump JS into markdown.
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
ad901e67
1 commit,
6 years ago
2 files
+
75
−
70
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
content/redirector.md
+
75
−
1
Options
@@ -2,4 +2,78 @@
title
:
"
Redirector"
---
<script>
{{- readFile "static/js/docs-redirector.js" | safeJS -}}
</script>
<script>
// Redirector for hcc-docs links
// Search for URL parameter 'q' and redirect to top match
var lunrIndex;
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('
&
'
);
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] === variable) {
return decodeURIComponent(pair[1].replace(/\+/g, '%20'));
}
}
}
// Initialize lunrjs using our generated index file
function initLunr() {
// First retrieve the index file
return $.getJSON(baseurl + "/index.json")
.done(function(index) {
pagesIndex = index;
// Set up lunrjs by declaring the fields we use
// Also provide their boost level for the ranking
lunrIndex = new lunr.Index
lunrIndex.ref("uri");
lunrIndex.field('title', {
boost: 15
});
lunrIndex.field('tags', {
boost: 10
});
lunrIndex.field("content", {
boost: 5
});
// Feed lunr with each file and let lunr actually index them
pagesIndex.forEach(function(page) {
lunrIndex.add(page);
});
lunrIndex.pipeline.remove(lunrIndex.stemmer)
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.error("Error getting Hugo index file:", err);
});
}
function search(query) {
// Find the item in our index corresponding to the lunr one to have more info
return lunrIndex.search(query).map(function(result) {
return pagesIndex.filter(function(page) {
return page.uri === result.ref;
})[0];
});
}
initLunr().then(function() {
var searchTerm = getQueryVariable('q');
// Replace non-word chars with space. lunr doesn't like quotes.
searchTerm = searchTerm.replace(/[
\W
_]+/g," ");
var results = search(searchTerm);
if (!results.length) {
window.location = baseurl;
} else {
window.location = results[0].uri;
}
});
</script>
Loading