From 288076d6f513fbda79b3a671b65cfb323475207d Mon Sep 17 00:00:00 2001 From: rai Date: Mon, 1 Jan 2024 17:50:33 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20/about-us,=20/contact,=20/links?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Elements/LinkCard/LinkCard.astro | 22 ++++++---- src/content/config.ts | 40 +++++++++++-------- src/content/pages/about-us/index.mdx | 5 ++- src/content/pages/contact/index.mdx | 1 + src/content/pages/links/index.mdx | 1 + src/layouts/PageLayout/PageLayout.astro | 36 +++++++++++++++++ src/layouts/PageLayout/index.ts | 1 + src/layouts/PostLayout/PostLayout.astro | 9 +---- src/pages/[...slug]/index.astro | 26 ++++++++++++ src/styles/katex.css | 3 ++ 10 files changed, 112 insertions(+), 32 deletions(-) create mode 100644 src/layouts/PageLayout/PageLayout.astro create mode 100644 src/layouts/PageLayout/index.ts create mode 100644 src/pages/[...slug]/index.astro create mode 100644 src/styles/katex.css diff --git a/src/components/Elements/LinkCard/LinkCard.astro b/src/components/Elements/LinkCard/LinkCard.astro index aff6d2fb..1fe027bb 100644 --- a/src/components/Elements/LinkCard/LinkCard.astro +++ b/src/components/Elements/LinkCard/LinkCard.astro @@ -4,8 +4,12 @@ import { twMerge } from "tailwind-merge" import { unfurl } from "unfurl.js" import { Icon } from "../Icon" -type Props = HTMLAttributes<"a"> -const { href, ...props } = Astro.props +type Props = HTMLAttributes<"a"> & { + title?: string + description?: string + image?: string +} +const { href, title, description, image, ...props } = Astro.props const url = new URL(href ?? "") const metadata = await unfurl(url.href).catch(() => undefined) @@ -23,7 +27,11 @@ const shouldInvertFavicon = url.hostname.includes("github") >

{og?.title ?? href}

- {og?.description &&

{og.description}

} + { + (description || og?.description) && ( +

{description ?? og?.description}

+ ) + }
{ favicon ? ( @@ -32,16 +40,16 @@ const shouldInvertFavicon = url.hostname.includes("github") ) } -

{url.hostname}

+

{title ?? url.hostname}

