diff --git a/components.py b/components.py new file mode 100644 index 000000000..07f2dc2e6 --- /dev/null +++ b/components.py @@ -0,0 +1,33 @@ +import os +import json + + + +def setup(app): + """Setup connects events to the components output builder""" + app.connect("html-page-context", add_component_details) + app.connect("build-finished", create_output) + app.compoents_output = {} + + is_production = os.getenv("NETLIFY") == "true" + + return { + "version": "1.0.0", + "parallel_read_safe": True, + "parallel_write_safe": not is_production, + } + + +def add_component_details(app, pagename, templatename, context, doctree): + """As each page is built, collect page details for the output.""" + if pagename.startswith("components/"): + app.compoents_output[pagename] = { + "title": context["title"], + "url": context["pageurl"] + } + + +def create_output(app, exception): + """Generates the components.json from the collected component pages""" + with open(os.path.join(app.builder.outdir, "components.json"), "wt") as f: + f.write(json.dumps(app.compoents_output)) diff --git a/conf.py b/conf.py index f459985ab..716290824 100644 --- a/conf.py +++ b/conf.py @@ -39,7 +39,8 @@ sys.path.append(os.path.abspath(".")) extensions = [ "github", "seo", - "sitemap", + "components", + "sitemap" ] # Add any paths that contain templates here, relative to this directory. diff --git a/schema_doc.py b/schema_doc.py index 7bd78c886..c69f451d5 100644 --- a/schema_doc.py +++ b/schema_doc.py @@ -13,7 +13,7 @@ from docutils import nodes # This file is not processed by default as extension unless added. # To add this extension from command line use: -# -Dextensions=github,seo,sitemap,schema_doc" +# -Dextensions=github,seo,sitemap,components,schema_doc" # also for improve performance running old version # -d_build/.doctrees-schema