Skip to content

Commit

Permalink
introduce auto-generation of index for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
arogozhnikov committed Nov 9, 2022
1 parent fcd5fe5 commit 686dc1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ dependencies = [
[tool.hatch.envs.docs.scripts]
# For examples to build one has to run:
# hatch run docs:build
build = "mkdocs build --clean --strict {args}"
serve = "mkdocs serve --dev-addr localhost:8000 {args}"
deploy = "mkdocs build --clean --strict && mkdocs gh-deploy"
convert = "python scripts/convert_readme.py"
build = "convert && mkdocs build --clean --strict {args}"
serve = "convert && mkdocs serve --dev-addr localhost:8000 {args}"
deploy = "convert && mkdocs build --clean --strict && mkdocs gh-deploy"


[tool.hatch.envs.pypi.scripts]
Expand Down
31 changes: 31 additions & 0 deletions scripts/convert_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Converts readme from github repo page to mkdocs-friendly
"""
from pathlib import Path

original_text = Path(__file__).parent.parent.joinpath('README.md').read_text(encoding='utf-8')


def replace_with_video_tag(line: str):
if line.startswith('https://') and line.endswith('.mp4') and ' ' not in line:
# treating as link to mp4 file.
return f"""
<video width="800" controls><source src="{line}" type="video/mp4">
Your browser does not support the video </video>\n\n<br />\n\n<br />
""".strip()
else:
# other lines are not touched
return line


new_content = '\n'.join([
replace_with_video_tag(line)
for line in original_text.splitlines()
])
# save contents
docs_index = Path(__file__).parent.parent.joinpath('docs_src', 'index.md')
assert docs_index.parent.exists()
docs_index.write_bytes(
new_content.encode('utf-8')
)
print('Converted README.md')

0 comments on commit 686dc1e

Please sign in to comment.