Mkdocs: Using ENV variables in mkdocs.yml

Created on 5 Apr 2017  路  3Comments  路  Source: mkdocs/mkdocs

This is more of a question - is there some way to use ENV variables in mkdocs.yml? The thing is that I want to automatically deploy to gh-pages when the build is successful, but I don't want to expose my Google Analytics tokens. Would be awesome!

Most helpful comment

Digging into PyYAML, I can answer my own question:

google_analytics:
  - !!python/object/apply:os.getenv ["GOOGLE_ANALYTICS_TOKEN"]
  - auto

All 3 comments

Digging into PyYAML, I can answer my own question:

google_analytics:
  - !!python/object/apply:os.getenv ["GOOGLE_ANALYTICS_TOKEN"]
  - auto

@squidfunk , do you know if it is possible to add non strings this way ?

This doesn't work:

plugins:
    - search
    - pdf-export:
        combined: !!python/object/apply:os.getenv ["PDF_EXPORT_COMBINED"]

The build complains that string is not bool value:

PS> $Env:PDF_EXPORT_COMBINED='true'
PS> mkdocs build
...
ERROR - Config value: 'plugins'. Error: Plugin value: 'combined'. 
        Expected type: <class 'bool'> but received: <class 'str'>

I looked into PyYAML section _YAML tags and Python types_[^1] to no avail. I guess form:

!!python/object/apply:module.f | value of聽f(...)

could be used as I need pythons distutils.util.strtobool( os.getenv("PDF_EXPORT_COMBINED") ) but not sure if that is possible using that syntax.

@majkinetor don't know, sorry. I'm not proficient in Python.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

banj picture banj  路  6Comments

rei-vilo picture rei-vilo  路  5Comments

oliviernguyenquoc picture oliviernguyenquoc  路  6Comments

beeva-marcosromero picture beeva-marcosromero  路  4Comments

twardoch picture twardoch  路  3Comments