Skip to content

Commit d6236ae

Browse files
committed
new search box
1 parent 0de8b85 commit d6236ae

14 files changed

+256
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
__site/
33
node_modules/
44
Manifest.toml
5+
.vscode/

Learning/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Learning Materials
2+
3+
This page contains a series of materials for learning quantum information, many-body physics and scientific computing. These materials target students at the Hong Kong University of Science and Technology (Guangzhou) and are freely available to the public.
4+
5+
## Videos
6+
7+
~~~
8+
<iframe width="560" height="315" src="https://www.youtube.com/embed/eGpDw8tVG3c?si=xOBU69a4aZ66fnd8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
9+
~~~
10+
11+
## Books
12+
- Quantum computation and quantum information
13+
- Quantum computation and quantum information. Nielsen M A, Chuang I L. Cambridge university press, 2010.
14+
15+
- Computational complexity
16+
- The nature of computation. Moore C, Mertens S. OUP Oxford, 2011.
17+
18+
- Scientific computing
19+
- Matrix computations. Golub G H, Van Loan C F. JHU press, 2013.
20+
- Exact exponential algorithms. Fedor V. Fomin , Dieter Kratsch. Springer, 2010.
21+
22+
## Learn Programming
23+
The following resources are used for Julia programming language training:
24+
- [Modern Julia Workflows](https://modernjuliaworkflows.github.io/)
25+
- [Think Julia: How to Think Like a Computer Scientist](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html)
26+
- [GitHub: JuliaComputing/Training](https://github.com/JuliaComputing/Training)

ReadingList/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Reading List

TrainingCamps/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++
2-
title = "Past Events"
2+
title = "Past Events"
33
+++
44

55
This page contains a series of materials for training students in quantum information, many-body physics and scientific computing. These materials target students at the Hong Kong University of Science and Technology (Guangzhou) and are freely available to the public.

_layout/foot.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ga('send', 'pageview');
3030
</script>
3131
<script async src=https://www.google-analytics.com/analytics.js></script>
32+
<script src="/libs/lunr/lunr.min.js"></script>
3233

3334
</body>
3435
</html>

_layout/head.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ <h1>{{title}}</h1>
3535
<br><br>
3636
{{end}}{{end}}
3737
<!-- Content appended here -->
38+
<!doctype html>
39+
<!-- first few lines ... -->
40+
<script src="/libs/lunr/lunr.min.js"></script>
41+
<script src="/libs/lunr/lunr_index.js"></script>
42+
<script src="/libs/lunr/lunrclient.min.js"></script>
43+
</head>
44+
<!-- ... -->
45+
<form id="lunrSearchForm" name="lunrSearchForm">
46+
<input class="search-input" name="q" placeholder="Enter search term" type="text">
47+
<input type="submit" value="Search" formaction="/search/index.html">
48+
</form>

_layout/header.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
<nav class="navbar navbar-expand-lg navbar-light justify-content-center">
33
<ul class="navbar-nav">
44
<li class="nav-item {{ispage index}}active{{end}}"><a class="nav-link" href="/"><i data-feather="home"></i>Home</a></li>
5-
<li class="nav-item {{ispage post/*}}active{{end}}"><a class="nav-link" href="/TrainingCamps/"><i data-feather="file-text"></i>Training Camps</a></li>
6-
<li class="nav-item {{ispage post/*}}active{{end}}"><a class="nav-link" href="/NextEvent/"><i data-feather="book-open"></i>Next Events</a></li>
5+
<li class="nav-item {{ispage ReadingList/*}}active{{end}}"><a class="nav-link" href="/ReadingList/"><i data-feather="file-text"></i>Reading</a></li>
6+
<li class="nav-item {{ispage Learning/*}}active{{end}}"><a class="nav-link" href="/Learning/"><i data-feather="book-open"></i>Learning</a></li>
7+
<li class="nav-item {{ispage TrainingCamps/*}}active{{end}}"><a class="nav-link" href="/TrainingCamps/"><i data-feather="file-text"></i>Training Camps</a></li>
8+
<li class="nav-item {{ispage NextEvent/*}}active{{end}}"><a class="nav-link" href="/NextEvent/"><i data-feather="bell"></i>Next Events</a></li>
79
</ul>
810
</nav>
911
</div>

_layout/style_adjustments.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,11 @@
8383
margin: 0
8484
}
8585

86+
.result-title a { text-decoration: none; }
87+
.result-title a:hover { text-decoration: underline; }
88+
.result-preview { color: #808080; }
89+
.resultCount { color: #808080; }
90+
.result-query { font-weight: bold; }
91+
#lunrSearchForm { margin-top: 1em; }
92+
8693
</style>

_libs/lunr/build_index.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
var path = require("path");
2+
var fs = require("fs");
3+
var lunr = require("lunr");
4+
var cheerio = require("cheerio");
5+
6+
// don't modify this, it'll be modified on the fly by lunr() in Franklin
7+
const PATH_PREPEND = "..";
8+
9+
const HTML_FOLDER = "../../__site";
10+
const OUTPUT_INDEX = "lunr_index.js";
11+
12+
function isHtml(filename) {
13+
lower = filename.toLowerCase();
14+
return (lower.endsWith(".htm") || lower.endsWith(".html"));
15+
}
16+
17+
function findHtml(folder) {
18+
if (!fs.existsSync(folder)) {
19+
console.log("Could not find folder: ", folder);
20+
return;
21+
}
22+
var files = fs.readdirSync(folder);
23+
var htmls = [];
24+
for (var i = 0; i < files.length; i++) {
25+
var filename = path.join(folder, files[i]);
26+
var stat = fs.lstatSync(filename);
27+
if (stat.isDirectory()) {
28+
if (stat == "assets" || stat == "css" || stat == "libs" ) {
29+
continue
30+
}
31+
var recursed = findHtml(filename);
32+
for (var j = 0; j < recursed.length; j++) {
33+
recursed[j] = path.join(files[i], recursed[j]).replace(/\\/g, "/");
34+
}
35+
htmls.push.apply(htmls, recursed);
36+
}
37+
else if (isHtml(filename)){
38+
htmls.push(files[i]);
39+
};
40+
};
41+
return htmls;
42+
};
43+
44+
function readHtml(root, file, fileId) {
45+
var filename = path.join(root, file);
46+
var txt = fs.readFileSync(filename).toString();
47+
var $ = cheerio.load(txt);
48+
var title = $("title").text();
49+
if (typeof title == 'undefined') title = file;
50+
var body = $("body").text()
51+
if (typeof body == 'undefined') body = "";
52+
53+
var data = {
54+
"id": fileId,
55+
"l": filename,
56+
"t": title,
57+
"b": body
58+
}
59+
return data;
60+
}
61+
62+
function buildIndex(docs) {
63+
var idx = lunr(function () {
64+
this.ref('id');
65+
this.field('t'); // title
66+
this.field('b'); // body
67+
docs.forEach(function (doc) {
68+
this.add(doc);
69+
}, this);
70+
});
71+
return idx;
72+
}
73+
74+
function buildPreviews(docs) {
75+
var result = {};
76+
for (var i = 0; i < docs.length; i++) {
77+
var doc = docs[i];
78+
result[doc["id"]] = {
79+
"t": doc["t"],
80+
"l": doc["l"].replace(/^\.\.\/\.\.\/__site/gi, '/' + PATH_PREPEND)
81+
}
82+
}
83+
return result;
84+
}
85+
86+
function main() {
87+
files = findHtml(HTML_FOLDER);
88+
var docs = [];
89+
for (var i = 0; i < files.length; i++) {
90+
docs.push(readHtml(HTML_FOLDER, files[i], i));
91+
}
92+
var idx = buildIndex(docs);
93+
var prev = buildPreviews(docs);
94+
var js = "const LUNR_DATA = " + JSON.stringify(idx) + ";\n" +
95+
"const PREVIEW_LOOKUP = " + JSON.stringify(prev) + ";";
96+
fs.writeFile(OUTPUT_INDEX, js, function(err) {
97+
if(err) {
98+
return console.log(err);
99+
}
100+
});
101+
}
102+
103+
main();

_libs/lunr/lunr.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_libs/lunr/lunr_index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_libs/lunr/lunrclient.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// This file and its minified version is adapted from https://github.com/BLE-LTER/Lunr-Index-and-Search-for-Static-Sites which is unlicensed.
2+
//
3+
4+
"use strict";
5+
6+
var LUNR_CONFIG = {
7+
"resultsElementId": "searchResults", // Element to contain results
8+
"countElementId": "resultCount" // Element showing number of results
9+
};
10+
11+
12+
// Get URL arguments
13+
function getParameterByName(name) {
14+
var url = window.location.href;
15+
name = name.replace(/[\[\]]/g, "\\$&");
16+
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
17+
results = regex.exec(url);
18+
if (!results) return null;
19+
if (!results[2]) return "";
20+
return decodeURIComponent(results[2].replace(/\+/g, " "));
21+
}
22+
23+
24+
// Parse search results into HTML
25+
function parseLunrResults(results) {
26+
var html = [];
27+
for (var i = 0; i < results.length; i++) {
28+
var id = results[i]["ref"];
29+
var item = PREVIEW_LOOKUP[id]
30+
var title = item["t"];
31+
var preview = item["p"];
32+
var link = item["l"].replace("__site/", "");
33+
var result = ('<li><span class="result-title"><a href="' + link + '">'
34+
+ title + '</a></span>');
35+
html.push(result);
36+
}
37+
if (html.length) {
38+
html.join("");
39+
return '<ul>'+html+'</ul>'
40+
}
41+
else {
42+
return "";
43+
}
44+
}
45+
46+
47+
function escapeHtml(unsafe) {
48+
return unsafe
49+
.replace(/&/g, "&amp;")
50+
.replace(/</g, "&lt;")
51+
.replace(/>/g, "&gt;")
52+
.replace(/"/g, "&quot;")
53+
.replace(/'/g, "&#039;");
54+
}
55+
56+
57+
function showResultCount(total) {
58+
var element = document.getElementById(LUNR_CONFIG["countElementId"])
59+
if (element !== null) {
60+
element.innerHTML = total + ".";
61+
}
62+
}
63+
64+
65+
function searchLunr(query) {
66+
var idx = lunr.Index.load(LUNR_DATA);
67+
// Write results to page
68+
var results = idx.search(query);
69+
var resultHtml = parseLunrResults(results);
70+
var elementId = LUNR_CONFIG["resultsElementId"];
71+
document.getElementById(elementId).innerHTML = resultHtml;
72+
// Write the number of results
73+
showResultCount(results.length);
74+
}
75+
76+
77+
// When the window loads, read query parameters and perform search
78+
window.onload = function() {
79+
var query = getParameterByName("q");
80+
if (query != "" && query != null) {
81+
document.forms.lunrSearchForm.q.value = query;
82+
searchLunr(query);
83+
} else {
84+
// empty query: show 0 results (no query)
85+
showResultCount("0 (empty query)");
86+
}
87+
document.getElementById("focus").focus();
88+
};

_libs/lunr/lunrclient.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

search.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@def title = "Search ⋅ Quantum Bay"
2+
3+
## Search
4+
5+
Number of results found: ~~~<span id="resultCount"></span>~~~
6+
7+
~~~
8+
<div id="searchResults"></div>
9+
~~~

0 commit comments

Comments
 (0)