Skip to content

Commit

Permalink
docs: add a docs workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
EspenAlbert committed Aug 18, 2023
1 parent ae801a4 commit 78cac83
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: docs
on:
push:
branches:
- docs-support
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: actions/cache@v2
with:
key: ${{ github.ref }}
path: .cache
- run: pip install mkdocs-material
- run: pip install pillow cairosvg
- run: python ./pre_docs.py
- run: mkdocs gh-deploy --force
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ __pycache__/
# Editors
.idea/
*.iml

# docs
site
.cache
docs/
65 changes: 65 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
site_name: py-libs documentation
site_url: https://espenalbert.github.io/py-libs/
theme:
name: material
features:
- navigation.tabs
- navigation.sections
- toc.integrate
- navigation.top
- search.suggest
- search.highlight
- content.tabs.link
- content.code.annotation
- content.code.copy
language: en
palette:
- scheme: default
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
primary: teal
accent: purple
- scheme: slate
toggle:
icon: material/toggle-switch
name: Switch to light mode
primary: teal
accent: lime

plugins:
- social
- search

repo_name: EspenAlbert/py-libs
repo_url: https://github.com/EspenAlbert/py-libs
edit_uri: edit/main/docs/
extra:
social:
- icon: fontawesome/brands/github-alt
link: https://github.com/EspenAlbert

nav:
- Get Started: index.md
- Model Lib: model_lib
- Compose Chart Export: compose_chart_export
- Docker Compose Parser: docker_compose_parser
- zero-3rdparty: zero_3rdparty


markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.snippets
- admonition
- pymdownx.arithmatex:
generic: true
- footnotes
- pymdownx.details
- pymdownx.superfences
- pymdownx.mark
- attr_list
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
34 changes: 34 additions & 0 deletions pre_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import shutil
from pathlib import Path
from typing import Iterable

SRC = Path(__file__).parent
DOCS_DIR = SRC / "docs"
IGNORED_MD_DIRECTORIES = [".pytest_cache", "test", "dist"]

FILENAME_RENAME = {
"readme.md": "index.md"
}

def ignore_md_path(rel_path: str) -> bool:
return any(f"{d}/" in rel_path for d in IGNORED_MD_DIRECTORIES)


def add_dest_paths(src_path: Path, md_dest_path: Path) -> Iterable[Path]:
if new_name := FILENAME_RENAME.get(md_dest_path.name):
yield md_dest_path.parent / new_name
yield md_dest_path

def move_md_files():
for md_src_path in SRC.rglob("*.md"):
rel_path = str(md_src_path.relative_to(SRC))
if md_src_path.is_relative_to(DOCS_DIR) or ignore_md_path(rel_path):
continue
md_dest_path = DOCS_DIR / rel_path
for final_dest_path in add_dest_paths(md_src_path, md_dest_path):
final_dest_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(md_src_path, final_dest_path)


if __name__ == "__main__":
move_md_files()
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@
- An experiment for sharing python packages
- [model_lib-pydantic base models with convenient dump methods](./model_lib/readme.md)
- `pip install model-lib`
- [zero_lib-handy standalone scripts without 3rdparty dependencies](./zero_3rdparty)
- [zero_lib-handy standalone scripts without 3rdparty dependencies](./zero_3rdparty/readme.md)
- `pip install zero-3rdparty`

0 comments on commit 78cac83

Please sign in to comment.