refactor(all): biomejs
This commit is contained in:
parent
9c22eceaf7
commit
a519150e9f
29 changed files with 540 additions and 489 deletions
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Container from "@components/Container.astro";
|
||||
import { SITE } from "@consts";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
---
|
||||
|
||||
<Layout title="404" description={SITE.DESCRIPTION}>
|
||||
|
|
|
@ -1,41 +1,45 @@
|
|||
---
|
||||
import { type CollectionEntry, getCollection, render } from "astro:content";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Container from "@components/Container.astro";
|
||||
import FormattedDate from "@components/FormattedDate.astro";
|
||||
import { readingTime } from "@lib/utils";
|
||||
import PostNavigation from "@components/PostNavigation.astro";
|
||||
import TableOfContents from "@components/TableOfContents.astro";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import { readingTime } from "@lib/utils";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = (await getCollection("blog")).filter((post) => !post.data.draft).sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
return posts.map((post) => ({
|
||||
params: { id: post.id },
|
||||
props: post,
|
||||
}));
|
||||
const posts = (await getCollection("blog"))
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
return posts.map((post) => ({
|
||||
params: { id: post.id },
|
||||
props: post,
|
||||
}));
|
||||
}
|
||||
type Props = CollectionEntry<"blog">;
|
||||
|
||||
const posts = (await getCollection("blog")).filter((post) => !post.data.draft).sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
const posts = (await getCollection("blog"))
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
|
||||
function getNextPost() {
|
||||
let postIndex;
|
||||
for (const post of posts) {
|
||||
if (post.id === Astro.params.id) {
|
||||
postIndex = posts.indexOf(post);
|
||||
return posts[postIndex + 1];
|
||||
}
|
||||
}
|
||||
let postIndex;
|
||||
for (const post of posts) {
|
||||
if (post.id === Astro.params.id) {
|
||||
postIndex = posts.indexOf(post);
|
||||
return posts[postIndex + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPrevPost() {
|
||||
let postIndex;
|
||||
for (const post of posts) {
|
||||
if (post.id === Astro.params.id) {
|
||||
postIndex = posts.indexOf(post);
|
||||
return posts[postIndex - 1];
|
||||
}
|
||||
}
|
||||
let postIndex;
|
||||
for (const post of posts) {
|
||||
if (post.id === Astro.params.id) {
|
||||
postIndex = posts.indexOf(post);
|
||||
return posts[postIndex - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nextPost = getNextPost();
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
---
|
||||
import { type CollectionEntry, getCollection } from "astro:content";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Container from "@components/Container.astro";
|
||||
import ArrowCard from "@components/ArrowCard.astro";
|
||||
import Container from "@components/Container.astro";
|
||||
import { SITE } from "@consts";
|
||||
import { HOME } from "@consts";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
|
||||
const data = (await getCollection("blog")).filter((post) => !post.data.draft).sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
const data = (await getCollection("blog"))
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
|
||||
type Acc = {
|
||||
[year: string]: CollectionEntry<"blog">[];
|
||||
[year: string]: CollectionEntry<"blog">[];
|
||||
};
|
||||
|
||||
const posts = data.reduce((acc: Acc, post) => {
|
||||
const year = post.data.date.getFullYear().toString();
|
||||
if (!acc[year]) {
|
||||
acc[year] = [];
|
||||
}
|
||||
acc[year].push(post);
|
||||
return acc;
|
||||
const year = post.data.date.getFullYear().toString();
|
||||
if (!acc[year]) {
|
||||
acc[year] = [];
|
||||
}
|
||||
acc[year].push(post);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const years = Object.keys(posts).sort((a, b) => parseInt(b) - parseInt(a));
|
||||
const years = Object.keys(posts).sort(
|
||||
(a, b) => Number.parseInt(b) - Number.parseInt(a),
|
||||
);
|
||||
---
|
||||
|
||||
<Layout title={HOME.TITLE} description={SITE.DESCRIPTION}>
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
import { getCollection } from "astro:content";
|
||||
import rss from "@astrojs/rss";
|
||||
import { SITE } from "@consts";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
export async function GET(context) {
|
||||
const blog = (await getCollection("blog")).filter((post) => !post.data.draft);
|
||||
const blog = (await getCollection("blog")).filter((post) => !post.data.draft);
|
||||
|
||||
const items = [...blog].sort(
|
||||
(a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
|
||||
);
|
||||
|
||||
const items = [...blog].sort(
|
||||
(a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
|
||||
);
|
||||
|
||||
return rss({
|
||||
title: SITE.TITLE,
|
||||
description: SITE.DESCRIPTION,
|
||||
site: context.site,
|
||||
items: items.map((item) => ({
|
||||
title: item.data.title,
|
||||
description: item.data.description,
|
||||
pubDate: item.data.date,
|
||||
link: `/${item.id}/`,
|
||||
})),
|
||||
});
|
||||
return rss({
|
||||
title: SITE.TITLE,
|
||||
description: SITE.DESCRIPTION,
|
||||
site: context.site,
|
||||
items: items.map((item) => ({
|
||||
title: item.data.title,
|
||||
description: item.data.description,
|
||||
pubDate: item.data.date,
|
||||
link: `/${item.id}/`,
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue