Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: automatically generate SUMMARY.md from the list of src/*.md files #1016

Open
wusunlab opened this issue Aug 22, 2019 · 8 comments
Labels
A-Summary Area: The summary page, organization of pages.

Comments

@wusunlab
Copy link

wusunlab commented Aug 22, 2019

It would be nice if there is an option to generate SUMMARY.md automatically from the list of markdown files under src (except SUMMARY.md itself). The generated SUMMARY.md would map the directory structure. For example, if I have chapters and sections organized in subfolders,

.
├── book.toml
└── src
    ├── SUMMARY.md
    ├── chapter_1
    │   ├── section_1_1.md
    │   ├── section_1_2.md
    │   └── section_1_3.md
    ├── chapter_1.md
    ├── chapter_2
    │    └── section_2_1.md
    └── chapter_2.md

the generated SUMMARY.md could be look like

# SUMMARY

- [Chapter 1 title parsed from markdown file](./chapter_1.md)
    - [Section 1.1 title](./chapter_1/section_1_1.md)
    - [Section 1.2 title](./chapter_1/section_1_2.md)
    - [Section 1.3 title](./chapter_1/section_1_3.md)
- [Chapter 2 title](./chapter_2.md)
    - [Section 2.1 title](./chapter_2/section_2_1.md)

The advantage of this feature would be to save the effort of manually checking if every chapter/section is included in SUMMARY.md.

@mrec
Copy link

mrec commented Aug 30, 2019

Are you proposing that titles are generated from the slugged filenames? That feels a bit limiting.

A possible alternative might be to take the ordering from filenames, but titles from the top-level headings in each file.

@wusunlab
Copy link
Author

Hi, sorry if it wasn't clear. I was suggesting that the chapter or section title could be parsed from the top-level heading of each markdown file. I was able to prototype this in a crude way in Python. So I think this could be doable in Rust as well, though I'm not familiar with markdown parsing.

@segfaultsourcery
Copy link
Contributor

Hi, I've been wanting this as well, but I've had trouble figuring out what the title should be for the folders. By title I mean the text used for the links in the summary.

I tried getting around the problem by assuming there's a file in each folder called landing.md. It's in the same spirit of index.html, and it'll be the first file linked to in any folder. The first line in this file determines the name of the folder. For all other .md files, the first line is always used as the title.

This is a PoC combining my concerns with what I understood yours to be. Can you try it out and give your input?

https://github.com/segfaultsourcery/auto-generate-summary

@PsiACE
Copy link

PsiACE commented Nov 25, 2019

I like this feature, which provides a pretty good basis for migration.

@segfaultsourcery
Copy link
Contributor

@PsiACE Since OP seems to have disappeared, could you have a look at my PoC (above your comment) and tell me what you think?

@PsiACE
Copy link

PsiACE commented Nov 25, 2019

@PsiACE Since OP seems to have disappeared, could you have a look at my PoC (above your comment) and tell me what you think?

I'll try it later. Thank you so much for your work.

@troyerta
Copy link

troyerta commented Apr 11, 2020

I have a python script that does this very thing. But you need to adopt my file naming convention to test it out immediately. Then you would need to change the convention to whatever you need. Right now, it just generates the title from the filename.

So garlic-cheese-foccia-bread.md gets printed to the summary with the title "Garlic Cheese Foccia Bread". Nice and simple.

I use it maintain a large cooking recipe book (~300 pages) - so I can drop files into the right chapter directory, and then deploy to gh-pages with a dumb makefile that runs the summary generator as part of the deploy sequence - so just look in my recipes repo to find it. It's terrible recursive python code, so if it needs a refactor to rust, then I understand why - but I don't know rust. ;)

@blaggacao
Copy link

I just stumbled on this one: https://github.com/dvogt23/book-summary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Summary Area: The summary page, organization of pages.
Projects
None yet
Development

No branches or pull requests

7 participants