This commit is contained in:
parent
844d31754d
commit
36870785bc
35 changed files with 1344 additions and 1330 deletions
|
@ -1,11 +1,11 @@
|
|||
---
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Container from '@/components/Container.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import { SITE } from '@/consts'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { cn } from '@/lib/utils'
|
||||
import Breadcrumbs from "@/components/Breadcrumbs.astro";
|
||||
import Container from "@/components/Container.astro";
|
||||
import Link from "@/components/Link.astro";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { SITE } from "@/consts";
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
import { cn } from "@/lib/utils";
|
||||
---
|
||||
|
||||
<Layout title="404" description={SITE.description}>
|
||||
|
|
|
@ -1,37 +1,39 @@
|
|||
---
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Container from '@/components/Container.astro'
|
||||
import PaginationComponent from '@/components/ui/pagination'
|
||||
import { SITE } from '@/consts'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import type { PaginateFunction } from 'astro'
|
||||
import { type CollectionEntry, getCollection } from 'astro:content'
|
||||
import { type CollectionEntry, getCollection } from "astro:content";
|
||||
import BlogCard from "@/components/BlogCard.astro";
|
||||
import Breadcrumbs from "@/components/Breadcrumbs.astro";
|
||||
import Container from "@/components/Container.astro";
|
||||
import PaginationComponent from "@/components/ui/pagination";
|
||||
import { SITE } from "@/consts";
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
import type { PaginateFunction } from "astro";
|
||||
|
||||
export async function getStaticPaths({
|
||||
paginate,
|
||||
paginate,
|
||||
}: {
|
||||
paginate: PaginateFunction
|
||||
paginate: PaginateFunction;
|
||||
}) {
|
||||
const allPosts = await getCollection('blog', ({ data }) => !data.draft)
|
||||
return paginate(
|
||||
allPosts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()),
|
||||
{ pageSize: SITE.postsPerPage },
|
||||
)
|
||||
const allPosts = await getCollection("blog", ({ data }) => !data.draft);
|
||||
return paginate(
|
||||
allPosts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()),
|
||||
{ pageSize: SITE.postsPerPage },
|
||||
);
|
||||
}
|
||||
|
||||
const { page } = Astro.props
|
||||
const { page } = Astro.props;
|
||||
|
||||
const postsByYear = page.data.reduce(
|
||||
(acc: Record<string, CollectionEntry<'blog'>[]>, post) => {
|
||||
const year = post.data.date.getFullYear().toString()
|
||||
;(acc[year] ??= []).push(post)
|
||||
return acc
|
||||
},
|
||||
{},
|
||||
)
|
||||
(acc: Record<string, CollectionEntry<"blog">[]>, post) => {
|
||||
const year = post.data.date.getFullYear().toString();
|
||||
(acc[year] ??= []).push(post);
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
const years = Object.keys(postsByYear).sort((a, b) => parseInt(b) - parseInt(a))
|
||||
const years = Object.keys(postsByYear).sort(
|
||||
(a, b) => Number.parseInt(b) - Number.parseInt(a),
|
||||
);
|
||||
---
|
||||
|
||||
<Layout title="Blog" description="Blog">
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
---
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Container from '@/components/Container.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import { SITE } from '@/consts'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getCollection } from 'astro:content'
|
||||
import { getCollection } from "astro:content";
|
||||
import BlogCard from "@/components/BlogCard.astro";
|
||||
import Container from "@/components/Container.astro";
|
||||
import Link from "@/components/Link.astro";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { SITE } from "@/consts";
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
|
||||
const blog = (await getCollection('blog'))
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
||||
.slice(0, SITE.featuredPostCount)
|
||||
const blog = (await getCollection("blog"))
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
||||
.slice(0, SITE.featuredPostCount);
|
||||
---
|
||||
|
||||
<Layout title="Home" description={SITE.description}>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { APIRoute } from 'astro'
|
||||
import type { APIRoute } from "astro";
|
||||
|
||||
const getRobotsTxt = (sitemapURL: URL) => `
|
||||
User-agent: AI2Bot
|
||||
|
@ -49,9 +49,9 @@ User-agent: YouBot
|
|||
Disallow: /
|
||||
|
||||
Sitemap: ${sitemapURL.href}
|
||||
`
|
||||
`;
|
||||
|
||||
export const GET: APIRoute = ({ site }) => {
|
||||
const sitemapURL = new URL('sitemap-index.xml', site)
|
||||
return new Response(getRobotsTxt(sitemapURL))
|
||||
}
|
||||
const sitemapURL = new URL("sitemap-index.xml", site);
|
||||
return new Response(getRobotsTxt(sitemapURL));
|
||||
};
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
import { SITE } from '@/consts'
|
||||
import rss from '@astrojs/rss'
|
||||
import type { APIContext } from 'astro'
|
||||
import { getCollection } from 'astro:content'
|
||||
import { getCollection } from "astro:content";
|
||||
import { SITE } from "@/consts";
|
||||
import rss from "@astrojs/rss";
|
||||
import type { APIContext } from "astro";
|
||||
|
||||
export async function GET(context: APIContext) {
|
||||
try {
|
||||
const posts = await getCollection('blog', ({ data }) => !data.draft)
|
||||
posts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
||||
try {
|
||||
const posts = await getCollection("blog", ({ data }) => !data.draft);
|
||||
posts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
|
||||
return rss({
|
||||
title: SITE.title,
|
||||
description: SITE.description,
|
||||
site: context.site ?? SITE.href,
|
||||
items: posts.map((post) => ({
|
||||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
pubDate: post.data.date,
|
||||
link: `/blog/${post.id}/`,
|
||||
})),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error generating RSS feed:', error)
|
||||
return new Response('Error generating RSS feed', { status: 500 })
|
||||
}
|
||||
return rss({
|
||||
title: SITE.title,
|
||||
description: SITE.description,
|
||||
site: context.site ?? SITE.href,
|
||||
items: posts.map((post) => ({
|
||||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
pubDate: post.data.date,
|
||||
link: `/blog/${post.id}/`,
|
||||
})),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error generating RSS feed:", error);
|
||||
return new Response("Error generating RSS feed", { status: 500 });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue