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

Create a named tmp directory for techdocs_metadata generation #9

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Extensions:

## Changelog

### 0.0.13

- Fixed issue where the whole temp directory could be included in the built site output. [#7](https://github.com/backstage/mkdocs-techdocs-core/issues/7)

### 0.0.12

- Updated home repository to be the new https://github.com/backstage/mkdocs-techdocs-core
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

setup(
name="mkdocs-techdocs-core",
version="0.0.12",
version="0.0.13",
description="The core MkDocs plugin used by Backstage's TechDocs as a wrapper around "
"multiple MkDocs plugins and Python Markdown extensions",
long_description=long_description,
Expand Down
20 changes: 13 additions & 7 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
* limitations under the License.
"""

import tempfile
import os
from mkdocs.plugins import BasePlugin
from mkdocs.theme import Theme
from mkdocs.contrib.search import SearchPlugin
from mkdocs_monorepo_plugin.plugin import MonorepoPlugin
from pymdownx.emoji import to_svg
import tempfile
import os


class TechDocsCore(BasePlugin):

def __init__(self):
# This directory will be removed automatically once the docs are built
# MkDocs needs a directory for the theme with the `techdocs_metadata.json` file
self.tmp_dir_techdocs_theme = tempfile.TemporaryDirectory()

def on_config(self, config):
fp = open(os.path.join(tempfile.gettempdir(), "techdocs_metadata.json"), "w+")
fp.write(
'{\n "site_name": "{{ config.site_name }}",\n "site_description": "{{ config.site_description }}"\n}'
)
with open(os.path.join(self.tmp_dir_techdocs_theme.name, "techdocs_metadata.json"), "w+") as fp:
fp.write(
'{\n "site_name": "{{ config.site_name }}",\n "site_description": "{{ config.site_description }}"\n}'
)

mdx_configs_override = {}
if "mdx_configs" in config:
Expand All @@ -41,7 +47,7 @@ def on_config(self, config):
"techdocs_metadata.json",
],
)
config["theme"].dirs.append(tempfile.gettempdir())
config["theme"].dirs.append(self.tmp_dir_techdocs_theme.name)

# Plugins
del config["plugins"]["techdocs-core"]
Expand Down