Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/pages/categories/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
// ------------------------------------
// 目次用のファイル
// ------------------------------------
import { getCollection, getEntry } from "astro:content";

import Layout from "../../layouts/Layout.astro";

const { slug } = Astro.params;

const metaData = await getEntry("metaData", `${slug}/meta`);

if (!metaData) {
return new Response(null, { status: 404 });
}

const docs = await getCollection("docs", ({ id }) => id.startsWith(`${slug}/`));
---

<Layout class="container m-auto px-6 md:w-[80%]" title={metaData.data.categoryName}>
<h1>{metaData.data.categoryName} ドキュメント一覧</h1>
<ul>
{
docs.map((doc) => {
return (
<li>
<a href={`/docs/${doc.id}`}>
{doc.data.title}
{doc.data.description && <p>{doc.data.description}</p>}
</a>
</li>
);
})
}
</ul>
</Layout>
27 changes: 11 additions & 16 deletions src/pages/docs/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
// ------------------------------------
// ドキュメント本体を表示する用のファイル
// ------------------------------------
import { getCollection, render } from "astro:content";
import { getEntry, render } from "astro:content";

import Layout from "../../layouts/Layout.astro";

export async function getStaticPaths() {
const docs = await getCollection("docs");
const { slug } = Astro.params;

return docs.map((doc) => {
return {
params: { slug: doc.id },
props: { doc },
};
});
}
const article = slug && (await getEntry("docs", slug));

const { doc } = Astro.props;
const { Content } = await render(doc);
if (!article) {
return new Response(null, { status: 404 });
}

export const prerender = true;
const { Content } = await render(article);
---

<Layout class="container m-auto px-6 md:w-[80%]" title={doc.data.title}>
<h1>{doc.data.title}</h1>
{doc.data.description && <p>{doc.data.description}</p>}
<Layout class="container m-auto px-6 md:w-[80%]" title={article.data.title}>
<h1>{article.data.title}</h1>
{article.data.description && <p>{article.data.description}</p>}
<!-- eslint-disable-next-line -->
<article headingoffset="1" class="prose max-w-none">
<Content />
</article>
Expand Down
45 changes: 0 additions & 45 deletions src/pages/docs/[slug].astro

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/docs/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ metaDatas.map((metaData) => {
entries.map((entry) => {
return (
<li>
<a href={`/docs/${entry.path}`}>{entry.categoryName}</a>
<a href={`/categories/${entry.path}`}>{entry.categoryName}</a>
</li>
);
})
Expand Down
Loading