-
-
Notifications
You must be signed in to change notification settings - Fork 361
docs/lib: generalise using the module system #3706
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
docs/lib: generalise using the module system #3706
Conversation
Modules to represent pages in the docs
Move the mdbook menu rendering code into the module system and generalise it to apply to multiple "categories" (mdbook parts) and "types" of category (prefix, suffix, etc).
8fa5731 to
c99d6f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so this means that we can "easily" add documentation "anywhere" in the module system, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I tried to come up with a structured way of representing a mdbook menu tree.
There are other possible approaches. E.g. we could have a flat structure with each element having a "loc" attribute.
|
This seems indeed much simpler to understand! It was pretty clear to me, and it’s been some time since I was really involved, thanks a lot! |
|
Thanks @traxys for your review! I would've liked more reviews and/or feedback from @GaetanLepage and @khaneliman, but I'm going to merge this later today to avoid it getting stale. |
|
Sorry, just deadline swamped at work so have no energy for in depth reviews atm. I trust your work, though. |
This PR introduces a new way of managing docs pages, inspired by work in #2884.
The end goal is to entirely replace
docs/mdbook/default.nixwith an overall simpler* implementation that creates fewer derivations and uses more upstream tooling, such aslib.options.optionAttrSetToDocList.* or at least, more understandable, modular, maintainable
The naive implementation may simple wish to directly apply
lib.options.optionAttrSetToDocListto the fulloptionsset, and then group that list into "pages" of options. This approach seems simple at first, however it quickly gets complex when you want to turn that set of pages into a mdbook summary menu.This PR takes an opposite approach. We start by defining the menu, and then decide later what goes on each page.
To minimise the scope of this PR, it does not aim to replace all docs pages yet. Instead, it only replaces the "lib docs" implementation for now.
That said, it does include scope for rendering options in its module scheme. There's no option-doc-rendering code yet, but I have laid out things like
_page.optionswhere we would list which options to include on that particular page.Another thing that is out-of-scope for now is including these docs-creating modules within the main nixvim module set. This will be possible, but isn't done here as a) it isn't fully finished and b) I want to minimise scope creep.
When this is done, we will be able to use the
extendModulesmodule arg to re-evaluate the outer nixvim configuration with differentspecialArgs(etc). This is useful for ensuring we don't accidentally rely on things likepkgsorconfigin our documented defaults/examples/etc.High level overview
In
docs/modules/menu.nix, a MDBook menu is represented as a freeform attrset of "category" submodules. Alongside these "categories" is a special_menuoption set, where explicit options can live. This "menu" represents the entireSUMMARY.mdfile.In
docs/modules/category.nix, each "category" is itself an attrset of "page" submodules. Alongside these pages is a_categoryoptions set, where category metadata is defined. A category represents what MDBook calls a "part".In
docs/modules/page.nixanddocs/modules/page-options.nix, each "page" is itself represented as an attrset of sub-pages. This is a recursive tree structure. Each page node also has a_pageoption set, where page metadata can be defined.When rendering the menu, we start in
menu.nixby sorting and ordering the categories, then simply concatenating each category's menu. Incategory.nix, we render the categories menu by concatenating each page's menu. Inpage-options.nix, we render a page's menu by printing the markdown for the specific page node and concatenating all sub-page's menus recursively.There's a little complexity when rendering menus:
showInMenubooleanlocpath and removing the parent (prefix) path.-list syntax and can't render as nested.nestedbooleanSee https://rust-lang.github.io/mdBook/format/summary.html