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

✨ feat(settings): add hierarchy-based setting overrides #128

Merged
merged 2 commits into from
Sep 1, 2023

Conversation

welpo
Copy link
Owner

@welpo welpo commented Sep 1, 2023

TL;DR Adds hierarchical setting overrides with priority: page > section > config.toml.

Description

This PR introduces a new feature that allows for hierarchical overriding of most settings (see list below). The priority of the settings is evaluated as page > section > config.toml.

Related issue: #124

Changes

  • Adds a new macro (evaluate_setting_priority, in settings.html) to handle hierarchical setting logic.
  • Updates config.toml and theme.toml to document the new hierarchy logic for each pertinent setting.
  • Moved the loading logic for katex, copy_button, and footnote_backlinks from base.html to content.html.

Priority Table

Here is how the priority is evaluated:

page section config.toml outcome
Any Any
Any Any
Any
Any
default

Legend:

  • ✅: true
  • ❌: false
  • ⬛: unset

Default Settings

The default value of the settings which follow this hierarchy is as follows:

setting default
show_reading_time true
footnote_backlinks false
katex false
quick_navigation_buttons false
copy_button true
show_remote_changes true

Example

If you'd like to only show the reading time on posts within your blog section, you could set config.toml like:

[extra]
show_reading_time = false

And in your _index.md (in content/blog):

paginate_by = 5
path = "/blog"
title = "Blog"
sort_by = "date"
template = "section.html"
insert_anchor_links = "left"

[extra]
show_reading_time = true

Note: the macro only checks the parent section, not all ancestors.


Additionally, I added some debugging code on top of content.html (commented out) to assist in troublehsooting. It creates a table on top of the articles like this:

debugging


Tasks

  • Review the code
  • Ensure the pages look the same as the main branch
  • Update markdown.md and javascript.md files to mention the hierarchy where relevant.

@welpo welpo added the enhancement New feature or request label Sep 1, 2023
@welpo welpo marked this pull request as ready for review September 1, 2023 11:53
@welpo welpo merged commit f61c9ec into main Sep 1, 2023
1 check passed
@welpo welpo deleted the feat/settings-hierarchy branch September 1, 2023 12:03
welpo added a commit that referenced this pull request Sep 1, 2023
welpo added a commit that referenced this pull request Sep 3, 2023
Can be set at the post, section and `config.toml`.
It respects the hierarchy post > section > config. See #128
welpo added a commit that referenced this pull request Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant