refactor: use js modules
parent
842e243241
commit
5e93038023
|
@ -87,7 +87,7 @@ def htmlOutput (result : AnalyzerResult) (root : String) : IO Unit := do
|
|||
FS.writeFile (basePath / "nav.js") navJs
|
||||
FS.writeFile (basePath / "search.js") searchJs
|
||||
FS.writeFile (basePath / "mathjax-config.js") mathjaxConfigJs
|
||||
FS.writeFile (basePath / "site-root.js") s!"siteRoot = \"{config.root}\"";
|
||||
FS.writeFile (basePath / "site-root.js") s!"export const SITE_ROOT = \"{config.root}\";";
|
||||
for (module, content) in result.moduleInfo.toArray do
|
||||
let moduleHtml := ReaderT.run (moduleToHtml content) config
|
||||
let path := moduleNameToFile basePath module
|
||||
|
|
|
@ -26,9 +26,10 @@ def baseHtmlArray (title : String) (site : Array Html) : HtmlM Html := do
|
|||
<link rel="shortcut icon" href={s!"{←getRoot}favicon.ico"}/>
|
||||
<link rel="prefetch" href={s!"{←getRoot}searchable_data.bmp"}/>
|
||||
|
||||
<script defer="true" src={s!"{←getRoot}site-root.js"}></script>
|
||||
<script defer="true" src={s!"{←getRoot}nav.js"}></script>
|
||||
<script defer="true" src={s!"{←getRoot}search.js"}></script>
|
||||
<script type="module" src={s!"{←getRoot}site-root.js"}></script>
|
||||
<script type="module" src={s!"{←getRoot}nav.js"}></script>
|
||||
<script type="module" src={s!"{←getRoot}search.js"}></script>
|
||||
|
||||
<script defer="true" src={s!"{←getRoot}mathjax-config.js"}></script>
|
||||
<script defer="true" src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
|
||||
<script defer="true" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { SITE_ROOT } from "./site-root.js";
|
||||
import { loadDecls, getMatches } from "./search.js";
|
||||
|
||||
// Persistent expansion cookie for the file tree
|
||||
// ---------------------------------------------
|
||||
|
||||
|
@ -106,7 +109,7 @@ if (tse != null) {
|
|||
// Simple declaration search
|
||||
// -------------------------
|
||||
|
||||
const declURL = new URL(`${siteRoot}searchable_data.bmp`, window.location);
|
||||
const declURL = new URL(`${SITE_ROOT}searchable_data.bmp`, window.location);
|
||||
const getDecls = (() => {
|
||||
let decls;
|
||||
return () => {
|
||||
|
@ -192,7 +195,7 @@ searchInput.addEventListener('input', async (ev) => {
|
|||
const d = sr.appendChild(document.createElement('a'));
|
||||
d.innerText = decl;
|
||||
d.title = decl;
|
||||
d.href = `${siteRoot}find/${decl}`;
|
||||
d.href = `${SITE_ROOT}find/${decl}`;
|
||||
}
|
||||
sr.setAttribute('state', 'done');
|
||||
oldSR.replaceWith(sr);
|
||||
|
@ -222,7 +225,7 @@ if (howabout) {
|
|||
for (const {decl} of results) {
|
||||
const li = ul.appendChild(document.createElement('li'));
|
||||
const a = li.appendChild(document.createElement('a'));
|
||||
a.href = `${siteRoot}find/${decl}`;
|
||||
a.href = `${SITE_ROOT}find/${decl}`;
|
||||
a.appendChild(document.createElement('code')).innerText = decl;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,11 +22,11 @@ function matchCaseSensitive(declName, lowerDeclName, pat) {
|
|||
}
|
||||
}
|
||||
|
||||
function loadDecls(searchableDataCnt) {
|
||||
export function loadDecls(searchableDataCnt) {
|
||||
return searchableDataCnt.map(({name, description}) => [name, name.toLowerCase(), description.toLowerCase()])
|
||||
}
|
||||
|
||||
function getMatches(decls, pat, maxResults = 30) {
|
||||
export function getMatches(decls, pat, maxResults = 30) {
|
||||
const lowerPats = pat.toLowerCase().split(/\s/g);
|
||||
const patNoSpaces = pat.replace(/\s/g, '');
|
||||
const results = [];
|
||||
|
@ -44,8 +44,3 @@ function getMatches(decls, pat, maxResults = 30) {
|
|||
}
|
||||
return results.sort(({err: a}, {err: b}) => a - b).slice(0, maxResults);
|
||||
}
|
||||
|
||||
if (typeof process === 'object') { // NodeJS
|
||||
const data = loadDecls(JSON.parse(require('fs').readFileSync('searchable_data.bmp').toString()));
|
||||
console.log(getMatches(data, process.argv[2] || 'ltltle'));
|
||||
}
|
Loading…
Reference in New Issue