feat: move some stuff around

This commit is contained in:
2023-08-01 18:35:35 +02:00
parent c5cf629482
commit e51667bbac
9 changed files with 97 additions and 63 deletions

View File

@ -18,40 +18,37 @@ async function updateMovieMetadata(
) {
const docId = `Media/movies/${name}.md`;
const currentDoc = await getDocument(docId);
let currentDoc = await getDocument(docId);
if (!currentDoc) return;
if (!currentDoc.startsWith("---\n---\n")) {
currentDoc = `---\n---\n\n${currentDoc}`;
}
const newDoc = transformDocument(currentDoc, (root) => {
const frontmatterNode = root.children.find((c) => c.type === "yaml");
const frontmatter = frontmatterNode?.value as string;
if (frontmatter) {
const value = parse(frontmatter) as Movie["meta"];
const value = parse(frontmatter) as Movie["meta"];
if (metadata.author && !value.author) {
value.author = metadata.author;
}
const newValue = {
...metadata,
date: formatDate(metadata.date),
...value,
};
if (metadata.image && !value.image) {
value.image = metadata.image;
}
if (metadata.date && !value.date) {
value.date = formatDate(metadata.date);
}
frontmatterNode.value = stringify(value);
}
frontmatterNode.value = stringify(newValue);
return root;
});
const response = await createDocument(docId, newDoc);
console.log({ newDoc });
return response;
return createDocument(docId, newDoc);
}
const GET = async (
const POST = async (
_req: Request,
_ctx: HandlerContext,
): Promise<Response> => {
@ -99,5 +96,5 @@ const GET = async (
};
export const handler: Handlers = {
GET,
POST,
};