feat: PostGrid aplikatzen du posta eta etiketetan

This commit is contained in:
txarli committed 2026-11-12 12:56:21 +01:00
1 parent 43a8df169b
commit 8ac7674e7a
6 files changed
+40 -59

No files matched your search

+1 -1
View File
@@ -20,5 +20,5 @@ let posts = allPosts
--- ---
<content> <content>
<PostGrid posts={posts} /> <PostGrid hasRandomPost posts={posts} />
</content> </content>
-44
View File
@@ -1,44 +0,0 @@
---
import type { CollectionEntry } from "astro:content";
interface Props {
post: CollectionEntry<"posts">;
}
const {
post: {
data: { slug, title, tags, description, added: date },
},
}: Props = Astro.props;
---
<li class="post">
<a href={`/post/${slug}/`} class="title">{title}</a>
<time datetime={date as string}>
{
new Date(date).toLocaleDateString("eu", {
year: "numeric",
month: "short",
day: "numeric",
})
}
</time>
<br />
{description && <p class="excerpt">{description}</p>}
<div>
{
tags &&
tags.map((tag: string) => (
<a class="tag" href={`/tag/${tag}`}>
#{tag}
</a>
))
}
</div>
</li>
<style>
.excerpt {
margin: 0;
}
</style>
+6 -1
View File
@@ -3,9 +3,10 @@ import type { CollectionEntry } from "astro:content";
interface Props { interface Props {
posts: CollectionEntry<"posts">[]; posts: CollectionEntry<"posts">[];
hasRandomPost?: boolean;
} }
const { posts } = Astro.props; const { posts, hasRandomPost = false } = Astro.props;
const postSlugs = posts.reduce<string[]>( const postSlugs = posts.reduce<string[]>(
(slugs, { data: { slug } }) => [slug, ...slugs], (slugs, { data: { slug } }) => [slug, ...slugs],
@@ -41,6 +42,8 @@ function getTiltDegrees() {
)) ))
} }
{
hasRandomPost && (
<li class="post post--random" style={`--tilt: ${getTiltDegrees()}deg;`}> <li class="post post--random" style={`--tilt: ${getTiltDegrees()}deg;`}>
<button <button
type="button" type="button"
@@ -53,6 +56,8 @@ function getTiltDegrees() {
<br /> <br />
<p class="excerpt">Bestela, irakurri ausaz aukeratutako post bat 🎲</p> <p class="excerpt">Bestela, irakurri ausaz aukeratutako post bat 🎲</p>
</li> </li>
)
}
</ul> </ul>
<script is:inline define:vars={{ postSlugs }}> <script is:inline define:vars={{ postSlugs }}>
+1 -1
View File
@@ -8,7 +8,7 @@ const { tags, all } = Astro.props;
--- ---
{all && <h3 class="tag-title">Ikusi postak etiketaren arabera</h3>} {all && <h3 class="tag-title">Ikusi postak etiketaren arabera</h3>}
<div class=`${all && "tags"}`> <div class="tags">
{ {
tags && tags &&
tags.map((tag) => ( tags.map((tag) => (
+20 -6
View File
@@ -3,11 +3,13 @@ import { getCollection } from "astro:content";
import BaseHead from "../../components/BaseHead.astro"; import BaseHead from "../../components/BaseHead.astro";
import Header from "../../components/Header.astro"; import Header from "../../components/Header.astro";
import Footer from "../../components/Footer.astro"; import Footer from "../../components/Footer.astro";
import Post from "../../components/Post.astro";
import ColorScript from "../../components/ColorScript.astro"; import ColorScript from "../../components/ColorScript.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../../config"; import { SITE_TITLE, SITE_DESCRIPTION } from "../../config";
import Container from "../../components/Container.astro"; import Container from "../../components/Container.astro";
import PostGrid from "../../components/PostGrid.astro";
import getTags from "../../scripts/getTags";
import Tags from "../../components/Tags.astro";
let posts = await getCollection("posts"); let posts = await getCollection("posts");
@@ -16,6 +18,8 @@ posts = posts.sort(
new Date(b.data.updated || b.data.added).valueOf() - new Date(b.data.updated || b.data.added).valueOf() -
new Date(a.data.updated || a.data.added).valueOf(), new Date(a.data.updated || a.data.added).valueOf(),
); );
const tags = getTags(posts);
--- ---
<!doctype html> <!doctype html>
@@ -24,15 +28,25 @@ posts = posts.sort(
<body> <body>
<Container> <Container>
<Header /> <Header />
</Container>
<main> <main>
<content> <content>
<ul class="posts-list"> <Tags tags={tags} />
{posts.map((post) => <Post post={post} />)} <PostGrid posts={posts} />
</ul>
</content> </content>
</main> </main>
<Container>
<Footer /> <Footer />
<ColorScript /></Container </Container>
> <ColorScript />
</body> </body>
</html> </html>
<style>
content {
display: flex;
flex-direction: column;
align-items: center;
gap: 2em;
}
</style>
+12 -6
View File
@@ -3,11 +3,11 @@ import { getCollection, type CollectionEntry } from "astro:content";
import BaseHead from "../../components/BaseHead.astro"; import BaseHead from "../../components/BaseHead.astro";
import Header from "../../components/Header.astro"; import Header from "../../components/Header.astro";
import Footer from "../../components/Footer.astro"; import Footer from "../../components/Footer.astro";
import Post from "../../components/Post.astro";
import ColorScript from "../../components/ColorScript.astro"; import ColorScript from "../../components/ColorScript.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../../config"; import { SITE_TITLE, SITE_DESCRIPTION } from "../../config";
import Container from "../../components/Container.astro"; import Container from "../../components/Container.astro";
import PostGrid from "../../components/PostGrid.astro";
export async function getStaticPaths() { export async function getStaticPaths() {
const posts = await getCollection("posts"); const posts = await getCollection("posts");
@@ -49,16 +49,22 @@ let sortedPosts = tag.sort(
<body> <body>
<Container> <Container>
<Header /> <Header />
</Container>
<main> <main>
<content> <content>
<h3>"{currentTag}" etiketa daukaten postak</h3> <h3>"{currentTag}" etiketa daukaten postak</h3>
<ul class="tags-list"> <PostGrid posts={sortedPosts} />
{sortedPosts.map((post) => <Post post={post} />)}
</ul>
</content> </content>
<Footer />
</main> </main>
<ColorScript /> <Container>
<Footer />
</Container> </Container>
<ColorScript />
</body> </body>
</html> </html>
<style>
h3 {
margin-bottom: 2em;
}
</style>