fix: filter out draft posts in pagination and tag collection
This commit is contained in:
parent
6b831e7100
commit
9862f3fa24
4 changed files with 8 additions and 5 deletions
|
|
@ -13,8 +13,9 @@ export async function getStaticPaths({
|
||||||
paginate: PaginateFunction;
|
paginate: PaginateFunction;
|
||||||
}) {
|
}) {
|
||||||
const posts = await getCollection("blog");
|
const posts = await getCollection("blog");
|
||||||
posts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
|
const filteredPosts = posts.filter((post) => !post.data.draft);
|
||||||
return paginate(posts, { pageSize: 5 });
|
filteredPosts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
|
||||||
|
return paginate(filteredPosts, { pageSize: 10 });
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,9 @@ import BlogPost from "@/components/BlogPost.astro";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await getCollection("blog");
|
const posts = await getCollection("blog");
|
||||||
|
const filteredPosts = posts.filter((post) => !post.data.draft);
|
||||||
const paths = await Promise.all(
|
const paths = await Promise.all(
|
||||||
posts.map(async (post) => {
|
filteredPosts.map(async (post) => {
|
||||||
const id = post.id;
|
const id = post.id;
|
||||||
const content = await render(post);
|
const content = await render(post);
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export async function getStaticPaths() {
|
||||||
const tags = new Set<string>();
|
const tags = new Set<string>();
|
||||||
|
|
||||||
posts.forEach((post) => {
|
posts.forEach((post) => {
|
||||||
if (post.data.tags) {
|
if (post.data.tags && !post.data.draft) {
|
||||||
post.data.tags.forEach((tag: string) => tags.add(tag));
|
post.data.tags.forEach((tag: string) => tags.add(tag));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ import PageTitle from "@/components/PageTitle.astro";
|
||||||
import Tag from "@/components/Tag.astro";
|
import Tag from "@/components/Tag.astro";
|
||||||
|
|
||||||
const posts = await getCollection("blog");
|
const posts = await getCollection("blog");
|
||||||
|
const filteredPosts = posts.filter((post) => !post.data.draft);
|
||||||
const tagsMap = new Map<string, number>();
|
const tagsMap = new Map<string, number>();
|
||||||
posts.forEach((post) => {
|
filteredPosts.forEach((post) => {
|
||||||
post.data.tags?.forEach((tag) => {
|
post.data.tags?.forEach((tag) => {
|
||||||
const currentCount = tagsMap.get(tag) || 0;
|
const currentCount = tagsMap.get(tag) || 0;
|
||||||
tagsMap.set(tag, currentCount + 1);
|
tagsMap.set(tag, currentCount + 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue