refactor: commands from menu
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import { parseDocument, renderMarkdown } from "@lib/documents.ts";
|
||||
import { parse } from "yaml";
|
||||
import { parse, stringify } from "yaml";
|
||||
import { createCrud } from "@lib/crud.ts";
|
||||
import { extractHashTags } from "@lib/string.ts";
|
||||
import { extractHashTags, formatDate } from "@lib/string.ts";
|
||||
import { fixRenderedMarkdown } from "@lib/helpers.ts";
|
||||
|
||||
export type Movie = {
|
||||
id: string;
|
||||
@ -18,6 +19,27 @@ export type Movie = {
|
||||
};
|
||||
};
|
||||
|
||||
function renderMovie(movie: Movie) {
|
||||
const meta = movie.meta;
|
||||
if ("date" in meta) {
|
||||
meta.date = formatDate(meta.date);
|
||||
}
|
||||
|
||||
return fixRenderedMarkdown(`${
|
||||
meta
|
||||
? `---
|
||||
${stringify(meta)}
|
||||
---`
|
||||
: `---
|
||||
---`
|
||||
}
|
||||
# ${movie.name}
|
||||
${movie.meta.image ? `` : ""}
|
||||
${movie.tags.map((t) => `#${t}`).join(" ")}
|
||||
${movie.description}
|
||||
`);
|
||||
}
|
||||
|
||||
export function parseMovie(original: string, id: string): Movie {
|
||||
const doc = parseDocument(original);
|
||||
|
||||
@ -80,3 +102,8 @@ const crud = createCrud<Movie>({
|
||||
|
||||
export const getMovie = crud.read;
|
||||
export const getAllMovies = crud.readAll;
|
||||
export const createMovie = (movie: Movie) => {
|
||||
console.log("creating movie", { movie });
|
||||
const content = renderMovie(movie);
|
||||
return crud.create(movie.id, content);
|
||||
};
|
||||
|
Reference in New Issue
Block a user