chore: init
This commit is contained in:
47
src/pages/blog/[slug].astro
Normal file
47
src/pages/blog/[slug].astro
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
import fetchApi from "../../lib/strapi";
|
||||
import type { ArticleData } from "../../interfaces/article";
|
||||
import Markdown from "../../components/Markdown.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const articles = await fetchApi<ArticleData[]>({
|
||||
endpoint: "articles",
|
||||
wrappedByKey: "data",
|
||||
});
|
||||
|
||||
console.log(articles);
|
||||
|
||||
return articles.map((article) => ({
|
||||
params: { slug: article.slug },
|
||||
props: { article },
|
||||
}));
|
||||
}
|
||||
type Props = {
|
||||
article: ArticleData;
|
||||
};
|
||||
|
||||
const { article } = Astro.props;
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{article.title}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
{
|
||||
article.image && (
|
||||
<img
|
||||
src={import.meta.env.STRAPI_URL + article.image}
|
||||
alt={article.title}
|
||||
/>
|
||||
)
|
||||
}
|
||||
<h1>{article.title}</h1>
|
||||
|
||||
<Markdown content={article.content} />
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
32
src/pages/index.astro
Normal file
32
src/pages/index.astro
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
import fetchApi from "../lib/strapi";
|
||||
import type { ArticleData } from "../interfaces/article";
|
||||
|
||||
const articles = await fetchApi<ArticleData[]>({
|
||||
endpoint: "articles?populate=image",
|
||||
wrappedByKey: "data",
|
||||
});
|
||||
|
||||
console.log('Articles response:', articles);
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Blog</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<ul>
|
||||
{
|
||||
articles.map((article) => (
|
||||
<li>
|
||||
<a href={`/blog/${article.slug}/`}>{article.title}</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user