mirror of
https://github.com/quatalog/site.git
synced 2025-01-27 06:56:48 +00:00
Typo, also forgot to push a file
This commit is contained in:
parent
2883516995
commit
572c19e698
65
js/search.js
Normal file
65
js/search.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
// parses URL params
|
||||
const params = window
|
||||
.location
|
||||
.search
|
||||
.slice(1)
|
||||
.split("&")
|
||||
.map(p => p.split("="))
|
||||
.reduce((obj,[key,value]) =>
|
||||
({ ...obj, [key]: decodeURIComponent(value) }),
|
||||
{}
|
||||
);
|
||||
|
||||
const search_term = params["search"];
|
||||
|
||||
const getSVG = function(name) {
|
||||
return '<svg><use href="./icons.svg#'+name+'"></use></svg>';
|
||||
}
|
||||
|
||||
const fuzzy_search_config = {
|
||||
limit: 25,
|
||||
includeScore: true,
|
||||
ignoreLocation: true,
|
||||
useExtendedSearch: true,
|
||||
threshold: 0.01,
|
||||
keys: [
|
||||
{
|
||||
name: 'code',
|
||||
weight: 0.1
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
weight: 0.1
|
||||
},
|
||||
{
|
||||
name: 'name',
|
||||
weight: 0.8
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const display_search_results = function(searchable_catalog) {
|
||||
const fuse = new Fuse(searchable_catalog,fuzzy_search_config);
|
||||
console.log("Searching for " + search_term + "...");
|
||||
const results = fuse.search(search_term,{limit:fuzzy_search_config.limit});
|
||||
const table = document.getElementById("searchResultsContainer");
|
||||
results.forEach(function(search_entry) {
|
||||
const entry = search_entry.item;
|
||||
const tr = table.insertRow(-1);
|
||||
tr.innerHTML += '<a href="courses/'
|
||||
+ entry.code + '">'
|
||||
+ '<h3><div><span class="courseName">'
|
||||
+ entry.name
|
||||
+ '</span><span class="courseCode">'
|
||||
+ entry.code + "</span></div></h3>"
|
||||
+ "<p>" + entry.description + "</p>" + '\n';
|
||||
});
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
// smart quotes
|
||||
document.getElementById("searchTerm").innerHTML = "“" + search_term + "”";
|
||||
fetch("searchable_catalog.json")
|
||||
.then(r => r.json())
|
||||
.then(display_search_results);
|
||||
}
|
39
search.html
Normal file
39
search.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<title id="title">Quatalog Search</title>
|
||||
|
||||
<link rel="shortcut icon" href="./favicon/quatalogIcon.png">
|
||||
<link rel="icon" href="./favicon/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="./favicon/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="./favicon/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="./favicon/favicon-16x16.png">
|
||||
<link rel="manifest" href="./favicon/site.webmanifest">
|
||||
|
||||
<meta property="og:title" content="Quatalog"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:url" content="https://quatalog.com"/>
|
||||
<meta property="og:description" content="Quatalog Search"/>
|
||||
<meta property="og:image" content="https://quatalog.com/images/quatalogVWordmarkBacking.png"/>
|
||||
<meta property="og:image:width" content="512"/>
|
||||
<meta property="og:image:height" content="256"/>
|
||||
<meta property="og:image:alt" content="Quatalog wordmark"/>
|
||||
|
||||
<script src="js/fuse.js"></script>
|
||||
<script src="js/search.js"></script>
|
||||
<script src="js/search_helper.js"></script>
|
||||
<link rel="stylesheet" href="./css/common.css"/>
|
||||
<link rel="stylesheet" href="./css/search.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qlog-header">
|
||||
<a id="qlog-wordmark" href="./"><svg><use href="./images/quatalogHWordmark.svg#QuatalogHWordmark"></use></svg></a>
|
||||
<form onsubmit="search_helper(event)">
|
||||
<input type="text" id="search" class="header-search" placeholder="Search...">
|
||||
</form>
|
||||
</div>
|
||||
<h1 id="searchTitle">
|
||||
Search results for <span id="searchTerm"></span>
|
||||
</h1>
|
||||
<table id="searchResultsContainer">
|
||||
</table>
|
||||
</body>
|
Loading…
Reference in a new issue