chore: dasdsad
This commit is contained in:
21
src/pages/blog/[...slug].astro
Normal file
21
src/pages/blog/[...slug].astro
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from "astro:content";
|
||||
import BlogPost from "../../layouts/BlogPost.astro";
|
||||
import { render } from "astro:content";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection("blog");
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.id },
|
||||
props: post,
|
||||
}));
|
||||
}
|
||||
type Props = CollectionEntry<"blog">;
|
||||
|
||||
const post = Astro.props;
|
||||
const { Content } = await render(post);
|
||||
---
|
||||
|
||||
<BlogPost {...post.data}>
|
||||
<Content />
|
||||
</BlogPost>
|
||||
@@ -1,47 +0,0 @@
|
||||
---
|
||||
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>
|
||||
116
src/pages/blog/index.astro
Normal file
116
src/pages/blog/index.astro
Normal file
@@ -0,0 +1,116 @@
|
||||
---
|
||||
import BaseHead from "../../components/BaseHead.astro";
|
||||
import Header from "../../components/Header.astro";
|
||||
import Footer from "../../components/Footer.astro";
|
||||
import { SITE_TITLE, SITE_DESCRIPTION } from "../../consts";
|
||||
import { getCollection } from "astro:content";
|
||||
import FormattedDate from "../../components/FormattedDate.astro";
|
||||
|
||||
const posts = (await getCollection("blog")).sort(
|
||||
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
|
||||
);
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<BaseHead title={SITE_TITLE} description={SITE_DESCRIPTION} />
|
||||
<style>
|
||||
main {
|
||||
width: 960px;
|
||||
}
|
||||
ul {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2rem;
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
ul li {
|
||||
width: calc(50% - 1rem);
|
||||
}
|
||||
ul li * {
|
||||
text-decoration: none;
|
||||
transition: 0.2s ease;
|
||||
}
|
||||
ul li:first-child {
|
||||
width: 100%;
|
||||
margin-bottom: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
ul li:first-child img {
|
||||
width: 100%;
|
||||
}
|
||||
ul li:first-child .title {
|
||||
font-size: 2.369rem;
|
||||
}
|
||||
ul li img {
|
||||
margin-bottom: 0.5rem;
|
||||
border-radius: 12px;
|
||||
}
|
||||
ul li a {
|
||||
display: block;
|
||||
}
|
||||
.title {
|
||||
margin: 0;
|
||||
color: rgb(var(--black));
|
||||
line-height: 1;
|
||||
}
|
||||
.date {
|
||||
margin: 0;
|
||||
color: rgb(var(--gray));
|
||||
}
|
||||
ul li a:hover h4,
|
||||
ul li a:hover .date {
|
||||
color: rgb(var(--accent));
|
||||
}
|
||||
ul a:hover img {
|
||||
box-shadow: var(--box-shadow);
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
ul {
|
||||
gap: 0.5em;
|
||||
}
|
||||
ul li {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
ul li:first-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
ul li:first-child .title {
|
||||
font-size: 1.563em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<Header />
|
||||
<main>
|
||||
<section>
|
||||
<ul>
|
||||
{
|
||||
posts.map((post) => (
|
||||
<li>
|
||||
<a href={`/blog/${post.id}/`}>
|
||||
<img
|
||||
width={720}
|
||||
height={360}
|
||||
src={post.data.heroImage}
|
||||
alt=""
|
||||
/>
|
||||
<h4 class="title">{post.data.title}</h4>
|
||||
<p class="date">
|
||||
<FormattedDate date={post.data.pubDate} />
|
||||
</p>
|
||||
</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
</main>
|
||||
<Footer />
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,32 +1,21 @@
|
||||
---
|
||||
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);
|
||||
import BaseHead from '../components/BaseHead.astro';
|
||||
import Header from '../components/Header.astro';
|
||||
import Footer from '../components/Footer.astro';
|
||||
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
|
||||
---
|
||||
|
||||
<!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>
|
||||
<head>
|
||||
<BaseHead title={SITE_TITLE} description={SITE_DESCRIPTION} />
|
||||
</head>
|
||||
<body>
|
||||
<Header />
|
||||
<main>
|
||||
<h1>Ayo</h1>
|
||||
<p>foo, bar, baz, qux, quux</p>
|
||||
</main>
|
||||
<Footer />
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user