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
+74 -93

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>
+18 -13
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,18 +42,22 @@ function getTiltDegrees() {
)) ))
} }
<li class="post post--random" style={`--tilt: ${getTiltDegrees()}deg;`}> {
<button hasRandomPost && (
type="button" <li class="post post--random" style={`--tilt: ${getTiltDegrees()}deg;`}>
role="link" <button
id="random-post-button" type="button"
class="title title--button" role="link"
> id="random-post-button"
Random post-a class="title title--button"
</button> >
<br /> Random post-a
<p class="excerpt">Bestela, irakurri ausaz aukeratutako post bat 🎲</p> </button>
</li> <br />
<p class="excerpt">Bestela, irakurri ausaz aukeratutako post bat 🎲</p>
</li>
)
}
</ul> </ul>
<script is:inline define:vars={{ postSlugs }}> <script is:inline define:vars={{ postSlugs }}>
+14 -14
View File
@@ -1,23 +1,23 @@
--- ---
interface Props { interface Props {
tags: string[]; tags: string[];
all?: boolean; all?: boolean;
} }
const { tags, all } = Astro.props; 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) => (
<> <>
<a class="tag" href={`/tag/${tag}`}> <a class="tag" href={`/tag/${tag}`}>
#{tag} #{tag}
</a> </a>
{` `} {` `}
</> </>
)) ))
} }
</div> </div>
+24 -10
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 />
<main> </Container>
<content> <main>
<ul class="posts-list"> <content>
{posts.map((post) => <Post post={post} />)} <Tags tags={tags} />
</ul> <PostGrid posts={posts} />
</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>
+17 -11
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 />
<main>
<content>
<h3>"{currentTag}" etiketa daukaten postak</h3>
<ul class="tags-list">
{sortedPosts.map((post) => <Post post={post} />)}
</ul>
</content>
<Footer />
</main>
<ColorScript />
</Container> </Container>
<main>
<content>
<h3>"{currentTag}" etiketa daukaten postak</h3>
<PostGrid posts={sortedPosts} />
</content>
</main>
<Container>
<Footer />
</Container>
<ColorScript />
</body> </body>
</html> </html>
<style>
h3 {
margin-bottom: 2em;
}
</style>