tickle/modules/templates/blog.mjs

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-05-13 15:26:48 +00:00
//@ts-check
import { fetchText } from "../utils/fetchText.mjs";
import { getElementByCSSSelector } from "../utils/getElementByCSSSelector.mjs";
import { onDocumentKeyUp } from "../utils/onDocumentKey.mjs";
import { parseFileList } from "../tickle/parseFileList.mjs";
import { createMenuEntriesFromFileList } from "../tickle/createMenuEntriesFromFileList.mjs";
import { sortFileListLines } from "../tickle/sortFileListLines.mjs";
import { mode } from "../tickle/mode.mjs";
import { bootstrapRouter } from "../tickle/bootstrapRouter.mjs";
export const bootstrap = async () => {
2023-05-18 21:33:33 +00:00
const [Body, Source] = [
2023-05-13 15:26:48 +00:00
"main",
"#Source",
].map(getElementByCSSSelector);
2023-05-13 15:58:34 +00:00
const lines = await fetchText("files.txt");
2023-05-13 15:26:48 +00:00
const links = parseFileList(lines);
const firstHref = links[0].href;
sortFileListLines(links);
2023-05-18 21:33:33 +00:00
Body.appendChild(createMenuEntriesFromFileList(links));
2023-05-13 15:26:48 +00:00
bootstrapRouter(firstHref, (content, raw) => {
Body.innerHTML = "";
Source.innerHTML = raw;
Body.appendChild(content);
});
onDocumentKeyUp("?", mode.sourceEnabled.toggle);
};
export default bootstrap;
if (!new URL(import.meta.url).searchParams.has("load")) {
bootstrap();
}