mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-11 23:02:53 +01:00
fix: minor fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import {UNCATEGORIZED} from "@constants/constants";
|
||||
interface Props {
|
||||
keyword: string;
|
||||
tags: string[];
|
||||
@@ -9,6 +10,8 @@ const { keyword, tags, categories} = Astro.props;
|
||||
import Button from "./control/Button.astro";
|
||||
import {getSortedPosts} from "../utils/content-utils";
|
||||
import {getPostUrlBySlug} from "../utils/url-utils";
|
||||
import {i18n} from "../i18n/translation";
|
||||
import I18nKey from "../i18n/i18nKey";
|
||||
|
||||
let posts = await getSortedPosts()
|
||||
|
||||
@@ -20,7 +23,8 @@ if (Array.isArray(tags) && tags.length > 0) {
|
||||
|
||||
if (Array.isArray(categories) && categories.length > 0) {
|
||||
posts = posts.filter(post =>
|
||||
post.data.category && categories.includes(post.data.category)
|
||||
(post.data.category && categories.includes(post.data.category)) ||
|
||||
(!post.data.category && categories.includes(UNCATEGORIZED))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,7 +70,7 @@ function formatTag(tag: string[]) {
|
||||
<div class="w-[10%]">
|
||||
<div class="h-3 w-3 bg-none rounded-full outline outline-[var(--primary)] mx-auto -outline-offset-[2px] z-50 outline-3"></div>
|
||||
</div>
|
||||
<div class="w-[80%] transition text-left text-black/50 dark:text-white/50">{group.posts.length} Articles</div>
|
||||
<div class="w-[80%] transition text-left text-black/50 dark:text-white/50">{group.posts.length} {i18n(I18nKey.postsCount)}</div>
|
||||
</div>
|
||||
{group.posts.map(post => (
|
||||
<a href={getPostUrlBySlug(post.slug)} aria-label={post.data.title} class="group">
|
||||
|
||||
@@ -4,7 +4,7 @@ const postsCollection = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
published: z.date(),
|
||||
draft: z.boolean(),
|
||||
draft: z.boolean().optional(),
|
||||
description: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
tags: z.array(z.string()).optional(),
|
||||
|
||||
@@ -20,8 +20,8 @@ export const ja: Translation = {
|
||||
[Key.wordsCount]: '文字',
|
||||
[Key.minuteCount]: '分',
|
||||
[Key.minutesCount]: '分',
|
||||
[Key.postCount]: 'post',
|
||||
[Key.postsCount]: 'posts',
|
||||
[Key.postCount]: '件の投稿',
|
||||
[Key.postsCount]: '件の投稿',
|
||||
|
||||
[Key.primaryColor]: '原色',
|
||||
|
||||
|
||||
11
src/pages/archive/category/uncategorized.astro
Normal file
11
src/pages/archive/category/uncategorized.astro
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
import MainGridLayout from "@layouts/MainGridLayout.astro";
|
||||
import ArchivePanel from "@components/ArchivePanel.astro";
|
||||
import {i18n} from "@i18n/translation";
|
||||
import I18nKey from "@i18n/i18nKey";
|
||||
import {UNCATEGORIZED} from "@constants/constants";
|
||||
---
|
||||
|
||||
<MainGridLayout title={i18n(I18nKey.archive)}>
|
||||
<ArchivePanel categories={[UNCATEGORIZED]}></ArchivePanel>
|
||||
</MainGridLayout>
|
||||
@@ -7,22 +7,16 @@ import {getPostUrlBySlug} from "@utils/url-utils";
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
const allBlogPosts = await getSortedPosts();
|
||||
return paginate(allBlogPosts, { pageSize: 6 });
|
||||
return paginate(allBlogPosts, { pageSize: 8 });
|
||||
}
|
||||
|
||||
const {page} = Astro.props;
|
||||
|
||||
---
|
||||
|
||||
<!-- 显示当前页面。也可以使用 Astro.params.page -->
|
||||
<MainGridLayout>
|
||||
<div class="flex flex-col gap-4 mb-4">
|
||||
{page.data.map((entry: { data: { draft: boolean; title: string; tags: string[]; category: string; published: Date; image: string; description: string; }; slug: string; }) => {
|
||||
// ここで draft が true の場合は何もレンダリングしない
|
||||
if (import.meta.env.PROD && entry.data.draft) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<TitleCard
|
||||
entry={entry}
|
||||
@@ -41,11 +35,3 @@ const {page} = Astro.props;
|
||||
</div>
|
||||
<Pagination class="mx-auto" page={page}></Pagination>
|
||||
</MainGridLayout>
|
||||
|
||||
<script>
|
||||
if (import.meta.env.DEV) {
|
||||
console.log("開発環境");
|
||||
} else {
|
||||
console.log("本番環境");
|
||||
}
|
||||
</script>
|
||||
@@ -1,7 +1,9 @@
|
||||
import { getCollection } from 'astro:content'
|
||||
|
||||
export async function getSortedPosts() {
|
||||
const allBlogPosts = await getCollection('posts')
|
||||
const allBlogPosts = await getCollection('posts', ({ data }) => {
|
||||
return import.meta.env.PROD ? data.draft !== true : true;
|
||||
})
|
||||
const sorted = allBlogPosts.sort((a, b) => {
|
||||
const dateA = new Date(a.data.published)
|
||||
const dateB = new Date(b.data.published)
|
||||
@@ -26,7 +28,9 @@ export type Tag = {
|
||||
}
|
||||
|
||||
export async function getTagList(): Promise<Tag[]> {
|
||||
const allBlogPosts = await getCollection('posts')
|
||||
const allBlogPosts = await getCollection('posts', ({ data }) => {
|
||||
return import.meta.env.PROD ? data.draft !== true : true;
|
||||
})
|
||||
|
||||
const countMap: { [key: string]: number } = {}
|
||||
allBlogPosts.map(post => {
|
||||
@@ -50,7 +54,9 @@ export type Category = {
|
||||
}
|
||||
|
||||
export async function getCategoryList(): Promise<Category[]> {
|
||||
const allBlogPosts = await getCollection('posts')
|
||||
const allBlogPosts = await getCollection('posts', ({ data }) => {
|
||||
return import.meta.env.PROD ? data.draft !== true : true;
|
||||
})
|
||||
const count: { [key: string]: number } = {}
|
||||
allBlogPosts.map(post => {
|
||||
if (!post.data.category) {
|
||||
|
||||
Reference in New Issue
Block a user