feat: PostGrid aplikatzen du posta eta etiketetan
This commit is contained in:
1 parent
43a8df169b
commit
8ac7674e7a
6 files changed
+74
-93
No files matched your search
@@ -20,5 +20,5 @@ let posts = allPosts
|
||||
---
|
||||
|
||||
<content>
|
||||
<PostGrid posts={posts} />
|
||||
<PostGrid hasRandomPost posts={posts} />
|
||||
</content>
|
||||
@@ -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>
|
||||
@@ -3,9 +3,10 @@ import type { CollectionEntry } from "astro:content";
|
||||
|
||||
interface Props {
|
||||
posts: CollectionEntry<"posts">[];
|
||||
hasRandomPost?: boolean;
|
||||
}
|
||||
|
||||
const { posts } = Astro.props;
|
||||
const { posts, hasRandomPost = false } = Astro.props;
|
||||
|
||||
const postSlugs = posts.reduce<string[]>(
|
||||
(slugs, { data: { slug } }) => [slug, ...slugs],
|
||||
@@ -41,18 +42,22 @@ function getTiltDegrees() {
|
||||
))
|
||||
}
|
||||
|
||||
<li class="post post--random" style={`--tilt: ${getTiltDegrees()}deg;`}>
|
||||
<button
|
||||
type="button"
|
||||
role="link"
|
||||
id="random-post-button"
|
||||
class="title title--button"
|
||||
>
|
||||
Random post-a
|
||||
</button>
|
||||
<br />
|
||||
<p class="excerpt">Bestela, irakurri ausaz aukeratutako post bat 🎲</p>
|
||||
</li>
|
||||
{
|
||||
hasRandomPost && (
|
||||
<li class="post post--random" style={`--tilt: ${getTiltDegrees()}deg;`}>
|
||||
<button
|
||||
type="button"
|
||||
role="link"
|
||||
id="random-post-button"
|
||||
class="title title--button"
|
||||
>
|
||||
Random post-a
|
||||
</button>
|
||||
<br />
|
||||
<p class="excerpt">Bestela, irakurri ausaz aukeratutako post bat 🎲</p>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
</ul>
|
||||
|
||||
<script is:inline define:vars={{ postSlugs }}>
|
||||
|
||||
+14
-14
@@ -1,23 +1,23 @@
|
||||
---
|
||||
interface Props {
|
||||
tags: string[];
|
||||
all?: boolean;
|
||||
tags: string[];
|
||||
all?: boolean;
|
||||
}
|
||||
|
||||
const { tags, all } = Astro.props;
|
||||
---
|
||||
|
||||
{all && <h3 class="tag-title">Ikusi postak etiketaren arabera</h3>}
|
||||
<div class=`${all && "tags"}`>
|
||||
{
|
||||
tags &&
|
||||
tags.map((tag) => (
|
||||
<>
|
||||
<a class="tag" href={`/tag/${tag}`}>
|
||||
#{tag}
|
||||
</a>
|
||||
{` `}
|
||||
</>
|
||||
))
|
||||
}
|
||||
<div class="tags">
|
||||
{
|
||||
tags &&
|
||||
tags.map((tag) => (
|
||||
<>
|
||||
<a class="tag" href={`/tag/${tag}`}>
|
||||
#{tag}
|
||||
</a>
|
||||
{` `}
|
||||
</>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
+24
-10
@@ -3,11 +3,13 @@ import { getCollection } from "astro:content";
|
||||
import BaseHead from "../../components/BaseHead.astro";
|
||||
import Header from "../../components/Header.astro";
|
||||
import Footer from "../../components/Footer.astro";
|
||||
import Post from "../../components/Post.astro";
|
||||
import ColorScript from "../../components/ColorScript.astro";
|
||||
|
||||
import { SITE_TITLE, SITE_DESCRIPTION } from "../../config";
|
||||
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");
|
||||
|
||||
@@ -16,6 +18,8 @@ posts = posts.sort(
|
||||
new Date(b.data.updated || b.data.added).valueOf() -
|
||||
new Date(a.data.updated || a.data.added).valueOf(),
|
||||
);
|
||||
|
||||
const tags = getTags(posts);
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@@ -24,15 +28,25 @@ posts = posts.sort(
|
||||
<body>
|
||||
<Container>
|
||||
<Header />
|
||||
<main>
|
||||
<content>
|
||||
<ul class="posts-list">
|
||||
{posts.map((post) => <Post post={post} />)}
|
||||
</ul>
|
||||
</content>
|
||||
</main>
|
||||
</Container>
|
||||
<main>
|
||||
<content>
|
||||
<Tags tags={tags} />
|
||||
<PostGrid posts={posts} />
|
||||
</content>
|
||||
</main>
|
||||
<Container>
|
||||
<Footer />
|
||||
<ColorScript /></Container
|
||||
>
|
||||
</Container>
|
||||
<ColorScript />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style>
|
||||
content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2em;
|
||||
}
|
||||
</style>
|
||||
+17
-11
@@ -3,11 +3,11 @@ import { getCollection, type CollectionEntry } from "astro:content";
|
||||
import BaseHead from "../../components/BaseHead.astro";
|
||||
import Header from "../../components/Header.astro";
|
||||
import Footer from "../../components/Footer.astro";
|
||||
import Post from "../../components/Post.astro";
|
||||
import ColorScript from "../../components/ColorScript.astro";
|
||||
|
||||
import { SITE_TITLE, SITE_DESCRIPTION } from "../../config";
|
||||
import Container from "../../components/Container.astro";
|
||||
import PostGrid from "../../components/PostGrid.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection("posts");
|
||||
@@ -49,16 +49,22 @@ let sortedPosts = tag.sort(
|
||||
<body>
|
||||
<Container>
|
||||
<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>
|
||||
<main>
|
||||
<content>
|
||||
<h3>"{currentTag}" etiketa daukaten postak</h3>
|
||||
<PostGrid posts={sortedPosts} />
|
||||
</content>
|
||||
</main>
|
||||
<Container>
|
||||
<Footer />
|
||||
</Container>
|
||||
<ColorScript />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style>
|
||||
h3 {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user