feat: load data from marka
This commit is contained in:
@@ -32,12 +32,12 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`);
|
|||||||
<Card.Content classes="px-8 py-7 order-last xs:order-first">
|
<Card.Content classes="px-8 py-7 order-last xs:order-first">
|
||||||
<Card.Title classes="text-4xl flex items-center gap-2">
|
<Card.Title classes="text-4xl flex items-center gap-2">
|
||||||
{
|
{
|
||||||
icon &&
|
icon &&
|
||||||
(
|
(icon?.length > 5 ? (
|
||||||
icon?.length > 5
|
<img class="h-6 w-6" src={icon} />
|
||||||
? <img class="h-6 w-6" src={icon} />
|
) : (
|
||||||
: <span class="p-r-4 text-md">{icon}</span>
|
<span class="p-r-4 text-md">{icon}</span>
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
{title}
|
{title}
|
||||||
</Card.Title>
|
</Card.Title>
|
||||||
|
@@ -13,6 +13,19 @@ interface Props {
|
|||||||
maxWidth?: number;
|
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 {
|
const {
|
||||||
src: image,
|
src: image,
|
||||||
loader = true,
|
loader = true,
|
||||||
@@ -24,6 +37,8 @@ const {
|
|||||||
|
|
||||||
let thumbhash = hash && image.fsPath ? await generateThumbHash(image) : "";
|
let thumbhash = hash && image.fsPath ? await generateThumbHash(image) : "";
|
||||||
|
|
||||||
|
const imageSrc = await checkImage(image);
|
||||||
|
|
||||||
let exif = await getExifData(image);
|
let exif = await getExifData(image);
|
||||||
|
|
||||||
const sizes = [
|
const sizes = [
|
||||||
@@ -45,11 +60,13 @@ const sizes = [
|
|||||||
].filter((size) => !maxWidth || size.width <= maxWidth);
|
].filter((size) => !maxWidth || size.width <= maxWidth);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
{imageSrc?
|
||||||
<AstroImage
|
<AstroImage
|
||||||
src={image}
|
src={imageSrc}
|
||||||
alt={alt}
|
alt={alt}
|
||||||
data-thumbhash={thumbhash}
|
data-thumbhash={thumbhash}
|
||||||
data-exif={JSON.stringify(exif)}
|
data-exif={JSON.stringify(exif)}
|
||||||
|
inferSize={true}
|
||||||
pictureAttributes={{
|
pictureAttributes={{
|
||||||
class: `${hash ? "block h-full relative" : ""} ${loader ? "thumb" : ""} ${pictureClass}`,
|
class: `${hash ? "block h-full relative" : ""} ${loader ? "thumb" : ""} ${pictureClass}`,
|
||||||
}}
|
}}
|
||||||
@@ -60,3 +77,4 @@ const sizes = [
|
|||||||
.join(", ")}>
|
.join(", ")}>
|
||||||
<slot />
|
<slot />
|
||||||
</AstroImage>
|
</AstroImage>
|
||||||
|
:undefined }
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
export async function listResource(id: string): Promise<any[]> {
|
export async function listResource(id: string): Promise<any[]> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`http://localhost:8080/resources?name=${id}`,
|
`http://localhost:8080/${id}`,
|
||||||
);
|
);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return []
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,37 +6,33 @@ import * as memorium from "@helpers/memorium";
|
|||||||
|
|
||||||
const path = useTranslatedPath(Astro.url);
|
const path = useTranslatedPath(Astro.url);
|
||||||
|
|
||||||
const collection = "resources/recipes";
|
const collection = "resources/Recipes";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
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 paths;
|
||||||
return {
|
|
||||||
params: {
|
|
||||||
recipeName: recipe.identifier
|
|
||||||
.replace("Recipes/", "")
|
|
||||||
.replace(/\.md$/, ""),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return paths;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const recipeResponse = await memorium.listResource(
|
||||||
const recipes = await memorium.listResource(
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
`Recipes/${Astro.params.recipeName}.md`,
|
`Recipes/${Astro.params.recipeName}.md`,
|
||||||
);
|
);
|
||||||
if (recipes.length === 0) {
|
if (!recipeResponse?.content) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 404,
|
status: 404,
|
||||||
statusText: "Not found",
|
statusText: "Not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const recipe = recipes[0];
|
const recipe = recipeResponse.content;
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Max Richter">
|
<Layout title="Max Richter">
|
||||||
@@ -58,14 +54,20 @@ const recipe = recipes[0];
|
|||||||
<h1>{recipe.name}</h1>
|
<h1>{recipe.name}</h1>
|
||||||
|
|
||||||
<h3>Ingredients</h3>
|
<h3>Ingredients</h3>
|
||||||
|
<ul>
|
||||||
|
{
|
||||||
|
recipe.recipeIngredient?.map((ingredient: any) => (
|
||||||
|
<li>{markdownToText(ingredient??"")}</li>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Instructions</h3>
|
||||||
<ol>
|
<ol>
|
||||||
{
|
{
|
||||||
recipe.recipeIngredient?.map((ingredient: any) => (
|
recipe.recipeIngredient?.map((ingredient: any) => (
|
||||||
<li>{markdownToText(ingredient)}</li>
|
<li>{markdownToText(ingredient??"")}</li>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<h3>Instructions</h3>
|
|
||||||
<p>{recipe.recipeInstructions}</p>
|
|
||||||
</Layout>
|
</Layout>
|
24
src/pages/resources/Recipes/index.astro
Normal file
24
src/pages/resources/Recipes/index.astro
Normal file
@@ -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");
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="Max Richter">
|
||||||
|
{
|
||||||
|
recipes.content.filter(res => res.content).map((recipe: any) => (
|
||||||
|
<HeroCard
|
||||||
|
post={{
|
||||||
|
collection: "resources/Recipes",
|
||||||
|
id: recipe.name.replace(/\.md$/, ""),
|
||||||
|
data: {
|
||||||
|
cover: recipe.content?.image ? `http://localhost:8080/${recipe.content.image}` : undefined,
|
||||||
|
title: recipe.name.replace(/\.md$/, ""),
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</Layout>
|
@@ -15,7 +15,7 @@ const wiki = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const articles = {
|
const articles = {
|
||||||
id: "articles",
|
id: "Articles",
|
||||||
collection,
|
collection,
|
||||||
body: "Articles saved",
|
body: "Articles saved",
|
||||||
data: {
|
data: {
|
||||||
@@ -25,7 +25,7 @@ const articles = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const recipes = {
|
const recipes = {
|
||||||
id: "recipes",
|
id: "Recipes",
|
||||||
collection,
|
collection,
|
||||||
body: "Recipes",
|
body: "Recipes",
|
||||||
data: {
|
data: {
|
||||||
@@ -35,7 +35,7 @@ const recipes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const movies = {
|
const movies = {
|
||||||
id: "movies",
|
id: "Movies",
|
||||||
collection,
|
collection,
|
||||||
body: "Movies",
|
body: "Movies",
|
||||||
data: {
|
data: {
|
||||||
@@ -45,7 +45,7 @@ const movies = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const series = {
|
const series = {
|
||||||
id: "series",
|
id: "Series",
|
||||||
collection,
|
collection,
|
||||||
body: "Series",
|
body: "Series",
|
||||||
data: {
|
data: {
|
||||||
|
@@ -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/*");
|
|
||||||
---
|
|
||||||
|
|
||||||
<Layout title="Max Richter">
|
|
||||||
{
|
|
||||||
recipes.map((recipe: any) => (
|
|
||||||
<HeroCard
|
|
||||||
post={{
|
|
||||||
collection: "resources/recipes",
|
|
||||||
id: recipe.identifier.replace("Recipes/", "").replace(/\.md$/, ""),
|
|
||||||
data: {
|
|
||||||
title: recipe.name,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</Layout>
|
|
Reference in New Issue
Block a user