Refactor of asset bundles

This commit is contained in:
Zef Hemel
2022-10-12 11:47:13 +02:00
parent 9dd94c5397
commit 4c19ab21f2
96 changed files with 6279 additions and 770 deletions
+2 -2
View File
@@ -2,10 +2,10 @@ export function niceDate(d: Date): string {
function pad(n: number) {
let s = String(n);
if (s.length === 1) {
s = '0' + s;
s = "0" + s;
}
return s;
}
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
}
+10 -6
View File
@@ -10,7 +10,7 @@ import { getServerLogs } from "../../syscall/silverbullet-syscall/sandbox.ts";
export async function parsePageCommand() {
console.log(
"AST",
JSON.stringify(await parseMarkdown(await getText()), null, 2)
JSON.stringify(await parseMarkdown(await getText()), null, 2),
);
}
@@ -53,15 +53,19 @@ export async function showLogsCommand() {
</style>
<div id="client-log-header">Client logs (max 100)</div>
<div id="client-log">
<pre>${clientLogs
<pre>${
clientLogs
.map((le) => `[${le.level}] ${le.message}`)
.join("\n")}</pre>
.join("\n")
}</pre>
</div>
<div id="server-log-header">Server logs (max 100)</div>
<div id="server-log">
<pre>${serverLogs
<pre>${
serverLogs
.map((le) => `[${le.level}] ${le.message}`)
.join("\n")}</pre>
.join("\n")
}</pre>
</div>`,
`
var clientDiv = document.getElementById("client-log");
@@ -74,7 +78,7 @@ export async function showLogsCommand() {
window.reloadInterval = setInterval(() => {
sendEvent("log:reload");
}, 1000);
`
`,
);
}
+2 -2
View File
@@ -28,7 +28,7 @@ export async function unfurlCommand() {
let selectedUnfurl: any = await filterBox(
"Unfurl",
options,
"Select the unfurl strategy of your choice"
"Select the unfurl strategy of your choice",
);
if (!selectedUnfurl) {
return;
@@ -38,7 +38,7 @@ export async function unfurlCommand() {
"server",
"unfurlExec",
selectedUnfurl.id,
url
url,
);
await replaceRange(nakedUrlNode?.from!, nakedUrlNode?.to!, replacement);
} catch (e: any) {
+1 -1
View File
@@ -75,7 +75,7 @@ export async function pageQueryProvider({
}: QueryProviderEvent): Promise<any[]> {
let allPages = await listPages();
let allPageMap: Map<string, any> = new Map(
allPages.map((pm) => [pm.name, pm])
allPages.map((pm) => [pm.name, pm]),
);
for (let { page, value } of await queryPrefix("meta:")) {
let p = allPageMap.get(page);
+9 -8
View File
@@ -35,7 +35,7 @@ export async function updatePlugs() {
plugList = plugListRead.filter((plug) => typeof plug === "string");
if (plugList.length !== plugListRead.length) {
throw new Error(
`Some of the plugs were not in a yaml list format, they were ignored`
`Some of the plugs were not in a yaml list format, they were ignored`,
);
}
} catch (e: any) {
@@ -56,7 +56,7 @@ export async function updatePlugs() {
await writeAttachment(
`_plug/${manifest.name}.plug.json`,
"string",
JSON.stringify(manifest)
JSON.stringify(manifest),
);
}
@@ -64,7 +64,7 @@ export async function updatePlugs() {
for (let existingPlug of await listPlugs()) {
let plugName = existingPlug.substring(
"_plug/".length,
existingPlug.length - ".plug.json".length
existingPlug.length - ".plug.json".length,
);
console.log("Considering", plugName);
if (!allPlugNames.includes(plugName)) {
@@ -94,27 +94,28 @@ export async function getPlugGithub(identifier: string): Promise<Manifest> {
branch = "main"; // or "master"?
}
return getPlugHTTPS(
`//raw.githubusercontent.com/${owner}/${repoClean}/${branch}/${path}`
`//raw.githubusercontent.com/${owner}/${repoClean}/${branch}/${path}`,
);
}
export async function getPlugGithubRelease(
identifier: string
identifier: string,
): Promise<Manifest> {
let [owner, repo, version] = identifier.split("/");
if (!version || version === "latest") {
console.log("fetching the latest version");
const req = await fetch(
`https://api.github.com/repos/${owner}/${repo}/releases/latest`
`https://api.github.com/repos/${owner}/${repo}/releases/latest`,
);
if (req.status !== 200) {
throw new Error(
`Could not fetch latest relase manifest from ${identifier}}`
`Could not fetch latest relase manifest from ${identifier}}`,
);
}
const result = await req.json();
version = result.name;
}
const finalUrl = `//github.com/${owner}/${repo}/releases/download/${version}/${repo}.plug.json`;
const finalUrl =
`//github.com/${owner}/${repo}/releases/download/${version}/${repo}.plug.json`;
return getPlugHTTPS(finalUrl);
}
+7 -5
View File
@@ -33,7 +33,7 @@ export async function queryProvider({
let results = await fullTextSearch(phraseFilter.value, 100);
let allPageMap: Map<string, any> = new Map(
results.map((r: any) => [r.name, r])
results.map((r: any) => [r.name, r]),
);
for (let { page, value } of await queryPrefix("meta:")) {
let p = allPageMap.get(page);
@@ -59,13 +59,15 @@ export async function searchCommand() {
}
export async function readPageSearch(
name: string
name: string,
): Promise<{ text: string; meta: PageMeta }> {
let phrase = name.substring(searchPrefix.length);
let results = await fullTextSearch(phrase, 100);
const text = `# Search results for "${phrase}"\n${results
.map((r: any) => `* [[${r.name}]] (score: ${r.rank})`)
.join("\n")}
const text = `# Search results for "${phrase}"\n${
results
.map((r: any) => `* [[${r.name}]] (score: ${r.rank})`)
.join("\n")
}
`;
return {
text: text,
+1 -1
View File
@@ -20,6 +20,6 @@ export async function statsCommand() {
const wordCount = countWords(text);
const time = readingTime(wordCount);
await flashNotification(
`${wordCount} words; ${time} minutes read; ${allPages.length} total pages in space.`
`${wordCount} words; ${time} minutes read; ${allPages.length} total pages in space.`,
);
}
+2 -2
View File
@@ -19,7 +19,7 @@ export async function indexTags({ name, tree }: IndexTreeEvent) {
});
batchSet(
name,
[...allTags].map((t) => ({ key: `tag:${t}`, value: t }))
[...allTags].map((t) => ({ key: `tag:${t}`, value: t })),
);
}
@@ -58,6 +58,6 @@ export async function tagProvider({ query }: QueryProviderEvent) {
[...allTags.entries()].map(([name, freq]) => ({
name,
freq,
}))
})),
);
}