mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00

* feat: use github actions to deploy docs fixes #4473 * fix: install xonsh * fix: doc action * chore: support *.md for documentation * fix: remove hardcoded docs link it affects local testing * refactor: move sphinx extensions to its own package * fix: remove deprecated get_theme_dir As of Sphinx 1.2, this is passed to Sphinx via a ``setup.py`` entry point, and no longer needs to be included in your documentation's ``conf.py``. * feat: jinja2 render without affecting incremental build * style: * feat: auto generate API doc no need to create a file for each module * chore: watch top-level and nested files * refactor: update lib api-docs as well * fix: import errors when doc generated for some modules * fix: relative path * feat: add release handling * Update .github/workflows/docs.yml Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com> * refactor: use github-app-token * chore: deploy docs only when merged Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""A sphinx extension to process jinja/rst template
|
|
|
|
Usage:
|
|
define the context variable needed by the document inside
|
|
``jinja_contexts`` variable in ``conf.py``
|
|
"""
|
|
|
|
# https://www.ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/
|
|
|
|
from pathlib import Path
|
|
|
|
import jinja2
|
|
|
|
from . import rst_helpers, utils
|
|
|
|
|
|
def rstjinja(app, docname, source):
|
|
"""
|
|
Render our pages as a jinja template for fancy templating goodness.
|
|
"""
|
|
# Make sure we're outputting HTML
|
|
if app.builder.format != "html":
|
|
return
|
|
|
|
print(docname)
|
|
page_ctx = app.config.jinja_contexts.get(docname)
|
|
if page_ctx is not None:
|
|
ctx = {
|
|
"rst": rst_helpers,
|
|
}
|
|
ctx.update(page_ctx)
|
|
environment = jinja2.Environment(
|
|
trim_blocks=True,
|
|
lstrip_blocks=True,
|
|
)
|
|
|
|
src = source[0]
|
|
rendered = environment.from_string(src).render(**ctx)
|
|
# rendered = app.builder.templates.render_string(src, ctx)
|
|
source[0] = rendered
|
|
|
|
# for debugging purpose write output
|
|
Path(utils.docs_dir / "_build" / f"{docname}.rst.out").write_text(rendered)
|
|
|
|
|
|
def setup(app):
|
|
app.connect("source-read", rstjinja)
|
|
|
|
# rst files can define the context with their names to be pre-processed with jinja
|
|
app.add_config_value(
|
|
"jinja_contexts",
|
|
{},
|
|
rebuild="", # no need for rebuild. only the source changes
|
|
# rebuild="env", # no need for rebuild. only the source changes
|
|
)
|