feat: Use metadata from typst

This commit is contained in:
Leni Aniva 2025-03-06 09:28:52 -08:00
parent 20fe91f628
commit 6d675094ea
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
2 changed files with 22 additions and 3 deletions

View File

@ -3,6 +3,8 @@
#metadata((
title: "Title",
date: "2025-01-01",
description: "Example diagram in typst",
tags: ("svg", "typst"),
))<post>
This is a diagram.
@ -56,3 +58,20 @@ This is a diagram.
line((1, 0), (1, calc.tan(30deg)), name: "tan", stroke: (paint: orange))
content("tan.end", $ text(#orange, tan alpha) = text(#red, sin alpha) / text(#blue, cos alpha) $, anchor: "west")
}))
== Heading
#figure(
table(
columns: (auto, auto, auto),
inset: 10pt,
align: horizon,
table.header(
[*System*], [*Speed*]
),
[LaTeX], [Slow],
[Markdown], [Fast],
[Typst], [Fast],
),
caption: [Comparison of blog typesetting options]
)

View File

@ -18,12 +18,12 @@ export const typstPreprocess = (config) => {
if (!extensionsParts.some((ext) => filename.endsWith(ext))) return;
const result_metadata = await exec_async(`typst query --features html ${filename} "<post>" --field value --one`);
const payload = String(result_metadata.stdout);
const metadata = JSON.parse(payload);
const metadata = String(result_metadata.stdout);
const result_post = await exec_async(`typst compile --features html --format html ${filename} -`);
// strip the body tag
const bodyHTML = /<body.*?>([\s\S]*)<\/body>/.exec(result_post.stdout)[1]
const code = "<script context='module'>\n export const metadata = {'title': 'Title', 'date': '2025-02-01'}\n</script>" + bodyHTML
const code = `<script context='module'>\n export const metadata = ${metadata}\n</script>` + bodyHTML
return {
code,