-
Notifications
You must be signed in to change notification settings - Fork 39
様々な箇所でAstroのContent Collectionsを使う #1777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
917d9cb
fb7b221
805b228
2a23206
e0cf9de
a93f6e2
14bdd34
0a19fab
0f383e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| --- | ||
| import assert from "assert"; | ||
| import type { MDXInstance } from "astro"; | ||
| import type { Frontmatter } from "@layouts/Layout.astro"; | ||
| import { getCollection } from "astro:content"; | ||
| import If from "@components/utils/If.astro"; | ||
| import type { Lang } from "@components/types"; | ||
| import { getLocaleDateString } from "@data/utils/notices"; | ||
| import { getLocaleDateString } from "src/lib/util"; | ||
|
|
||
| interface EventInformation { | ||
| key: string; | ||
|
|
@@ -21,36 +19,31 @@ interface Props { | |
|
|
||
| const { show, lang, alternative } = Astro.props; | ||
|
|
||
| const allEventsList: Map<string, EventInformation> = new Map( | ||
| [ | ||
| await Astro.glob<MDXInstance<Frontmatter>>( | ||
| "/src/pages/events/*/index.{md,mdx}" | ||
| ), | ||
| await Astro.glob<MDXInstance<Frontmatter>>("/src/pages/events/*.{md,mdx}"), | ||
| ] | ||
| .flat() | ||
| .map((instance) => { | ||
| const dateMatch = instance.file.match( | ||
| /\/(([0-9]{4}-[0-9]{2}-[0-9]{2})?[^/]*)(?:\/index)?\.mdx?$/ | ||
| ); | ||
| assert(dateMatch !== null); | ||
| assert(instance.url !== undefined); | ||
| const events = await getCollection("events") | ||
|
|
||
| return [ | ||
| dateMatch[1], | ||
| { | ||
| key: dateMatch[1], | ||
| date: dateMatch[2] ? new Date(dateMatch[2]) : null, | ||
| title: | ||
| instance.frontmatter.title?.replace( | ||
| /^[0-9]{4}([/-])[0-9]{1,2}\1[0-9]{1,2}\s*/, | ||
| "" | ||
| ) ?? "", | ||
| href: instance.url, | ||
| }, | ||
| ]; | ||
| }) | ||
| ); | ||
| const allEventsList: Map<string, EventInformation> = new Map( | ||
| events.map((event) => { | ||
| const dateMatch = event.filePath?.match( | ||
| /(([0-9]{4}-[0-9]{2}-[0-9]{2})?[^/]*)(?:\/index)?\.mdx?$/ | ||
| ); | ||
| if (!dateMatch) { | ||
| throw new Error(`Invalid file path: ${event.filePath}`); | ||
| } | ||
| return [ | ||
| dateMatch[1], | ||
| { | ||
| key: dateMatch[1], | ||
| date: dateMatch[2] ? new Date(dateMatch[2]) : null, | ||
| title: | ||
| event.data.title?.replace( | ||
| /^[0-9]{4}([/-])[0-9]{1,2}\1[0-9]{1,2}\s*/, | ||
| "" | ||
| ) ?? "", | ||
| href: `/${event.id}`, | ||
| }, | ||
| ]; | ||
| }) | ||
| ) | ||
|
||
|
|
||
| const eventsList: EventInformation[] = show.map((key) => { | ||
| const eventInfo = allEventsList.get(key); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,24 +1,23 @@ | ||||||
| import { useReducer } from "react"; | ||||||
| import type { Format, Number, Tool, Keyword } from "src/content.config"; | ||||||
|
|
||||||
| interface Filter { | ||||||
| label: string; | ||||||
| value: Lowercase<string>; | ||||||
| } | ||||||
|
|
||||||
| const FORMATS = [ | ||||||
| export const FORMATS = [ | ||||||
| { label: "リアルタイムオンライン", value: "realtime_online" }, | ||||||
| { label: "オンデマンド", value: "ondemand" }, | ||||||
| ] satisfies Filter[]; | ||||||
| type Format = (typeof FORMATS)[number]["value"]; | ||||||
|
|
||||||
| const NUMBERS = [ | ||||||
| export const NUMBERS = [ | ||||||
| { label: "101名以上", value: "mt100" }, | ||||||
| { label: "30名以上100名未満", value: "mt30-lt100" }, | ||||||
| { label: "30名未満", value: "lt30" }, | ||||||
| ] satisfies Filter[]; | ||||||
| type Number = (typeof NUMBERS)[number]["value"]; | ||||||
|
|
||||||
| const TOOLS = [ | ||||||
| export const TOOLS = [ | ||||||
| { label: "ITC-LMS", value: "itc-lms" }, | ||||||
| { label: "Google Classroom", value: "google-classroom" }, | ||||||
| { label: "Slack", value: "slack" }, | ||||||
|
|
@@ -45,16 +44,22 @@ const TOOLS = [ | |||||
| { label: "GoodNotes", value: "goodnotes" }, | ||||||
| "br", | ||||||
| { label: "Comment Screen", value: "comment-screen" }, | ||||||
| { label: "TeX", value: "tex" }, | ||||||
| { label: "Mathematica", value: "mathematica" }, | ||||||
| { label: "UTAS", value: "utas" }, | ||||||
| { label: "Google Drive", value: "google-drive" }, | ||||||
| { label: "Scrapbox", value: "scrapbox" }, | ||||||
| { label: "Mixlr", value: "mixlr" }, | ||||||
| { label: "TwitCasting", value: "twitcasting" }, | ||||||
| ] satisfies (Filter | "br")[]; | ||||||
| type Tool = Extract<(typeof TOOLS)[number], Filter>["value"]; | ||||||
|
|
||||||
| const KEYWORDS = [ | ||||||
| export const KEYWORDS = [ | ||||||
| { label: "板書", value: "hand-writing" }, | ||||||
| { label: "実験・実習", value: "experiment" }, | ||||||
| { label: "グループワーク", value: "group-work" }, | ||||||
| { label: "TA", value: "ta" }, | ||||||
| { label: "テキスト", value: "text"} | ||||||
|
||||||
| { label: "テキスト", value: "text"} | |
| { label: "テキスト", value: "text" } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,9 @@ | ||||||
| --- | ||||||
| import en from "@data/nav/en.yml"; | ||||||
| import ja from "@data/nav/ja.yml"; | ||||||
| import { basename } from "path"; | ||||||
| import type { MDXInstance, MarkdownInstance } from "astro"; | ||||||
| import { getCollection, getEntry } from "astro:content"; | ||||||
| import Slugger from "github-slugger"; | ||||||
| import Layout, { type Frontmatter } from "@layouts/Layout.astro"; | ||||||
| import Layout from "@layouts/Layout.astro"; | ||||||
| import type { Lang } from "@components/types"; | ||||||
| import type { Navigation } from "@data/schemas/nav"; | ||||||
| import Markdown from "@components/utils/Markdown.astro"; | ||||||
| import { unified } from "unified"; | ||||||
| import remarkParse from "remark-parse"; | ||||||
|
|
@@ -18,7 +15,7 @@ interface Props { | |||||
| } | ||||||
|
|
||||||
| const { lang } = Astro.props; | ||||||
| const navigations: Navigation[] = { ja, en }[lang]; | ||||||
| const { data: navigations } = await getEntry("nav", lang)! | ||||||
|
||||||
| const { data: navigations } = await getEntry("nav", lang)! | |
| const { data: navigations } = await getEntry("nav", lang)!; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,14 +1,16 @@ | ||||||
| import { getEntry } from "astro:content"; | ||||||
| import type { RSSFeedItem } from "@astrojs/rss"; | ||||||
| import getRssResponse from "@astrojs/rss"; | ||||||
| import remarkParse from "remark-parse"; | ||||||
| import { unified } from "unified"; | ||||||
|
|
||||||
| import { noticesWithIdReversed } from "@data/utils/notices"; | ||||||
| import { toHast } from "mdast-util-to-hast"; | ||||||
| import { toText } from "hast-util-to-text"; | ||||||
| import { select } from "hast-util-select"; | ||||||
| import type { Lang } from "@components/types"; | ||||||
|
|
||||||
| const { data: noticesWithId } = await getEntry("notices", "notice")! | ||||||
|
||||||
| const { data: noticesWithId } = await getEntry("notices", "notice")! | |
| const { data: noticesWithId } = await getEntry("notices", "notice")!; |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,144 @@ | ||||||||||||
| import { styleText } from "node:util"; | ||||||||||||
| import { defineCollection } from "astro:content"; | ||||||||||||
| import { z } from "astro/zod" | ||||||||||||
|
||||||||||||
| import { z } from "astro/zod" | |
| import { z } from "astro/zod"; |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after the opening brace in the object literal. This is inconsistent with formatting used elsewhere in the file and across the codebase.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
| }) | |
| } ) |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createEnumFromFilters function doesn't handle the case where the input array is empty. If an empty array is passed, accessing values[0] will be undefined, causing a runtime error. Consider adding validation to ensure the array has at least one element.
| const values = filters.map((f) => f.value); | |
| const values = filters.map((f) => f.value); | |
| if (values.length === 0) { | |
| throw new Error("createEnumFromFilters requires at least one filter value."); | |
| } |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after closing brace in the object literal. This is inconsistent with the formatting used elsewhere in the file.
| }) | |
| } ) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon at the end of the statement. This is inconsistent with the coding style used in the rest of the file.