flatironinstitute / ccn-template

Template repository for CCN software projects
https://ccn-template.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
7 stars 2 forks source link

mkdocs-gallery sort tutorials & configs #37

Open BalzaniEdoardo opened 1 year ago

BalzaniEdoardo commented 1 year ago

mkdocs-gallery custom configurations

If one want to configure the mkdocs-gallery behavior, the way to do it is to create a file in docs/ named gallery_conf.py.

A template for the file, which just set the default configs, can be found in the github page of mkdocs-gallery. This script adds a dependency on plotly.

Default configurations can be found in mkdocs_gallery/gen_gallery.py, and are stored in a dictionary named DEFAULT_GALLERY_CONF. The documentation is scarce, but some things are intuitive and others can be reverse engineered by looking at the source code.

Some configs I was interested in include:

If you need custom sorting, this can be easily achieved by creating a callable class that returns the sorting function to be used. The sorting happens in the script mkdocs_gallery/gen_data_model.py, within the GalleryBase.collect_script_files method. The method calls,

listdir = sorted(listdir, key=self.conf["within_subsection_order"]())

Where conf is the dictionary of configuration, listdir is a list of pathlib.Path paths. As long as the argument of key is a funciton that takes a path and returns something that can be sorted, you are good to go.

billbrod commented 1 year ago

This sounds super helpful. plotly is a big dependency (and doesn't seem to do anything), do you know why it gets added? And you're not saying we should include it, right?

For the static scripts, where do the outputs come from? Or does it just show the lines of code and that's it (similar to if we included code in a markdown file)? So there'd be no plots?

BalzaniEdoardo commented 1 year ago

about plotly, I am not sure. I am not sure what happens if I don't specify that configuration, not super clear from the mkdocs-gallery documentation