{ - og?.images && ( + (image || og?.images) && (
{og.images[0].alt
diff --git a/src/content/config.ts b/src/content/config.ts index 6fb10466..a939ea17 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -2,7 +2,7 @@ import { z, defineCollection } from "astro:content" import { categories } from "./categories" import { zodEnumFromObj } from "@/lib/zod" -export const postSchema = z +export const postsSchema = z .object({ title: z.string(), draft: z.boolean(), @@ -11,19 +11,9 @@ export const postSchema = z categories: z.array(zodEnumFromObj(categories)), tags: z.array(z.string()).optional(), icon: z.string(), - links: z - .array( - z.object({ - title: z.string().optional(), - description: z.string().optional(), - website: z.string().url(), - image: z.string().url().optional(), - }), - ) - .optional(), }) .strict() -export type PostSchema = z.infer +export type PostsSchema = z.infer export const membersSchema = z.object({ name: z.string(), @@ -40,14 +30,32 @@ export const membersSchema = z.object({ }) export type MembersSchema = z.infer -const postColection = defineCollection({ +export const pagesSchema = z.object({ + title: z.string(), + draft: z.boolean(), + date: z.date().optional(), + lastmod: z.date().optional(), + links: z + .array( + z.object({ + title: z.string().optional(), + description: z.string().optional(), + website: z.string().url(), + image: z.string().url().optional(), + }), + ) + .optional(), +}) +export type PagesSchema = z.infer + +const postsCollection = defineCollection({ type: "content", - schema: postSchema, + schema: postsSchema, }) const pagesCollection = defineCollection({ type: "content", - schema: postSchema, + schema: pagesSchema, }) const membersCollection = defineCollection({ @@ -56,7 +64,7 @@ const membersCollection = defineCollection({ }) export const collections = { - post: postColection, + post: postsCollection, pages: pagesCollection, members: membersCollection, } diff --git a/src/content/pages/about-us/index.mdx b/src/content/pages/about-us/index.mdx index 1e6ba97b..63af10eb 100644 --- a/src/content/pages/about-us/index.mdx +++ b/src/content/pages/about-us/index.mdx @@ -1,7 +1,8 @@ --- title: RICORAについて -date: "2022-02-15" -lastmod: "2022-02-15" +draft: false +date: 2022-02-15 +lastmod: 2022-02-15 slug: about-us --- diff --git a/src/content/pages/contact/index.mdx b/src/content/pages/contact/index.mdx index 5dbf913d..4f71002e 100644 --- a/src/content/pages/contact/index.mdx +++ b/src/content/pages/contact/index.mdx @@ -1,5 +1,6 @@ --- title: お問い合わせ +draft: false date: 2022-03-15T00:00:00+09:00 lastmod: 2023-06-16T00:00:00+09:00 slug: contact diff --git a/src/content/pages/links/index.mdx b/src/content/pages/links/index.mdx index fae1a168..a381bc8d 100644 --- a/src/content/pages/links/index.mdx +++ b/src/content/pages/links/index.mdx @@ -1,5 +1,6 @@ --- title: リンク +draft: false links: - title: RICORA description: Music TeamとProgramming Teamを合わせた、RICORA全体のホームページです。 diff --git a/src/layouts/PageLayout/PageLayout.astro b/src/layouts/PageLayout/PageLayout.astro new file mode 100644 index 00000000..2408057a --- /dev/null +++ b/src/layouts/PageLayout/PageLayout.astro @@ -0,0 +1,36 @@ +--- +import "@/styles/katex.css" +import { BaseLayout, type BaseLayoutProps } from "@/layouts/BaseLayout" +import type { CollectionEntry } from "astro:content" +import { mdxComponents } from "@/lib/mdx" +import { LinkCard } from "@/components/Elements/LinkCard" + +export type Props = BaseLayoutProps & { + page: CollectionEntry<"pages"> +} +const { page, ...props } = Astro.props + +const { Content } = await page.render() +--- + + +
+
+
+

{page.data.title}

+
+
+ { + page.data.links && ( +
+ {page.data.links.map((link) => ( + + ))} +
+ ) + } + +
+
+
+
diff --git a/src/layouts/PageLayout/index.ts b/src/layouts/PageLayout/index.ts new file mode 100644 index 00000000..1276da2b --- /dev/null +++ b/src/layouts/PageLayout/index.ts @@ -0,0 +1 @@ +export { default as PageLayout } from "./PageLayout.astro" diff --git a/src/layouts/PostLayout/PostLayout.astro b/src/layouts/PostLayout/PostLayout.astro index 0fbf7c8a..8d35f249 100644 --- a/src/layouts/PostLayout/PostLayout.astro +++ b/src/layouts/PostLayout/PostLayout.astro @@ -1,4 +1,5 @@ --- +import "@/styles/katex.css" import { Icon, type IconName } from "@/components/Elements/Icon" import { BaseLayout, type BaseLayoutProps } from "@/layouts/BaseLayout" import { formatDate } from "@/lib/date" @@ -15,7 +16,7 @@ const { Content } = await post.render() const date = formatDate(post.data.date) const lastmod = post.data.lastmod ? formatDate(post.data.lastmod) : undefined -const readingTime = calculateReadingTime(post.data.content) +const readingTime = calculateReadingTime(post.body) --- @@ -54,9 +55,3 @@ const readingTime = calculateReadingTime(post.data.content) - - diff --git a/src/pages/[...slug]/index.astro b/src/pages/[...slug]/index.astro new file mode 100644 index 00000000..2edb44b3 --- /dev/null +++ b/src/pages/[...slug]/index.astro @@ -0,0 +1,26 @@ +--- +import "katex/dist/katex.min.css" +import { isDev } from "@/lib/runtime" +import { getCollection } from "astro:content" +import type { CollectionEntry } from "astro:content" +import { PageLayout } from "@/layouts/PageLayout" + +export const getStaticPaths = async () => { + const postEntries = await getCollection("pages", ({ data }) => (isDev ? true : !data.draft)) + return postEntries.map((page) => ({ + params: { + slug: page.slug, + }, + props: { + page, + }, + })) +} + +type Props = { + page: CollectionEntry<"pages"> +} +const { page } = Astro.props +--- + + diff --git a/src/styles/katex.css b/src/styles/katex.css new file mode 100644 index 00000000..27d96d8b --- /dev/null +++ b/src/styles/katex.css @@ -0,0 +1,3 @@ +.katex { + font-size: 1.1rem !important; +}