fix: some issues
This commit is contained in:
@ -7,6 +7,7 @@ import { fixRenderedMarkdown } from "@lib/helpers.ts";
|
||||
|
||||
export type Article = {
|
||||
id: string;
|
||||
type: "article";
|
||||
content: string;
|
||||
name: string;
|
||||
tags: string[];
|
||||
@ -86,6 +87,7 @@ function parseArticle(original: string, id: string): Article {
|
||||
}
|
||||
|
||||
return {
|
||||
type: "article",
|
||||
id,
|
||||
name,
|
||||
tags,
|
||||
|
@ -7,6 +7,7 @@ export type Movie = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
type: "movie";
|
||||
tags: string[];
|
||||
meta: {
|
||||
date: Date;
|
||||
@ -27,7 +28,11 @@ export function parseMovie(original: string, id: string): Movie {
|
||||
|
||||
for (const child of doc.children) {
|
||||
if (child.type === "yaml") {
|
||||
meta = parse(child.value) as Movie["meta"];
|
||||
try {
|
||||
meta = (parse(child.value) || {}) as Movie["meta"];
|
||||
} catch (_) {
|
||||
// ignore here
|
||||
}
|
||||
|
||||
if (meta["rating"] && typeof meta["rating"] === "string") {
|
||||
meta.rating = [...meta.rating?.matchAll("⭐")].length;
|
||||
@ -59,6 +64,7 @@ export function parseMovie(original: string, id: string): Movie {
|
||||
}
|
||||
|
||||
return {
|
||||
type: "movie",
|
||||
id,
|
||||
name,
|
||||
tags,
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
import { parse } from "yaml";
|
||||
import { parseIngredient } from "https://esm.sh/parse-ingredient";
|
||||
import { createCrud } from "@lib/crud.ts";
|
||||
import { extractHashTags } from "@lib/string.ts";
|
||||
|
||||
export type IngredientGroup = {
|
||||
name: string;
|
||||
@ -23,17 +24,20 @@ export type Ingredient = {
|
||||
export type Ingredients = (Ingredient | IngredientGroup)[];
|
||||
|
||||
export type Recipe = {
|
||||
type: "recipe";
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
ingredients: Ingredients;
|
||||
preparation?: string;
|
||||
tags: string[];
|
||||
meta?: {
|
||||
link?: string;
|
||||
image?: string;
|
||||
rating?: number;
|
||||
portion?: number;
|
||||
author?: string;
|
||||
};
|
||||
name: string;
|
||||
description?: string;
|
||||
ingredients: Ingredients;
|
||||
preparation?: string;
|
||||
};
|
||||
|
||||
function parseIngredientItem(listItem: DocumentChild): Ingredient | undefined {
|
||||
@ -154,16 +158,25 @@ export function parseRecipe(original: string, id: string): Recipe {
|
||||
groups.push(group);
|
||||
}
|
||||
|
||||
const description = getTextOfRange(groups[0], original);
|
||||
let description = getTextOfRange(groups[0], original);
|
||||
|
||||
const ingredients = parseIngredients(groups[1]);
|
||||
|
||||
const preparation = getTextOfRange(groups[2], original);
|
||||
|
||||
const tags = extractHashTags(description || "");
|
||||
if (description) {
|
||||
for (const tag of tags) {
|
||||
description = description.replace("#" + tag, "");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: "recipe",
|
||||
id,
|
||||
meta,
|
||||
name,
|
||||
tags,
|
||||
description: description ? renderMarkdown(description) : "",
|
||||
ingredients,
|
||||
preparation: preparation ? renderMarkdown(preparation) : "",
|
||||
|
Reference in New Issue
Block a user