mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 23:32:53 +01:00
feat: initial commit
(cherry picked from commit 44c4d7b9521fe449e61edc614446195861932f8c)
This commit is contained in:
35
src/pages/archive/category/[category].astro
Normal file
35
src/pages/archive/category/[category].astro
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
|
||||
import {getSortedPosts} from "../../../utils/content-utils";
|
||||
import MainGridLayout from "../../../layouts/MainGridLayout.astro";
|
||||
import ArchivePanel from "../../../components/ArchivePanel.astro";
|
||||
|
||||
|
||||
export async function getStaticPaths() {
|
||||
let posts = await getSortedPosts()
|
||||
|
||||
const allCategories = posts.reduce((acc, post) => {
|
||||
if (!Array.isArray(post.data.categories))
|
||||
return acc;
|
||||
post.data.categories.forEach(category => acc.add(category));
|
||||
return acc;
|
||||
}, new Set());
|
||||
|
||||
const allCategoriesArray = Array.from(allCategories);
|
||||
|
||||
return allCategoriesArray.map(category => {
|
||||
return {
|
||||
params: {
|
||||
category: category
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const { category } = Astro.params;
|
||||
|
||||
---
|
||||
|
||||
<MainGridLayout>
|
||||
<ArchivePanel categories={[category]}></ArchivePanel>
|
||||
</MainGridLayout>
|
||||
10
src/pages/archive/index.astro
Normal file
10
src/pages/archive/index.astro
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
import { getCollection, getEntry } from "astro:content";
|
||||
import MainGridLayout from "../../layouts/MainGridLayout.astro";
|
||||
import ArchivePanel from "../../components/ArchivePanel.astro";
|
||||
---
|
||||
|
||||
<MainGridLayout>
|
||||
<ArchivePanel></ArchivePanel>
|
||||
</MainGridLayout>
|
||||
|
||||
34
src/pages/archive/tag/[tag].astro
Normal file
34
src/pages/archive/tag/[tag].astro
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
|
||||
import {getSortedPosts} from "../../../utils/content-utils";
|
||||
import MainGridLayout from "../../../layouts/MainGridLayout.astro";
|
||||
import ArchivePanel from "../../../components/ArchivePanel.astro";
|
||||
|
||||
|
||||
|
||||
export async function getStaticPaths() {
|
||||
let posts = await getSortedPosts()
|
||||
|
||||
const allTags = posts.reduce((acc, post) => {
|
||||
post.data.tags.forEach(tag => acc.add(tag));
|
||||
return acc;
|
||||
}, new Set());
|
||||
|
||||
const allTagsArray = Array.from(allTags);
|
||||
|
||||
return allTagsArray.map(tag => {
|
||||
return {
|
||||
params: {
|
||||
tag: tag
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const { tag } = Astro.params;
|
||||
|
||||
---
|
||||
|
||||
<MainGridLayout>
|
||||
<ArchivePanel tags={[tag]}></ArchivePanel>
|
||||
</MainGridLayout>
|
||||
3
src/pages/index.astro
Normal file
3
src/pages/index.astro
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
|
||||
---
|
||||
41
src/pages/page/[page].astro
Normal file
41
src/pages/page/[page].astro
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
import { getCollection, getEntry } from "astro:content";
|
||||
import MainGridLayout from "../../layouts/MainGridLayout.astro";
|
||||
import TitleCard from "../../components/TitleCardNew.astro";
|
||||
import Pagination from "../../components/control/Pagination.astro";
|
||||
import {getPostUrlBySlug, getSortedPosts} from "../../utils/content-utils";
|
||||
import {getConfig} from "../../utils/config-utils";
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
// const allBlogPosts = await getCollection("posts");
|
||||
const allBlogPosts = await getSortedPosts();
|
||||
return paginate(allBlogPosts, { pageSize: 6 });
|
||||
}
|
||||
|
||||
const {page} = Astro.props;
|
||||
|
||||
// page.data.map(entry => console.log(entry));
|
||||
// console.log(page)
|
||||
|
||||
// console.log(getConfig());
|
||||
|
||||
---
|
||||
|
||||
<!-- 显示当前页面。也可以使用 Astro.params.page -->
|
||||
<MainGridLayout>
|
||||
<div class="flex flex-col gap-4 mb-4">
|
||||
{page.data.map(entry =>
|
||||
<TitleCard
|
||||
entry={entry}
|
||||
title={entry.data.title}
|
||||
tags={entry.data.tags}
|
||||
categories={entry.data.categories}
|
||||
pubDate={entry.data.pubDate}
|
||||
url={getPostUrlBySlug(entry.slug)}
|
||||
cover={entry.data.cover}
|
||||
description={entry.data.description}
|
||||
></TitleCard>
|
||||
)}
|
||||
</div>
|
||||
<Pagination class="mx-auto" page={page}></Pagination>
|
||||
</MainGridLayout>
|
||||
73
src/pages/posts/[slug].astro
Normal file
73
src/pages/posts/[slug].astro
Normal file
@@ -0,0 +1,73 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import MainGridLayout from "../../layouts/MainGridLayout.astro";
|
||||
import ButtonTag from "../../components/control/ButtonTag.astro";
|
||||
import ImageBox from "../../components/misc/ImageBox.astro";
|
||||
import {Icon} from "astro-icon/components";
|
||||
import {formatDateToYYYYMMDD} from "../../utils/date-utils";
|
||||
import PostMetadata from "../../components/PostMetadata.astro";
|
||||
// 1. 为每个集合条目生成一个新路径
|
||||
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const blogEntries = await getCollection('posts');
|
||||
return blogEntries.map(entry => ({
|
||||
params: { slug: entry.slug }, props: { entry },
|
||||
}));
|
||||
}
|
||||
// 2. 当渲染的时候,你可以直接从属性中得到条目
|
||||
const { entry } = Astro.props;
|
||||
const { Content } = await entry.render();
|
||||
|
||||
const { remarkPluginFrontmatter } = await entry.render();
|
||||
|
||||
|
||||
---
|
||||
<MainGridLayout banner={entry.data.cover}>
|
||||
<div class="flex w-full rounded-[var(--radius-large)] overflow-hidden relative">
|
||||
<div class:list={["card-base z-10 px-9 py-6 relative w-full ",
|
||||
{}
|
||||
]}>
|
||||
<div class="flex flex-row text-black/30 dark:text-white/30 gap-5 mb-3 transition">
|
||||
<div class="flex flex-row items-center">
|
||||
<div class="transition h-6 w-6 rounded-md bg-black/5 dark:bg-white/5 text-black/50 dark:text-white/50 flex items-center justify-center mr-2">
|
||||
<Icon name="material-symbols:notes-rounded"></Icon>
|
||||
</div>
|
||||
<div class="text-sm">{remarkPluginFrontmatter.words} words</div>
|
||||
</div>
|
||||
<div class="flex flex-row items-center">
|
||||
<div class="transition h-6 w-6 rounded-md bg-black/5 dark:bg-white/5 text-black/50 dark:text-white/50 flex items-center justify-center mr-2">
|
||||
<Icon name="material-symbols:schedule-outline-rounded"></Icon>
|
||||
</div>
|
||||
<div class="text-sm">{remarkPluginFrontmatter.minutes} minutes</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="relative">
|
||||
<div
|
||||
class="transition w-full block font-bold mb-3 text-4xl
|
||||
text-black/90 dark:text-white/90
|
||||
before:w-1 before:h-5 before:rounded-md before:bg-[var(--primary)]
|
||||
before:absolute before:top-[10px] before:left-[-18px]
|
||||
">
|
||||
{entry.data.title}
|
||||
</div>
|
||||
</div>
|
||||
<PostMetadata
|
||||
class="mb-5"
|
||||
pubDate={entry.data.pubDate}
|
||||
tags={entry.data.tags}
|
||||
categories={entry.data.categories}
|
||||
></PostMetadata>
|
||||
|
||||
<div class="border-b-black/8 dark:border-b-white/8 border-dashed border-b-[1px] mb-5"></div>
|
||||
|
||||
<div class="prose dark:prose-invert max-w-none prose-h1:text-3xl">
|
||||
<Content />
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</MainGridLayout>
|
||||
Reference in New Issue
Block a user