Access to docs metadata from individual doc pages
under review
Daniel Kuschny
In many occasions some docs authors want to generate dynamic pages based on the metadata of other pages. Imagine that you describe one property/method of your library per file in the /docs/reference/{propname}.mdx
In this MDX you use the metadata to describe some basics of your property (type, default value etc.) From this folder you want to be able to generate an overview table listing all properties of your library. Take https://datatables.net/reference/option/ as a reference on that.
Currently Docusaurus does not provide a way to query all docs pages from the /docs/reference folder and access their metadata for dynamically generating content on a /docs/reference/index.mdx
Sébastien Lorber
under review
This is a hard problem to solve and GiHub issues or Discord #contributors are a better way to discuss this, in case you are still interested ;)
Daniel Kuschny
I started investigating on docusaurus internals and attempted to implement this feature. It is not a major change but it works quite well: https://github.com/Danielku15/docusaurus/tree/feature/docs-with-pageapi
Following changes were added:
- The DocsMetadata items also hold now any custom metadata keys that a user specifies on top of their files.
- A virtual module @docusaurus-meta/docsis provided via webpack allowing doc pages to import the list of available pages usingimport allDocs from '@docusaurus-meta/docs';
Of course this is just the starter for such a potential feature. On top of this "raw data" some more user friendly APIs could be added that allow filtering, sorting, version handling. Then this data can be used in components to generate tables, sidebars or whatever needed.
I decided to first open here a discussion than directly opening an issue or PR which might be closed in this early draft stage.
The whole feature idea is inspired from many other static page generators that offer comparable features on dynamic content generation.