Skip to content

Instantly share code, notes, and snippets.

View nafeu's full-sized avatar
🕶️
In Virtual Reality

Nafeu Nasir nafeu

🕶️
In Virtual Reality
View GitHub Profile
/* Step 1: Parse metadata and components from markdown file */
const decoder = new TextDecoder("utf-8");
const fileContent = decoder.decode(Deno.readFileSync(filename));
/* Step 1: Parse metadata and components from markdown file */
const decoder = new TextDecoder("utf-8");
const fileContent = decoder.decode(Deno.readFileSync(filename));
const components = fileContent.split(COMPONENT_DELIMITER);
[
"---\ntitle: Deno Markdown Site\nstyles: >\n body { color: #22a6b3; }\nfavicon: 🦕\n---\n/home:Home\n\n# Hom...",
"\n/about:About\n\n# About\n\nBuilt for learning.\n\n",
"\nlayout:footer\n\ndeno-md-site\n"
]
/* Step 1: Parse metadata and components from markdown file */
const decoder = new TextDecoder("utf-8");
const fileContent = decoder.decode(Deno.readFileSync(filename));
const components = fileContent.split(COMPONENT_DELIMITER);
const { meta: frontMatter } = Marked.parse(components[FIRST_ITEM_INDEX]);
const { title, styles, favicon } = frontMatter;
{ title: "Deno Markdown Site", styles: "body { color: #22a6b3; }\n", favicon: "🦕" }
/* Step 2: Construct page data from components */
for (const component of components) {
const { content } = Marked.parse(component);
console.log(content);
}
<p>/home:Home</p>
<h1 id="home">Home</h1>
<p>Hello world!</p>
<p>/about:About</p>
<h1 id="about">About</h1>
<p>Built for learning.</p>
<p>layout:footer</p>
<p>deno-md-site</p>
const COMPONENT_TYPE_PATTERN = /<\S>(.*?)\:(.*?)<\/\S>/g;
/* Step 2: Construct page data from components */
for (const component of components) {
const { content } = Marked.parse(component);
const [matchedComponentType] = content.matchAll(COMPONENT_TYPE_PATTERN);
const [, path, name] = matchedComponentType;
console.log({ path, name });
}
{ path: "/home", name: "Home" }
{ path: "/about", name: "About" }
{ path: "layout", name: "footer" }