fix: Metadata generation
This commit is contained in:
parent
332082102d
commit
20fe91f628
|
@ -1,13 +1,10 @@
|
|||
#import "@preview/cetz:0.3.2"
|
||||
|
||||
#metadata((
|
||||
title: "Title",
|
||||
date: "2025-01-01",
|
||||
))<post>
|
||||
|
||||
//#set page(width: auto, height: auto, margin: .5cm)
|
||||
|
||||
#show math.equation: block.with(fill: white, inset: 1pt)
|
||||
|
||||
This is a diagram.
|
||||
|
||||
#html.frame(cetz.canvas(length: 3cm, {
|
||||
|
|
|
@ -23,8 +23,7 @@ export async function getPosts(filter: { tag?: string, series?: string }) : Prom
|
|||
let posts: Post[] = await Promise.all(
|
||||
iterablePostFiles.map(async ([pathMarkdown, resolver]) => {
|
||||
const { metadata } = await resolver();
|
||||
console.log(await resolver());
|
||||
const slug = pathMarkdown.slice(pathMarkdown.lastIndexOf("/") + 1, -".md".length);
|
||||
const slug = pathMarkdown.slice(pathMarkdown.lastIndexOf("/") + 1, pathMarkdown.lastIndexOf("."));
|
||||
|
||||
return transformPostMeta(metadata, slug);
|
||||
})
|
||||
|
|
|
@ -13,25 +13,23 @@ export const typstPreprocess = (config) => {
|
|||
markup: async ({content: _, filename}) => {
|
||||
|
||||
const extensionsParts = extensions.map((ext) =>
|
||||
ext.startsWith('.') ? ext : '.' + ext
|
||||
);
|
||||
if (!extensionsParts.some((ext) => filename.endsWith(ext))) return;
|
||||
|
||||
console.log("Processing typst file: ", filename);
|
||||
ext.startsWith('.') ? ext : '.' + ext
|
||||
);
|
||||
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 data = JSON.parse(payload);
|
||||
console.log("data", data);
|
||||
const metadata = JSON.parse(payload);
|
||||
|
||||
const result_post = await exec_async(`typst compile --features html ${filename} -`);
|
||||
const code = String(result_post.stdout)
|
||||
const result_post = await exec_async(`typst compile --features html --format html ${filename} -`);
|
||||
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
|
||||
|
||||
return {
|
||||
code,
|
||||
metadata: data,
|
||||
data,
|
||||
map: '',
|
||||
data: {
|
||||
fm: metadata,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -53,4 +53,7 @@
|
|||
padding-left: 2em;
|
||||
padding-right: 2em;
|
||||
}
|
||||
:global(svg) {
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -3,9 +3,20 @@ import type { PageLoad } from './$types';
|
|||
import type { Post } from '$lib/types'
|
||||
import { getPosts, transformPostMeta } from '$lib/posts';
|
||||
|
||||
async function importPost(slug: string) {
|
||||
try {
|
||||
const post = await import(`$content/post/${slug}.md`);
|
||||
return post;
|
||||
}
|
||||
catch(e) {
|
||||
console.log("Could not find .md", e);
|
||||
}
|
||||
const post = await import(`$content/post/${slug}.typ`);
|
||||
return post;
|
||||
}
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
try {
|
||||
const post = await import(`$content/post/${params.slug}.md`);
|
||||
const post = await importPost(params.slug);
|
||||
if (!post) throw error(404);
|
||||
const metadata: Post = transformPostMeta(post.metadata, params.slug);
|
||||
const Content = post.default;
|
||||
|
|
Loading…
Reference in New Issue