Skip to content

Commit

Permalink
Specify config file location in generator (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
athackst committed Jun 14, 2021
1 parent d53825e commit 26fc121
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 44 deletions.
33 changes: 12 additions & 21 deletions .vscode/tasks.json
Expand Up @@ -73,7 +73,9 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"test set",
"test lint",
"test unittest",
"test integration",
"htmlproofer"
],
"group": {
Expand All @@ -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",
Expand All @@ -108,8 +99,8 @@
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": false
"showReuseMessage": false,
"clear": true
}
},
{
Expand All @@ -122,8 +113,8 @@
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": false
"showReuseMessage": false,
"clear": true
}
},
{
Expand All @@ -136,8 +127,8 @@
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": false
"showReuseMessage": false,
"clear": true
}
},
{
Expand All @@ -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",
Expand All @@ -161,8 +152,8 @@
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": false
"showReuseMessage": false,
"clear": true
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion action.yml
Expand Up @@ -65,7 +65,7 @@ inputs:
required: false
default: material
config:
description: "Configuration settings"
description: "Configuration file"
required: false
runs:
using: "docker"
Expand Down
3 changes: 3 additions & 0 deletions 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"

Expand Down
3 changes: 0 additions & 3 deletions docker/entrypoint.sh
Expand Up @@ -5,7 +5,4 @@ if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
fi

mkdocs_simple_gen
mkdocs build

exec "$@"
32 changes: 14 additions & 18 deletions mkdocs_simple_plugin/generator.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -120,41 +113,44 @@ 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`
```txt
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.
Expand Down

0 comments on commit 26fc121

Please sign in to comment.