Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Support content "sections"

Abierto
#209 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript
Área
content

Línea de trabajo

Empieza revisando los puntos de entrada makeSource y defineDocumentType mostrados en el issue; después, sigue cómo las rutas de los documentos y los campos calculados se convierten en colecciones como allDocsSections. Compara las secciones anidadas solicitadas y los metadatos por sección con los ejemplos de Hugo y Docusaurus. Se considera terminado cuando la API propuesta y la estructura tipada recursiva estén implementadas y verificadas mediante las pruebas adecuadas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
3.5k
Forks
192
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de contentlayerdev/contentlayer

Todos los issues de contentlayerdev/contentlayer

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.