diff --git a/src/components/Index.astro b/src/components/Index.astro index 66c34d7..dba8204 100644 --- a/src/components/Index.astro +++ b/src/components/Index.astro @@ -1,16 +1,3 @@ --- import { sections } from "../constants/sections.ts"; --- - -{sections.map((section) => ( - <> -
{section.title} - {section.description &&

{section.description}

} - -))} - - - - - - diff --git a/src/components/Toc.astro b/src/components/Toc.astro index 6f1faf2..40c3279 100644 --- a/src/components/Toc.astro +++ b/src/components/Toc.astro @@ -3,122 +3,30 @@ const currentPath = Astro.url.pathname; --- -
- -
+ {sections.map(section => { + const isActive = section.items.some(item => currentPath.startsWith(item.url)); - diff --git a/src/constants/sections.ts b/src/constants/sections.ts index 8249c9d..06183b3 100644 --- a/src/constants/sections.ts +++ b/src/constants/sections.ts @@ -1,16 +1,16 @@ import type { MDXInstance } from "astro"; export type PageItem = { - url: string; - file: string; - title: string; + url: string; + file: string; + title: string; }; export type Section = { - title: string; - key: string; - items: PageItem[]; - description?: string; + title: string; + key: string; + items: PageItem[]; + description?: string; }; // "html", @@ -24,88 +24,91 @@ // "final-work", const sections: Section[] = [ - { - key: "html", - title: "HTML", - items: [], - description: "", - }, - { - key: "js", - title: "JavaScript", - items: [], - description: "自分のページに振る舞い方を教えよう。", - }, - { - key: "cli", - title: "コマンドライン", - items: [], - description: "文字だけの世界で、パソコンと会話しよう。", - }, - { - key: "php", - title: "PHP", - items: [], - description: "", - }, - { - key: "sql", - title: "SQL", - items: [], - description: "", - }, - { - key: "git", - title: "Git", - items: [], - description: "", - }, - { - key: "tips", - title: "Tips", - items: [], - }, - { - key: "reference", - title: "参考資料", - items: [], - }, - { - key: "final-work", - title: "最終課題", - items: [], - }, + { + key: "html", + title: "HTML", + items: [], + description: "", + }, + { + key: "js", + title: "JavaScript", + items: [], + description: "自分のページに振る舞い方を教えよう。", + }, + { + key: "cli", + title: "コマンドライン", + items: [], + description: "文字だけの世界で、パソコンと会話しよう。", + }, + { + key: "php", + title: "PHP", + items: [], + description: "", + }, + { + key: "sql", + title: "SQL", + items: [], + description: "", + }, + { + key: "git", + title: "Git", + items: [], + description: "", + }, + { + key: "tips", + title: "Tips", + items: [], + }, + { + key: "reference", + title: "参考資料", + items: [], + }, + { + key: "final-work", + title: "最終課題", + items: [], + }, ]; type Article = { - title?: string; + title?: string; }; async function getSectionPages(sectionPath: string): Promise { - const allPages = import.meta.glob>(`../pages/**/*.mdx`); - const filteredPages = Object.entries(allPages).filter(([path, _]) => - path.includes(`/pages/${sectionPath}/`), - ); + const allPages = import.meta.glob>(`../pages/**/*.mdx`); + const filteredPages = Object.entries(allPages).filter(([path, _]) => + path.includes(`/pages/${sectionPath}/`), + ); - const files = await Promise.all( - filteredPages.map(async ([filePath, resolver]) => { - const module = await resolver(); - const page: PageItem = { - file: filePath, - title: module.frontmatter?.title || "", - url: module.url || "", - }; + const files = await Promise.all( + filteredPages.map(async ([filePath, resolver]) => { + const module = await resolver(); - return page; - }), - ); + console.log(module.title); - return files; + const page: PageItem = { + file: filePath, + title: module.title || "", + url: module.url || "", + }; + + return page; + }), + ); + + return files; } sections.forEach(async (section) => { - const pages = await getSectionPages(section.key); - section.items = pages.sort((a, b) => a.title.localeCompare(b.title)); + const pages = await getSectionPages(section.key); + section.items = pages.sort((a, b) => a.title.localeCompare(b.title)); }); export { sections };