Skip to content

feat: getEntryを使ったページにする - #239

Draft
ryosanhin wants to merge 1 commit into
feat/md-pagesfrom
feat/routing-get-entry
Draft

ryosanhin wants to merge 1 commit into
feat/md-pagesfrom
feat/routing-get-entry

Conversation

@ryosanhin

Copy link
Copy Markdown

概要

  • 読み込み時にgetCollection ではなくgetEntry を使う用に変更した
  • これに伴い分かれていた目次ファイルと記事ファイルが統合された

関連 Issue

備考

変更内容の詳細

目次と記事の切り替えは以下の通りである。

{
  metaData ? (
    <!--ここに目次用の処理-->
  ) : (
    <!--ここに記事用の処理-->
  )
}

このようにmetaData が存在するか否かで決めている。

metaData はgetEntry("metaData", `${slug}/meta`) で取得されるため、ディレクトリ名と重複する.md ファイルは基本的に避けて欲しい。

データの取得は以下の通りである。

if (metaData) {
  filteredDocs = await getCollection("docs", ({ id }) => id.startsWith(`${slug}/`));
} else {
  article = await getEntry("docs", slug);

  if (article) {
    const rendered = await render(article);
    Content = rendered.Content;
  }
}

このようにmetaData が存在するか否かで決めている。

とにかくディレクトリ名と重複する.md ファイルは基本的に避けて欲しい(挙動がわからない)。

エディタ警告部分

slug がundefined の可能性がある、filteredDocs はany の可能性がある、article はundefined の可能性がある等々色々出ているが後々対応を考えていきたい。

@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ryosanhin ryosanhin changed the title feat: getEntryを使ったページにする(仮) feat: getEntryを使ったページにする Sep 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slug が存在しないときに 404 にならず 500 とかになると思うので、その点を修正してほしいです!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これをやると lint エラーもいくつか消えると思います

const { doc } = Astro.props;
const { Content } = await render(doc);
if (metaData) {
filteredDocs = await getCollection("docs", ({ id }) => id.startsWith(`${slug}/`));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2階層まで許容だと思うんですが、これだとすべて同階層表示となって親子関係がわからなくなってしまうなと思いました

@Yusuke4869 Yusuke4869 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category 名と md ファイル名の重複を避ける1つの手段として
カテゴリー側を src/pages/categories/[...slug].astro に置くというのがある気がします

Comment on lines +13 to +15
let article;
let Content;
let filteredDocs = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

三項演算子を使うなどして let を使わなくできると BEST です

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初期値なしで let を使うと any 型になって型の警告にもなるので注意が必要です!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants