feat: move some stuff around
This commit is contained in:
@ -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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user