Skip to content

Commit

Permalink
Add build process for rendering markdown to html
Browse files Browse the repository at this point in the history
  • Loading branch information
reweeden committed Oct 25, 2022
1 parent 5825929 commit 1c859ae
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ SOURCES := \
lambda/tea_bumper.py \
lambda/update_lambda.py

RESOURCES := $(wildcard lambda/templates/*)
HTML_TEMPLATES := $(wildcard lambda/templates/*.html)
MD_TEMPLATES := $(wildcard lambda/templates/*.md)
TERRAFORM := $(wildcard terraform/*)

REQUIREMENTS_IN := $(wildcard requirements/*.in)
Expand All @@ -15,7 +16,9 @@ DIR := dist
EMPTY := $(DIR)/empty
# Temporary artifacts
DIST_SOURCES := $(SOURCES:lambda/%=$(DIR)/code/%)
DIST_RESOURCES := $(RESOURCES:lambda/%=$(DIR)/code/%)
DIST_MD_RESOURCES := $(MD_TEMPLATES:lambda/%.md=$(DIR)/code/%.html)
DIST_HTML_RESOURCES := $(HTML_TEMPLATES:lambda/%=$(DIR)/code/%)
DIST_RESOURCES := $(DIST_HTML_RESOURCES) $(DIST_MD_RESOURCES)
DIST_TERRAFORM := $(TERRAFORM:terraform/%=$(DIR)/terraform/%)

BUCKET_MAP_OBJECT_KEY := DEFAULT
Expand Down Expand Up @@ -105,8 +108,13 @@ $(DIR)/thin-egress-app-dependencies.zip: requirements/requirements.txt $(REQUIRE
@mkdir -p $(DIR)/python
$(DOCKER_LAMBDA_CI) build/dependency_builder.sh "$(DIR)/thin-egress-app-dependencies.zip" "$(DIR)"

.SECONDARY: $(DIST_MD_RESOURCES)
$(DIST_MD_RESOURCES): $(DIR)/code/%.html: lambda/%.md $(BUILD_VENV)
@mkdir -p $(@D)
$(BUILD_VENV)/bin/python scripts/render_md.py $< --output $@

.SECONDARY: $(DIST_RESOURCES)
$(DIST_RESOURCES): $(DIR)/code/%: lambda/%
$(DIST_HTML_RESOURCES): $(DIR)/code/%: lambda/%
@mkdir -p $(@D)
cp $< $@

Expand Down
1 change: 1 addition & 0 deletions lambda/templates/s3access.md
3 changes: 3 additions & 0 deletions requirements/requirements-make.in
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
jinja2
markdown
pygments
pymdown-extensions
12 changes: 12 additions & 0 deletions requirements/requirements-make.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
#
# pip-compile requirements/requirements-make.in
#
importlib-metadata==5.0.0
# via markdown
jinja2==3.1.2
# via -r requirements/requirements-make.in
markdown==3.4.1
# via
# -r requirements/requirements-make.in
# pymdown-extensions
markupsafe==2.1.1
# via jinja2
pygments==2.13.0
# via -r requirements/requirements-make.in
pymdown-extensions==9.7
# via -r requirements/requirements-make.in
zipp==3.10.0
# via importlib-metadata
34 changes: 34 additions & 0 deletions scripts/render_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import argparse
from pathlib import Path
from typing import Optional

import markdown


def render_markdown(inpath: Path, outpath: Optional[Path] = None):
rendered = markdown.markdown(
inpath.read_text(),
extensions=[
"markdown.extensions.sane_lists",
"markdown.extensions.tables",
"pymdownx.betterem",
"pymdownx.highlight",
"pymdownx.superfences",
]
)
outpath = outpath or inpath.with_suffix(".html")
outpath.write_text(rendered)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("input", type=Path)
parser.add_argument("--output", "-o", type=Path)

args = parser.parse_args()

render_markdown(args.input, args.output)


if __name__ == "__main__":
main()

0 comments on commit 1c859ae

Please sign in to comment.