Update formats of a blog page

This commit is contained in:
Daisuke Nakahara 2025-05-09 20:20:02 +09:00
parent c23ff1633c
commit fc2a5be2e7
4 changed files with 16 additions and 9 deletions

View file

@ -1,10 +1,8 @@
// Import the glob loader
import { glob } from "astro/loaders"; import { glob } from "astro/loaders";
// Import utilities from `astro:content`
import { z, defineCollection } from "astro:content"; import { z, defineCollection } from "astro:content";
// Define a `loader` and `schema` for each collection
const blog = defineCollection({ const blog = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), loader: glob({ pattern: '**/post-*.md', base: "./src/blog" }),
schema: z.object({ schema: z.object({
title: z.string(), title: z.string(),
pubDate: z.date(), pubDate: z.date(),
@ -12,5 +10,5 @@ const blog = defineCollection({
tags: z.array(z.string()) tags: z.array(z.string())
}) })
}); });
// Export a single `collections` object to register your collection(s)
export const collections = { blog }; export const collections = { blog };

View file

@ -1,13 +1,20 @@
--- ---
import BaseLayout from "./BaseLayout.astro"; import BaseLayout from "./BaseLayout.astro";
const { frontmatter } = Astro.props; const { frontmatter } = Astro.props;
const optionsForDate = {
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
timeZoneName:"short"
};
--- ---
<BaseLayout pageTitle={frontmatter.title}> <BaseLayout pageTitle={frontmatter.title}>
<p>{frontmatter.pubDate.toLocaleDateString()}</p> <p>Created on: {frontmatter.pubDate.toLocaleDateString("ja-JP", optionsForDate)}</p>
<p><em>{frontmatter.description}</em></p>
<p>Written by: {frontmatter.author}</p> <p>Written by: {frontmatter.author}</p>
<img src={frontmatter.image.url} width="300" alt={frontmatter.image.alt} /> <p><em>{frontmatter.description}</em></p>
<div class="tags"> <div class="tags">
{ {
frontmatter.tags.map((tag: string) => ( frontmatter.tags.map((tag: string) => (

View file

@ -9,6 +9,8 @@
], ],
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",
"jsxImportSource": "preact" "jsxImportSource": "preact",
"strictNullChecks": true,
"allowJs": true
} }
} }