Creating a Table of Contents for All Content
See original GitHub issueI’m curious how to easily create a Table of Contents for all content files, divided up into sections (directories), pretty much like how it is in the Docs Theme on the left-hand sidebar. I feel like it’s super-easy, but can’t find any examples anywhere.
This is for a project already in production (so can’t use the Nuxt Content Docs module).
On the one hand it looks like its all in the root directory of content
, but then how is it organized?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Word Tips: How to Create a Table of Contents in Word
Now for the easy part! Once you've applied heading styles, you can insert your table of contents in just a few clicks. Navigate...
Read more >Table of Contents in Word - CustomGuide
1. Click in the document where you want to insert a Table of Contents. 2. Click the References tab on the ribbon. 3....
Read more >How to Create a Table of Contents in Word in 7 Easy Steps
4. Click the Table of Contents command. Go to Ribbon > References > Table of Contents. Choose from one of the two automatic...
Read more >How to build a table of contents in Microsoft Word
1. Go to each page of your document and implement a heading style to the title via Home > Styles. You can also...
Read more >The Wicked Easy Way to Create a Table of Contents in Word
Click in your document where you want to create the table of contents. If you'd like it to appear on its own page,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, that’s a great idea about the numbering rules. I will definitely steal that one, and hopefully down the line there can be an easier built-in solution.
Thanks!
@jhull
I’m glad to hear that it worked! 👍
And yeah, I also think it’s somewhat confusing at first that relationship between
position
property and directory structure.In short, as you guess, we are supposed to have position set in sequence from beginning to end.
If I understand it correctly based on my code reading, the situation is like the following:
fs.readdir()
method (recursively) to retrieve all the file names in thecontent
directly.fs.readdir()
doesn’t guarantee the order of file names (reference).fs.readdir()
, it is transformed and pushed to an array (database’s internal behavior).I believe this is why authors provide
position
property. With this property, Nuxt Content can sort files according to information architecture, independently of physical directory structure. Indeed, without such property, we can’t fetch prev/next files and have a control on the order of navigation links.By the way, I also wish there were better way. 🤔 What we want to do is to order pages, and not numbering every single of them, right?
With current approach, the more the website grows, the harder it would likely to become to organize files/pages. FYI, I’m avoiding such situation by defining numbering rules, where I can add pages between others later (e.g. increment position by 5 for pages, by 100 for directories (categories)).