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