feat: reduce JSON data size

main
Henrik 2023-09-10 12:39:37 +02:00
parent a0779fa7de
commit 08de0ad10c
5 changed files with 13 additions and 27 deletions

View File

@ -38,8 +38,13 @@ structure JsonModule where
structure JsonHeaderIndex where structure JsonHeaderIndex where
headers : List (String × String) := [] headers : List (String × String) := []
structure JsonIndexedDeclarationInfo where
kind : String
docLink : String
deriving FromJson, ToJson
structure JsonIndex where structure JsonIndex where
declarations : List (String × JsonDeclarationInfo) := [] declarations : List (String × JsonIndexedDeclarationInfo) := []
instances : HashMap String (RBTree String Ord.compare) := .empty instances : HashMap String (RBTree String Ord.compare) := .empty
importedBy : HashMap String (Array String) := .empty importedBy : HashMap String (Array String) := .empty
modules : List (String × String) := [] modules : List (String × String) := []
@ -71,7 +76,10 @@ def JsonHeaderIndex.addModule (index : JsonHeaderIndex) (module : JsonModule) :
def JsonIndex.addModule (index : JsonIndex) (module : JsonModule) : BaseHtmlM JsonIndex := do def JsonIndex.addModule (index : JsonIndex) (module : JsonModule) : BaseHtmlM JsonIndex := do
let mut index := index let mut index := index
let newModule := (module.name, ← moduleNameToLink (String.toName module.name)) let newModule := (module.name, ← moduleNameToLink (String.toName module.name))
let newDecls := module.declarations.map (fun d => (d.info.name, d.info)) let newDecls := module.declarations.map (fun d => (d.info.name, {
kind := d.info.kind,
docLink := d.info.docLink,
}))
index := { index with index := { index with
modules := newModule :: index.modules modules := newModule :: index.modules
declarations := newDecls ++ index.declarations declarations := newDecls ++ index.declarations

View File

@ -168,12 +168,9 @@ function getMatches(declarations, pattern, allowedKinds = undefined, maxResults
const lowerPats = pattern.toLowerCase().split(/\s/g); const lowerPats = pattern.toLowerCase().split(/\s/g);
const patNoSpaces = pattern.replace(/\s/g, ""); const patNoSpaces = pattern.replace(/\s/g, "");
const results = []; const results = [];
for (const [_, { for (const [name, {
name,
kind, kind,
doc,
docLink, docLink,
sourceLink,
}] of Object.entries(declarations)) { }] of Object.entries(declarations)) {
// Apply "kind" filter // Apply "kind" filter
if (allowedKinds !== undefined) { if (allowedKinds !== undefined) {
@ -182,26 +179,14 @@ function getMatches(declarations, pattern, allowedKinds = undefined, maxResults
} }
} }
const lowerName = name.toLowerCase(); const lowerName = name.toLowerCase();
const lowerDoc = doc.toLowerCase();
let err = matchCaseSensitive(name, lowerName, patNoSpaces); let err = matchCaseSensitive(name, lowerName, patNoSpaces);
// match all words as substrings of docstring
if (
err >= 3 &&
pattern.length > 3 &&
lowerPats.every((l) => lowerDoc.indexOf(l) != -1)
) {
err = 3;
}
if (err !== undefined) { if (err !== undefined) {
results.push({ results.push({
name, name,
kind, kind,
doc,
err, err,
lowerName, lowerName,
lowerDoc,
docLink, docLink,
sourceLink,
}); });
} }
} }

View File

@ -80,8 +80,6 @@ async function findAndRedirect(pattern, strict, view) {
window.location.replace(result.link); window.location.replace(result.link);
} else if (view == "doc") { } else if (view == "doc") {
window.location.replace(result.docLink); window.location.replace(result.docLink);
} else if (view == "src") {
window.location.replace(result.sourceLink);
} else { } else {
// fallback to doc page // fallback to doc page
window.location.replace(result.docLink); window.location.replace(result.docLink);

View File

@ -3,7 +3,7 @@ import { DeclarationDataCenter } from "./declaration-data.js";
fillImportedBy(); fillImportedBy();
async function fillImportedBy() { async function fillImportedBy() {
if (!MODULE_NAME) { if (typeof(MODULE_NAME) == "undefined") {
return; return;
} }
const dataCenter = await DeclarationDataCenter.init(); const dataCenter = await DeclarationDataCenter.init();

View File

@ -112,7 +112,7 @@ function handleSearch(dataCenter, err, ev, sr, maxResults, autocomplete) {
// update autocomplete results // update autocomplete results
removeAllChildren(sr); removeAllChildren(sr);
for (const { name, kind, doc, docLink } of result) { for (const { name, kind, docLink } of result) {
const row = sr.appendChild(document.createElement("div")); const row = sr.appendChild(document.createElement("div"));
row.classList.add("search_result") row.classList.add("search_result")
const linkdiv = row.appendChild(document.createElement("div")) const linkdiv = row.appendChild(document.createElement("div"))
@ -121,11 +121,6 @@ function handleSearch(dataCenter, err, ev, sr, maxResults, autocomplete) {
link.innerText = name; link.innerText = name;
link.title = name; link.title = name;
link.href = SITE_ROOT + docLink; link.href = SITE_ROOT + docLink;
if (!autocomplete) {
const doctext = row.appendChild(document.createElement("div"));
doctext.innerText = doc
doctext.classList.add("result_doc")
}
} }
} }
// handle error // handle error