diff --git a/src/components/HeroCard.astro b/src/components/HeroCard.astro index e5cc0be..a051e55 100644 --- a/src/components/HeroCard.astro +++ b/src/components/HeroCard.astro @@ -32,12 +32,12 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`); { - icon && - ( - icon?.length > 5 - ? - : {icon} - ) + icon && + (icon?.length > 5 ? ( + + ) : ( + {icon} + )) } {title} diff --git a/src/components/Image.astro b/src/components/Image.astro index 634b62d..c8de239 100644 --- a/src/components/Image.astro +++ b/src/components/Image.astro @@ -13,6 +13,19 @@ interface Props { maxWidth?: number; } +async function checkImage(src:string){ + try { + const res = await fetch(src); + if (res.ok) { + return src + } + return undefined + }catch(err){ + console.log({src}); + return undefined + } +} + const { src: image, loader = true, @@ -24,6 +37,8 @@ const { let thumbhash = hash && image.fsPath ? await generateThumbHash(image) : ""; +const imageSrc = await checkImage(image); + let exif = await getExifData(image); const sizes = [ @@ -45,11 +60,13 @@ const sizes = [ ].filter((size) => !maxWidth || size.width <= maxWidth); --- +{imageSrc? +:undefined } diff --git a/src/helpers/memorium.ts b/src/helpers/memorium.ts index 51ea75f..035d2df 100644 --- a/src/helpers/memorium.ts +++ b/src/helpers/memorium.ts @@ -1,10 +1,10 @@ export async function listResource(id: string): Promise { try { const response = await fetch( - `http://localhost:8080/resources?name=${id}`, + `http://localhost:8080/${id}`, ); return await response.json(); } catch (error) { - return [] + return []; } } diff --git a/src/pages/resources/movies/[movieName].astro b/src/pages/resources/Movies/[movieName].astro similarity index 100% rename from src/pages/resources/movies/[movieName].astro rename to src/pages/resources/Movies/[movieName].astro diff --git a/src/pages/resources/movies/index.astro b/src/pages/resources/Movies/index.astro similarity index 100% rename from src/pages/resources/movies/index.astro rename to src/pages/resources/Movies/index.astro diff --git a/src/pages/resources/recipes/[recipeName].astro b/src/pages/resources/Recipes/[recipeName].astro similarity index 63% rename from src/pages/resources/recipes/[recipeName].astro rename to src/pages/resources/Recipes/[recipeName].astro index 88205f8..53f9b4d 100644 --- a/src/pages/resources/recipes/[recipeName].astro +++ b/src/pages/resources/Recipes/[recipeName].astro @@ -6,37 +6,33 @@ import * as memorium from "@helpers/memorium"; const path = useTranslatedPath(Astro.url); -const collection = "resources/recipes"; +const collection = "resources/Recipes"; export async function getStaticPaths() { + const recipes = await memorium.listResource("Recipes"); - const recipes = await memorium.listResource("Recipes/*"); + const paths = recipes.content.filter(res =>res.content).map((recipe: any) => { + return { + params: { + recipeName: recipe.name.replace(/\.md$/, ""), + }, + }; + }); - const paths = recipes.map((recipe: any) => { - return { - params: { - recipeName: recipe.identifier - .replace("Recipes/", "") - .replace(/\.md$/, ""), - }, - }; - }); - - return paths; + return paths; } - -const recipes = await memorium.listResource( +const recipeResponse = await memorium.listResource( //@ts-ignore `Recipes/${Astro.params.recipeName}.md`, ); -if (recipes.length === 0) { +if (!recipeResponse?.content) { return new Response(null, { status: 404, statusText: "Not found", }); } -const recipe = recipes[0]; +const recipe = recipeResponse.content; --- @@ -58,14 +54,20 @@ const recipe = recipes[0];

{recipe.name}

Ingredients

+
    + { + recipe.recipeIngredient?.map((ingredient: any) => ( +
  • {markdownToText(ingredient??"")}
  • + )) + } +
+ +

Instructions

    { recipe.recipeIngredient?.map((ingredient: any) => ( -
  1. {markdownToText(ingredient)}
  2. +
  3. {markdownToText(ingredient??"")}
  4. )) }
- -

Instructions

-

{recipe.recipeInstructions}

diff --git a/src/pages/resources/Recipes/index.astro b/src/pages/resources/Recipes/index.astro new file mode 100644 index 0000000..5efbb54 --- /dev/null +++ b/src/pages/resources/Recipes/index.astro @@ -0,0 +1,24 @@ +--- +import Layout from "@layouts/Layout.astro"; +import HeroCard from "@components/HeroCard.astro"; +import * as memorium from "@helpers/memorium"; + +const recipes = await memorium.listResource("Recipes"); +--- + + + { + recipes.content.filter(res => res.content).map((recipe: any) => ( + + )) + } + diff --git a/src/pages/resources/series/[seriesName].astro b/src/pages/resources/Series/[seriesName].astro similarity index 100% rename from src/pages/resources/series/[seriesName].astro rename to src/pages/resources/Series/[seriesName].astro diff --git a/src/pages/resources/series/index.astro b/src/pages/resources/Series/index.astro similarity index 100% rename from src/pages/resources/series/index.astro rename to src/pages/resources/Series/index.astro diff --git a/src/pages/resources/index.astro b/src/pages/resources/index.astro index 2501b61..cf93cd1 100644 --- a/src/pages/resources/index.astro +++ b/src/pages/resources/index.astro @@ -15,7 +15,7 @@ const wiki = { }; const articles = { - id: "articles", + id: "Articles", collection, body: "Articles saved", data: { @@ -25,7 +25,7 @@ const articles = { }; const recipes = { - id: "recipes", + id: "Recipes", collection, body: "Recipes", data: { @@ -35,7 +35,7 @@ const recipes = { }; const movies = { - id: "movies", + id: "Movies", collection, body: "Movies", data: { @@ -45,7 +45,7 @@ const movies = { }; const series = { - id: "series", + id: "Series", collection, body: "Series", data: { diff --git a/src/pages/resources/recipes/index.astro b/src/pages/resources/recipes/index.astro deleted file mode 100644 index 8b31d39..0000000 --- a/src/pages/resources/recipes/index.astro +++ /dev/null @@ -1,23 +0,0 @@ ---- -import Layout from "@layouts/Layout.astro"; -import HeroCard from "@components/HeroCard.astro"; -import * as memorium from "@helpers/memorium"; - -const recipes = await memorium.listResource("Recipes/*"); ---- - - - { - recipes.map((recipe: any) => ( - - )) - } -