From 26fc1211097038fa7f4f3d468196d82086831fc1 Mon Sep 17 00:00:00 2001 From: Allison Thackston Date: Sun, 13 Jun 2021 21:29:16 -0700 Subject: [PATCH] Specify config file location in generator (#196) --- .vscode/tasks.json | 33 +++++++++++-------------------- Dockerfile | 2 +- action.yml | 2 +- docker/deploy.sh | 3 +++ docker/entrypoint.sh | 3 --- mkdocs_simple_plugin/generator.py | 32 +++++++++++++----------------- 6 files changed, 31 insertions(+), 44 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9bb1d4ee..2e26910f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -73,7 +73,9 @@ "type": "shell", "dependsOrder": "sequence", "dependsOn": [ - "test set", + "test lint", + "test unittest", + "test integration", "htmlproofer" ], "group": { @@ -87,17 +89,6 @@ "command": "./tests/test.sh", "problemMatcher": [] }, - { - "label": "test set", - "type": "shell", - "dependsOrder": "parallel", - "dependsOn": [ - "test unittest", - "test integration", - "test lint" - ], - "problemMatcher": [] - }, { "label": "test unittest", "type": "shell", @@ -108,8 +99,8 @@ "reveal": "always", "focus": false, "panel": "dedicated", - "showReuseMessage": true, - "clear": false + "showReuseMessage": false, + "clear": true } }, { @@ -122,8 +113,8 @@ "reveal": "always", "focus": false, "panel": "dedicated", - "showReuseMessage": true, - "clear": false + "showReuseMessage": false, + "clear": true } }, { @@ -136,8 +127,8 @@ "reveal": "always", "focus": false, "panel": "dedicated", - "showReuseMessage": true, - "clear": false + "showReuseMessage": false, + "clear": true } }, { @@ -147,8 +138,8 @@ "args": [ "--url-ignore=https://fonts.gstatic.com,https://twitter.com/althack", "--allow-hash-href", - "--file-ignore=./site/404.html", "--internal-domains='athackst.github.io/mkdocs-simple-plugin'", + "--url-swap=^/mkdocs-simple-plugin:", "./site/" ], "dependsOrder": "sequence", @@ -161,8 +152,8 @@ "reveal": "always", "focus": false, "panel": "dedicated", - "showReuseMessage": true, - "clear": false + "showReuseMessage": false, + "clear": true } }, { diff --git a/Dockerfile b/Dockerfile index 7593acf0..80911ed6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,4 +35,4 @@ COPY docker/deploy.sh /usr/local/bin/ COPY docker/entrypoint.sh /usr/local/bin/ ENTRYPOINT ["entrypoint.sh"] -CMD ["mkdocs", "serve", "-a", "0.0.0.0:8000"] +CMD ["mkdocs_simple_gen", "--serve", "--", "-a", "0.0.0.0:8000"] diff --git a/action.yml b/action.yml index dd513c7c..40abebc8 100644 --- a/action.yml +++ b/action.yml @@ -65,7 +65,7 @@ inputs: required: false default: material config: - description: "Configuration settings" + description: "Configuration file" required: false runs: using: "docker" diff --git a/docker/deploy.sh b/docker/deploy.sh index 8e87029f..084e1fcb 100755 --- a/docker/deploy.sh +++ b/docker/deploy.sh @@ -1,5 +1,8 @@ #!/bin/bash +mkdocs_simple_gen --config-file ${ {$INPUT_CONFIG} : 'mkdocs.yml' } +mkdocs build + git config --global user.name "${GITHUB_ACTOR}" git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 669ce36c..1036ad65 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -5,7 +5,4 @@ if [ -f "requirements.txt" ]; then pip install -r requirements.txt fi -mkdocs_simple_gen -mkdocs build - exec "$@" diff --git a/mkdocs_simple_plugin/generator.py b/mkdocs_simple_plugin/generator.py index 6d0b3cd8..f176390b 100644 --- a/mkdocs_simple_plugin/generator.py +++ b/mkdocs_simple_plugin/generator.py @@ -6,7 +6,7 @@ configuration file (only if needed) and optionally install dependencies, build, and serve the site. -# Installation +## Installation Install the plugin with pip. @@ -44,26 +44,19 @@ def default_config(): # and may not exist. config['edit_uri'] = '' - if "CONFIG_FILE" in os.environ.keys() and os.environ["CONFIG_FILE"]: - with open(os.environ["CONFIG_FILE"], 'r') as file: - try: - config = yaml.load(file) - except yaml.YAMLError as exc: - print(exc) - config['site_url'] = 'http://localhost' def maybe_set_string(name): - env_variable = "INPUT_"+name.upper() + env_variable = "INPUT_" + name.upper() config_variable = name.lower() if env_variable in os.environ.keys() and os.environ[env_variable]: config[config_variable] = os.environ[env_variable] def maybe_set_dict(name, key): - env_variable = "INPUT_"+name.upper() + env_variable = "INPUT_" + name.upper() config_variable = name.lower() if env_variable in os.environ.keys() and os.environ[env_variable]: - config[config_variable] = { key: os.environ[env_variable] } + config[config_variable] = {key: os.environ[env_variable]} # Set the config variables via environment if exist maybe_set_string("site_name") maybe_set_string("site_url") @@ -120,34 +113,36 @@ def setup_config(config_file="mkdocs.yml"): except yaml.YAMLError as exc: print(exc) raise - print(config_file) write_config(config_file, config) return config @click.command() +@click.option("--config-file", default="mkdocs.yml", + help="set the configuration file") @click.option('--build/--no-build', default=False, help="build the site using mkdocs build") @click.option('--serve/--no-serve', default=False, help="serve the site using mkdocs serve") @click.argument('mkdocs-args', nargs=-1) -def main(build, serve, mkdocs_args): +def main(config_file, build, serve, mkdocs_args): """Generate and build a mkdocs site.""" - setup_config() + setup_config(config_file) + args = mkdocs_args + ("-f", config_file) if build: - os.system("mkdocs build " + " ".join(mkdocs_args)) + os.system("mkdocs build " + " ".join(args)) if serve: - os.system("mkdocs serve " + " ".join(mkdocs_args)) + os.system("mkdocs serve " + " ".join(args)) """ md -# Usage +## Usage ```bash mkdocs_simple_gen ``` -# Command line options +### Command line options See `--help` @@ -155,6 +150,7 @@ def main(build, serve, mkdocs_args): Usage: mkdocs_simple_gen [OPTIONS] Options: + --config-file set the configuration file --build / --no-build build the site using mkdocs build --serve / --no-serve serve the site using mkdocs serve --help Show this message and exit.