mirror of
https://github.com/maciejpedzich/maciejpedzi.ch.git
synced 2024-11-27 15:45:47 +01:00
Create and use BlogSubpage layout component
This commit is contained in:
parent
d5a7b418a3
commit
e2159db240
39
src/layouts/BlogSubpage.astro
Normal file
39
src/layouts/BlogSubpage.astro
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
import BaseLayout from '../layouts/BaseLayout.astro';
|
||||
import NavLink from '../components/NavLink.astro';
|
||||
|
||||
export interface Props {
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const { title, description } = Astro.props;
|
||||
---
|
||||
|
||||
<BaseLayout title={title} description={description}>
|
||||
<section>
|
||||
<h2>My blog</h2>
|
||||
<nav class="cmr2-text" aria-label="">
|
||||
<NavLink href="/blog">recent posts</NavLink>
|
||||
<NavLink href="/blog/categories">categories</NavLink>
|
||||
<NavLink href="/blog/tags">tags</NavLink>
|
||||
<NavLink href="/blog/archive">archive</NavLink>
|
||||
<NavLink href="/rss.xml" target="_blank">rss feed</NavLink>
|
||||
</nav>
|
||||
<slot />
|
||||
</section>
|
||||
</BaseLayout>
|
||||
|
||||
<style>
|
||||
nav {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
section {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
section > h2 {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
</style>
|
25
src/pages/blog/categories/[category].astro
Normal file
25
src/pages/blog/categories/[category].astro
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
import type { CollectionEntry } from 'astro:content';
|
||||
|
||||
import BlogSubpage from '../../../layouts/BlogSubpage.astro';
|
||||
import PostList from '../../../components/PostList.astro';
|
||||
import frontMatterConfig from '../../../../frontmatter.json';
|
||||
|
||||
export function getStaticPaths() {
|
||||
const categories = frontMatterConfig['frontMatter.taxonomy.categories'];
|
||||
return categories.map((category) => ({ params: { category } }));
|
||||
}
|
||||
|
||||
const { category } = Astro.params;
|
||||
|
||||
const filterFn = (entry: CollectionEntry<'blog'>) =>
|
||||
entry.data.categories.includes(category as string);
|
||||
---
|
||||
|
||||
<BlogSubpage
|
||||
title={`"${category}" posts`}
|
||||
description={`"blog posts from "${category}" category`}
|
||||
>
|
||||
<h3><em>{category}</em> posts</h3>
|
||||
<PostList filterFn={filterFn} />
|
||||
</BlogSubpage>
|
20
src/pages/blog/categories/index.astro
Normal file
20
src/pages/blog/categories/index.astro
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
import BlogSubpage from '../../../layouts/BlogSubpage.astro';
|
||||
import frontMatterConfig from '../../../../frontmatter.json';
|
||||
|
||||
const categories = frontMatterConfig['frontMatter.taxonomy.categories'];
|
||||
---
|
||||
|
||||
<BlogSubpage title="tags" description="all categories of maciej's blog posts">
|
||||
<ul>
|
||||
{
|
||||
categories.sort().map((category) => (
|
||||
<li>
|
||||
<a href={`/blog/categories/${encodeURIComponent(category)}`}>
|
||||
{category}
|
||||
</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</BlogSubpage>
|
@ -1,31 +1,11 @@
|
||||
---
|
||||
import BaseLayout from '../../layouts/BaseLayout.astro';
|
||||
import BlogSubpage from '../../layouts/BlogSubpage.astro';
|
||||
import PostList from '../../components/PostList.astro';
|
||||
import NavLink from '../../components/NavLink.astro';
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
<BlogSubpage
|
||||
title="blog"
|
||||
description="blog about the making of maciej's projects and more"
|
||||
>
|
||||
<section>
|
||||
<h2>My blog</h2>
|
||||
<nav class="cmr2-text" aria-label="">
|
||||
<NavLink href="/blog">recent posts</NavLink>
|
||||
<NavLink href="/blog/categories">categories</NavLink>
|
||||
<NavLink href="/blog/tags">tags</NavLink>
|
||||
<NavLink href="/blog/archive">archive</NavLink>
|
||||
</nav>
|
||||
<PostList />
|
||||
</section>
|
||||
</BaseLayout>
|
||||
|
||||
<style>
|
||||
section {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
section > h2 {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
</style>
|
||||
<PostList />
|
||||
</BlogSubpage>
|
||||
|
25
src/pages/blog/tags/[tag].astro
Normal file
25
src/pages/blog/tags/[tag].astro
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
import type { CollectionEntry } from 'astro:content';
|
||||
|
||||
import BlogSubpage from '../../../layouts/BlogSubpage.astro';
|
||||
import PostList from '../../../components/PostList.astro';
|
||||
import frontMatterConfig from '../../../../frontmatter.json';
|
||||
|
||||
export function getStaticPaths() {
|
||||
const tags = frontMatterConfig['frontMatter.taxonomy.tags'];
|
||||
return tags.map((tag) => ({ params: { tag } }));
|
||||
}
|
||||
|
||||
const { tag } = Astro.params;
|
||||
|
||||
const filterFn = (entry: CollectionEntry<'blog'>) =>
|
||||
entry.data.tags.includes(tag as string);
|
||||
---
|
||||
|
||||
<BlogSubpage
|
||||
title={`posts tagged "${tag}"`}
|
||||
description={`maciej's blog posts tagged "${tag}"`}
|
||||
>
|
||||
<h3>Posts tagged <em>{tag}</em></h3>
|
||||
<PostList filterFn={filterFn} />
|
||||
</BlogSubpage>
|
31
src/pages/blog/tags/index.astro
Normal file
31
src/pages/blog/tags/index.astro
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
import BlogSubpage from '../../../layouts/BlogSubpage.astro';
|
||||
import frontMatterConfig from '../../../../frontmatter.json';
|
||||
|
||||
const tags = frontMatterConfig['frontMatter.taxonomy.tags'];
|
||||
---
|
||||
|
||||
<BlogSubpage title="tags" description="all tags of maciej's blog posts">
|
||||
<ul id="tags">
|
||||
{
|
||||
tags.sort().map((tag) => (
|
||||
<li>
|
||||
<a href={`/blog/tags/${tag}`}>{tag}</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</BlogSubpage>
|
||||
|
||||
<style>
|
||||
#tags {
|
||||
margin-top: 0.25rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem 1rem;
|
||||
}
|
||||
|
||||
#tags > li::before {
|
||||
content: '';
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user