Search code examples
webdirectorymkdocs

mkdocs: How to create Folder like structure


I want to create a small local file with my personal lecture notes. The Structure that I want is

Index 1 (contains overview of subfolders, but not the full content of them) Index 1.1 (contains overview of subfolders but not the full content of them) Index 1.1.1 (contains content of section)

At the moment my mkdocs.yml looks like

site_name: Lectures

theme: readthedocs

extra_javascript: 
    - https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML

markdown_extensions:
    - mdx_math

pages:
- Lecture1 
  - 'week 1': 'lec1/week1.md'
      - 'section 1': 'lec1/week1/sec1.md

But the previous code does not display it like I want.


Solution

  • Your pages config is not valid.

    First, a section must end in a colon (:) to indicate that the indented lines which follow are children of the section.

    - Lecture:
      - 'week 1'...
    

    Second, only a "section" can have children. A "page" cannot have children.

    - 'week 1':
      - Summary: 'lec1/week1.md'
      - 'section 1': 'lec1/week1/sec1.md'
    

    Yes, that means you need to add an extra entry for the week1.md page. I gave it the title Summary. Of course, you could use whatever name you think is more appropriate. In any event, the full config should look like this:

    pages:
      - Lecture:
        - 'week 1':
          - Summary: 'lec1/week1.md'
          - 'section 1': 'lec1/week1/sec1.md'