Skip to content

Add enabled on serve config option #182

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

Closed

Conversation

bittorala
Copy link

Provide an option like that in mkdocs-git-authors-plugin, with which the plugin can be disabled when running with mkdocs serve, for faster build times and hot reloading when running locally (especially with big projects). This can be more convenient than setting env vars.

Bittor Alaña added 2 commits May 2, 2025 10:49
For big projects where handling the git log of all source files can
significantly affect hot reload time, provide an option similar to that
in mkdocs-git-authors-plugin, by which the plugin can be disabled when
running with `mkdocs serve`.
@timvink
Copy link
Owner

timvink commented May 6, 2025

It's not an option I would like to add to all my plugins. In fact, the enabled option should be removed entirely as this is now implemented in mkdocs itself for all plugins (https://www.mkdocs.org/user-guide/configuration/#enabled-option).

Would using an environment variable (https://www.mkdocs.org/user-guide/configuration/#environment-variables) and the !ENV pattern work for you as well? You do something like this: enable_rev_date=0 && mkdocs serve when you have this in your mkdocs.yml:

plugins:
  - search
  - git-revision-date-localized:
    enabled: !ENV [enable_rev_date, true]

@bittorala
Copy link
Author

Hi! I have a Docker container that my colleagues and I use both for locally serving the sites and for building the assets for the deployments of our docs. We basically want to have the author and dates info in the deployed docs, to provide the full picture, and to hide it in local development, to avoid slowing down the hot reload.

The problem (or rather an inconvenience) is that my colleagues will have to bear in mind that they pass an env var to the container when running locally (if plugin is enabled by default), or else we will have to change all the build pipelines to have them set that env var (if plugin is disabled by default).

Again, this is not a big problem at all, but the flag in your other plugin matched our use case perfectly so it seemed sensible to have it here too.

I see how this is an edge case and it's always preferable to use core functionality over adding extra config variables. So feel free to close the PR if you're not convinced.

@timvink
Copy link
Owner

timvink commented May 8, 2025

Is it an option to change the docker file? E.g. something like this:

# Set environment variable
ENV MY_VAR=some_value

or

RUN MY_VAR=some_value mkdocs build

Another option is 'detecting' the build environment. Many build environments set a specific environment variable, see for example this module:

elif os.getenv("GITHUB_ACTIONS") is not None and n_commits == 1:

So you could use:

plugins:
  - search
  - git-revision-date-localized:
    enabled: !ENV [GITHUB_ACTIONS, false]

So I'm not convinced, and I think you can work out a solution that is both easy for colleagues and works on CI. With my current understanding of the !ENV syntax and the now natively supported enabled parameter from mkdocs, I would not add enabled or enabled_on_serve parameters to any plugins.

Thanks for the work you put in though, still much appreciated!

@timvink timvink closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants