Add Categories and Tags with new configs
This commit is contained in:
39
src/pages/[...blog]/[...page].astro
Normal file
39
src/pages/[...blog]/[...page].astro
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
import { SITE, BLOG } from "~/config.mjs";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
import Layout from "~/layouts/BlogLayout.astro";
|
||||
import BlogList from "~/components/widgets/BlogList.astro";
|
||||
import Pagination from "~/components/widgets/Pagination.astro";
|
||||
import { getCanonical, getPermalink } from "~/utils/permalinks";
|
||||
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
if (BLOG?.disabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
|
||||
return paginate(posts, {
|
||||
params: { blog: BLOG?.slug || undefined },
|
||||
pageSize: BLOG.postsPerPage,
|
||||
});
|
||||
}
|
||||
|
||||
const { page } = Astro.props;
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
|
||||
const meta = {
|
||||
title: `Blog ${currentPage > 1 ? `— Page ${currentPage} ` : ""}— ${SITE.name}`,
|
||||
description: SITE.description,
|
||||
canonical: getCanonical(getPermalink(page.url.current))
|
||||
}
|
||||
---
|
||||
|
||||
<Layout meta={meta}>
|
||||
<Fragment slot="title">
|
||||
News and step-by-step guides about
|
||||
<span class="bg-clip-text text-transparent bg-gradient-to-r from-blue-500 to-pink-500">AstroWind
|
||||
</span>
|
||||
</Fragment>
|
||||
<BlogList page={page} />
|
||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||
</Layout>
|
33
src/pages/[...blog]/[slug].astro
Normal file
33
src/pages/[...blog]/[slug].astro
Normal file
@ -0,0 +1,33 @@
|
||||
---
|
||||
import { SITE, BLOG } from "~/config.mjs";
|
||||
import { getCanonical, getPermalink } from "~/utils/permalinks";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
import { findImage } from "~/utils/findImage";
|
||||
import Layout from "~/layouts/PageLayout.astro";
|
||||
import BlogPost from "~/components/widgets/BlogPost.astro";
|
||||
|
||||
|
||||
export async function getStaticPaths() {
|
||||
if (BLOG?.disabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.slug, blog: BLOG.postsWithoutBlogSlug ? undefined : BLOG?.slug || undefined },
|
||||
props: { post },
|
||||
}));
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
|
||||
const meta = {
|
||||
title: `${post.title} — ${SITE.name}`,
|
||||
description: post.description,
|
||||
canonical: post.canonical || getCanonical(getPermalink(post.slug, "post")),
|
||||
image: await findImage(post.image),
|
||||
}
|
||||
---
|
||||
|
||||
<Layout meta={meta}>
|
||||
<BlogPost post={{ ...post, image: meta.image }} />
|
||||
</Layout>
|
46
src/pages/[...categories]/[category]/[...page].astro
Normal file
46
src/pages/[...categories]/[category]/[...page].astro
Normal file
@ -0,0 +1,46 @@
|
||||
---
|
||||
import { SITE, BLOG } from "~/config.mjs";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
import Layout from "~/layouts/BlogLayout.astro";
|
||||
import BlogList from "~/components/widgets/BlogList.astro";
|
||||
import Pagination from "~/components/widgets/Pagination.astro";
|
||||
import { getCanonical, getPermalink } from "~/utils/permalinks";
|
||||
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
if (BLOG?.disabled || BLOG?.category?.disabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
|
||||
const categories = new Set()
|
||||
posts.map(post => {
|
||||
typeof post.category === "string" && categories.add(post.category.toLowerCase())
|
||||
})
|
||||
|
||||
return Array.from(categories).map((category) => (
|
||||
paginate(posts.filter((post) => typeof post.category === "string" && category === post.category.toLowerCase()), {
|
||||
params: { category, categories: BLOG?.category?.slug || undefined },
|
||||
pageSize: BLOG.postsPerPage,
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
const { page } = Astro.props;
|
||||
const { category } = Astro.params;
|
||||
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
|
||||
const meta = {
|
||||
title: `Category ${category} ${currentPage > 1 ? `— Page ${currentPage} ` : ""}— ${SITE.name}`,
|
||||
description: SITE.description,
|
||||
canonical: getCanonical(getPermalink(page.url.current))
|
||||
}
|
||||
---
|
||||
|
||||
<Layout meta={{ ...meta, noindex: true }}>
|
||||
<Fragment slot="title">
|
||||
Category {category}
|
||||
</Fragment>
|
||||
<BlogList page={page} />
|
||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||
</Layout>
|
46
src/pages/[...tags]/[tag]/[...page].astro
Normal file
46
src/pages/[...tags]/[tag]/[...page].astro
Normal file
@ -0,0 +1,46 @@
|
||||
---
|
||||
import { SITE, BLOG } from "~/config.mjs";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
import Layout from "~/layouts/BlogLayout.astro";
|
||||
import BlogList from "~/components/widgets/BlogList.astro";
|
||||
import Pagination from "~/components/widgets/Pagination.astro";
|
||||
import { getCanonical, getPermalink } from "~/utils/permalinks";
|
||||
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
if (BLOG?.disabled || BLOG?.tag?.disabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
|
||||
const tags = new Set()
|
||||
posts.map(post => {
|
||||
Array.isArray(post.tags) && post.tags.map(tag => tags.add(tag.toLowerCase()))
|
||||
})
|
||||
|
||||
return Array.from(tags).map((tag) => (
|
||||
paginate(posts.filter((post) => Array.isArray(post.tags) && post.tags.includes(tag)), {
|
||||
params: { tag, tags: BLOG?.tag?.slug || undefined },
|
||||
pageSize: BLOG.postsPerPage,
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
const { page } = Astro.props;
|
||||
const { tag } = Astro.params;
|
||||
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
|
||||
const meta = {
|
||||
title: `Posts by tag '${tag}' ${currentPage > 1 ? `— Page ${currentPage} ` : ""}— ${SITE.name}`,
|
||||
description: SITE.description,
|
||||
canonical: getCanonical(getPermalink(page.url.current))
|
||||
}
|
||||
---
|
||||
|
||||
<Layout meta={{ ...meta, noindex: true }}>
|
||||
<Fragment slot="title">
|
||||
Tag {tag}
|
||||
</Fragment>
|
||||
<BlogList page={page} />
|
||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||
</Layout>
|
@ -1,28 +0,0 @@
|
||||
---
|
||||
import Layout from "~/layouts/PageLayout.astro";
|
||||
|
||||
import { SITE } from "~/config.mjs";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
|
||||
import BlogList from "~/components/widgets/BlogList.astro";
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
const posts = await fetchPosts();
|
||||
|
||||
return paginate(posts, {
|
||||
pageSize: SITE.postsPerPage,
|
||||
});
|
||||
}
|
||||
|
||||
const { page } = Astro.props;
|
||||
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
|
||||
const title = `Blog ${currentPage > 1 ? `— Page ${currentPage} ` : ""}— ${SITE.name}`;
|
||||
const description = SITE.description;
|
||||
const canonical = new URL(page.url.current, Astro.site);
|
||||
---
|
||||
|
||||
<Layout meta={{ title, description, canonical }}>
|
||||
<BlogList page={page} />
|
||||
</Layout>
|
@ -1,29 +0,0 @@
|
||||
---
|
||||
import { SITE } from "~/config.mjs";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
import { findImage } from "~/utils/findImage";
|
||||
|
||||
import Layout from "~/layouts/PageLayout.astro";
|
||||
import BlogPost from "~/components/widgets/BlogPost.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await fetchPosts();
|
||||
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.slug },
|
||||
props: { post },
|
||||
}));
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
|
||||
const title = `${post.title} — ${SITE.name}`;
|
||||
const description = post.description;
|
||||
const canonical = post.canonical || new URL(`blog/${post.slug}`, Astro.site);
|
||||
|
||||
const image = await findImage(post.image);
|
||||
---
|
||||
|
||||
<Layout meta={{ title, description, canonical, image, }}>
|
||||
<BlogPost post={{ ...post, image }} />
|
||||
</Layout>
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
import Layout from "~/layouts/PageLayout.astro";
|
||||
|
||||
import { SITE } from "~/config.mjs";
|
||||
import { getCanonical, getHomePermalink } from "~/utils/permalinks";
|
||||
import Layout from "~/layouts/PageLayout.astro";
|
||||
|
||||
import Hero from "~/components/widgets/Hero.astro";
|
||||
import BasicCTA from "~/components/widgets/BasicCTA.astro";
|
||||
@ -13,12 +13,14 @@ import StepsLeft from "~/components/widgets/StepsLeft.astro";
|
||||
import HighlightedPosts from "~/components/widgets/HighlightedPosts.astro";
|
||||
import Stats from "~/components/widgets/Stats.astro";
|
||||
|
||||
const title = SITE.title;
|
||||
const description = SITE.description;
|
||||
const canonical = new URL("", Astro.site);
|
||||
const meta = {
|
||||
title: SITE.title,
|
||||
description: SITE.description,
|
||||
canonical: getCanonical(getHomePermalink()),
|
||||
}
|
||||
---
|
||||
|
||||
<Layout meta={{ title, description, canonical }}>
|
||||
<Layout meta={meta}>
|
||||
<Hero />
|
||||
<BasicFeatures />
|
||||
<StepsLeft />
|
||||
|
@ -2,6 +2,7 @@ import rss from "@astrojs/rss";
|
||||
|
||||
import { SITE } from "~/config.mjs";
|
||||
import { fetchPosts } from "~/utils/fetchPosts";
|
||||
import { getPermalink } from "~/utils/permalinks";
|
||||
|
||||
const posts = await fetchPosts();
|
||||
|
||||
@ -12,7 +13,7 @@ export const get = () =>
|
||||
site: import.meta.env.SITE,
|
||||
|
||||
items: posts.map((post) => ({
|
||||
link: `blog/${post.slug}`,
|
||||
link: getPermalink(post.slug, "post"),
|
||||
title: post.title,
|
||||
description: post.description,
|
||||
pubDate: post.pubDate,
|
||||
|
Reference in New Issue
Block a user