Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Support content "sections"

オープン
#209 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
content

調査の方向性

まず、issue に示されているエントリポイント makeSource と defineDocumentType を確認し、次にドキュメントパスと計算フィールドが allDocsSections のようなコレクションになるまでの流れを追ってください。要求されているネストされたセクションとセクションごとのメタデータを、Hugo と Docusaurus の例と比較してください。提案された API と再帰的な型付き構造が実装され、適切なテストで検証されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

feature

One of the things that I really like about Hugo is its sections feature, which enables you to separate nested directories of content into well-defined groups. So instead of a kind of "flat" array of files you end up getting a nested structure like this:

Documentation
\_ Getting started
  \_ Installation
  \_ Platforms
\_ Administration
  \_ Kubernetes
    \_ Setup
    \_ Configuration
\_ etc

As expected, sections can be infinitely nested and each can have its own metadata. I don't necessarily endorse the way that Hugo does this (you need to sprinkle _index.md files throughout your tree) but I do think that having this kind of rich structure available to you is great for creating tables of content, sidebar navs, and all of that good stuff. Personally, it's the thing that I'm missing the most as I cross the chasm from mostly doing things in Hugo to doing things in JS world.

I could envision being able to do something like this in Contentlayer:

export const Doc = defineDocumentType(() => ({
  name: 'Doc',
  filePathPattern: `**/*.md`,
  fields: {
    title: {
      type: 'string',
      description: 'The title of the doc',
      required: true,
    },
  },
  computedFields: {
    url: {
      type: 'string',
      resolve: (post) => `/docs/${post._raw.flattenedPath}`,
    },
  },
}))

export default makeSource({
  contentDirPath: 'docs',
  documentTypes: [Doc],
  // tiny little change
  sections: true,
})

This could export an allDocsSections object of type Sections<Doc> that would enable you to recurse through the tree.

<ul>
  {allDocs.sections.map(section => (
  <li>
    <p>{section.title}</p>
    
    <ul>
      {section.docs.map(doc => (
        <li>
          {doc.title}
        </li>
      ))}
      
      {section.sections.map(section => ( /* nest */ ))}
    </ul>
  </li>)}
</ul>

This is very off the cuff but hopefully provides some sense of what I'm suggesting. I'd be quite happy to help out with this if others find the idea compelling. Just wanted to register it here in this forum.

Note: Docusaurus also supports this using a _category_.{json|yml} file that creates a new "category" (basically an analogue to the sections concept) wherever it's found in the directory tree.

主要言語
TypeScript
スター
3.5k
フォーク
192
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

contentlayerdev/contentlayer のほかの issue

contentlayerdev/contentlayer の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。