Skip to content

Settle on one canonical TOC Tree implementation #40

@Mpdreamz

Description

@Mpdreamz

Relates: #32

The {toctree} directive is not a Myst native directive it comes from Sphinx.

Currently this repository includes the sample documentation from https://github.com/elastic/markitpy-samples/tree/main/docs/source which were heavily geared to Sphinx.

Pending discussion #38 we'll most likely don't want to support {toctree} but instead use the Myst native way through myst.yml

See: https://mystmd.org/guide/table-of-contents

This has several advantages:

  • Building the navigation does not require us parsing the whole file for a{toctree}
    • We don't have to enforce a {toctree} is always provided at the beginning/end of an index.md
  • myst.yml allows grouping of related files in the same folder through children without them needing to be in a folder

Disadvantages

Proposal

Since myst.toc is very much geared towards smaller documentation sites or single Jupiter notebook html export I propose we follow its TOC in spirt:

  • Allow a single toc definition control any nested children
  • Allow nested toc definitions to isolate if needed
  • Not a one way door, we can still include folder's without having to explicitly specify all its children
  • Subfolders can define their own toc configuration
    • Unless a parent folder's toc defines its content explicitly this will result in a build error.

Example configuration

exclude:
  - notes.md
  - '**/ignore.md'
toc: 
  - file: index.md
  - file: config.md
  - file: search.md
     children:
       - file: search-part2.md
       - folder: search  
  - folder: my-folder1
    exclude:
       - '_*.md'
  - folder: my-folder2
    children: 
       - file: subpath/file.md
       - file: file.md
       - pattern: *.md
       - folder: sub/folder

Going over the bits in isolation:

exclude:
  - notes.md
  - '**/ignore.md'

Globally ignores any files matching the configured glob patterns.

toc: 
  - file: index.md
  - file: config.md

Ordered list so index.md and config.md appear first.

  - file: search.md
     children:
       - file: search-part2.md
       - folder: search  

Creates a collapsable section in the navigation with search.md being the root and search-part2.md and the contents of the search folder as its children.

  - folder: my-folder1
    exclude:
       - '_*.md'

Auto include my-folder1 if that folder contains a toc it will use that otherwise use the default rules for folder inclusion.

  - folder: my-folder2
    children: 
       - file: subpath/file.md
       - file: file.md
       - pattern: *.md
       - folder: sub/folder

An inline toc declaration for my-folder2. If that my-folder2 holds its own toc file too it will result in a build error.

The inline declaration automatically prefixes my-folder2 to children so that it can be renamed with ease.

future expansions ideas

We can expand this later with more options e.g:

  - folder: new-feature
     aliases: ['featureA', 'featureB']

To emit the folder as new-feature/* and featureA/* and featureB/*` as a means to safely rename a folder while links and rewrite rules get updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions