fix: some issues
This commit is contained in:
@@ -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