diff --git a/README.md b/README.md index 0fa9429..09fb8fd 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Fuwari (not the final name maybe) is a static blog template built with [Astro](h 1. [Generate a new repository](https://github.com/saicaca/fuwari/generate) from this template. 2. Edit the config file `src/config.ts` to customize your blog. -3. Run `pnpm run new-post -- ` to create a new post and edit it in `src/content/posts/`. +3. Run `npm run new-post -- ` or `pnpm run new-post ` to create a new post and edit it in `src/content/posts/`. 4. Deploy your blog to Vercel, Netlify, GitHub Pages, etc. following [the guides](https://docs.astro.build/en/guides/deploy/). ## ⚙️ Frontmatter of Posts @@ -38,6 +38,7 @@ description: This is the first post of my new Astro blog. image: /images/cover.jpg tags: [Foo, Bar] category: Front-end +draft: false --- ``` @@ -45,12 +46,12 @@ category: Front-end All commands are run from the root of the project, from a terminal: -| Command | Action | -|:---------------------------------|:-------------------------------------------------| -| `pnpm install` | Installs dependencies | -| `pnpm run dev` | Starts local dev server at `localhost:4321` | -| `pnpm run build` | Build your production site to `./dist/` | -| `pnpm run preview` | Preview your build locally, before deploying | -| `pnpm run astro ...` | Run CLI commands like `astro add`, `astro check` | -| `pnpm run astro -- --help` | Get help using the Astro CLI | -| `pnpm run new-post -- ` | Create a new post | +| Command | Action | +|:------------------------------------------------------------------|:-------------------------------------------------| +| `npm install` | Installs dependencies | +| `npm run dev` | Starts local dev server at `localhost:4321` | +| `npm run build` | Build your production site to `./dist/` | +| `npm run preview` | Preview your build locally, before deploying | +| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | +| `npm run astro -- --help` | Get help using the Astro CLI | +| `npm run new-post -- `
`pnpm run new-post ` | Create a new post | diff --git a/scripts/new-post.js b/scripts/new-post.js index 829dec3..828b7c3 100644 --- a/scripts/new-post.js +++ b/scripts/new-post.js @@ -37,10 +37,11 @@ if (fs.existsSync(fullPath)) { const content = `--- title: ${args[0]} published: ${getDate()} -description: -image: +description: '' +image: '' tags: [] -category: +category: '' +draft: false --- ` diff --git a/src/components/ArchivePanel.astro b/src/components/ArchivePanel.astro index 9a59a9d..4a1a783 100644 --- a/src/components/ArchivePanel.astro +++ b/src/components/ArchivePanel.astro @@ -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[]) {
-
{group.posts.length} Articles
+
{group.posts.length} {i18n(I18nKey.postsCount)}
{group.posts.map(post => ( diff --git a/src/content/config.ts b/src/content/config.ts index 7cbb7fa..5066aaa 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -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(), diff --git a/src/i18n/languages/ja.ts b/src/i18n/languages/ja.ts index 9a8812d..e575c4f 100644 --- a/src/i18n/languages/ja.ts +++ b/src/i18n/languages/ja.ts @@ -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]: '原色', diff --git a/src/pages/archive/category/uncategorized.astro b/src/pages/archive/category/uncategorized.astro new file mode 100644 index 0000000..d580146 --- /dev/null +++ b/src/pages/archive/category/uncategorized.astro @@ -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"; +--- + + + + diff --git a/src/pages/page/[page].astro b/src/pages/page/[page].astro index cb76b96..c9ceb9a 100644 --- a/src/pages/page/[page].astro +++ b/src/pages/page/[page].astro @@ -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; --- -
{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 ( - - \ No newline at end of file diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index 526be3d..92e3a65 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -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 { - 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 { - 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) {