Refactor wiki page to put everything in monthly files

This commit is contained in:
Ayaz Salikhov
2023-11-06 00:26:54 +01:00
parent 641e13e933
commit 3f5cc4fdf2
4 changed files with 88 additions and 60 deletions

View File

@@ -36,8 +36,8 @@ jobs:
repository: ${{ github.repository }}.wiki repository: ${{ github.repository }}.wiki
path: wiki/ path: wiki/
- name: Update wiki page 🏷 - name: Update wiki 🏷
run: python3 -m tagging.update_wiki_page --wiki-dir wiki/ --hist-line-dir /tmp/jupyter/hist_lines/ --manifest-dir /tmp/jupyter/manifests/ run: python3 -m tagging.update_wiki --wiki-dir wiki/ --hist-line-dir /tmp/jupyter/hist_lines/ --manifest-dir /tmp/jupyter/manifests/
shell: bash shell: bash
- name: Push Wiki to GitHub 📤 - name: Push Wiki to GitHub 📤

85
tagging/update_wiki.py Executable file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env python3
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import argparse
import logging
import shutil
from pathlib import Path
LOGGER = logging.getLogger(__name__)
def update_home_wiki_page(wiki_dir: Path, month: str) -> None:
TABLE_BEGINNING = "| - | - |\n"
wiki_home_file = wiki_dir / "Home.md"
wiki_home_content = wiki_home_file.read_text()
month_line = f"| `{month}` | [`link`](./{month}) |\n"
if month_line not in wiki_home_content:
wiki_home_content = wiki_home_content.replace(
TABLE_BEGINNING, TABLE_BEGINNING + month_line
)
wiki_home_file.write_text(wiki_home_content)
LOGGER.info("Wiki home file updated")
def update_monthly_wiki_page(
wiki_dir: Path, month: str, build_history_line: str
) -> None:
MONTHLY_PAGE_HEADER = f"""\
# Images built during {month}
| Date | Image | Links |
| - | - | - |
"""
monthly_page = wiki_dir / (month + ".md")
if not monthly_page.exists():
LOGGER.info("Creating monthly page")
monthly_page.write_text(MONTHLY_PAGE_HEADER)
monthly_page_content = monthly_page.read_text().replace(
MONTHLY_PAGE_HEADER, MONTHLY_PAGE_HEADER + build_history_line + "\n"
)
monthly_page.write_text(monthly_page_content)
def update_wiki(wiki_dir: Path, hist_line_dir: Path, manifest_dir: Path) -> None:
LOGGER.info("Updating wiki")
LOGGER.info("Copying manifest files")
for manifest_file in manifest_dir.glob("*.md"):
shutil.copy(manifest_file, wiki_dir / "manifests" / manifest_file.name)
LOGGER.info(f"Manifest file added: {manifest_file.name}")
for build_history_line_file in sorted(hist_line_dir.glob("*.txt")):
build_history_line = build_history_line_file.read_text()
assert build_history_line.startswith("| `")
month = build_history_line[3:10]
update_home_wiki_page(wiki_dir, month)
update_monthly_wiki_page(wiki_dir, month, build_history_line)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
"--wiki-dir",
required=True,
type=Path,
help="Directory for wiki repo",
)
arg_parser.add_argument(
"--hist-line-dir",
required=True,
type=Path,
help="Directory to save history line",
)
arg_parser.add_argument(
"--manifest-dir",
required=True,
type=Path,
help="Directory to save manifest file",
)
args = arg_parser.parse_args()
update_wiki(args.wiki_dir, args.hist_line_dir, args.manifest_dir)

View File

@@ -1,57 +0,0 @@
#!/usr/bin/env python3
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import argparse
import logging
import shutil
from pathlib import Path
LOGGER = logging.getLogger(__name__)
TABLE_BEGINNING = "|-|-|-|\n"
def update_wiki_page(wiki_dir: Path, hist_line_dir: Path, manifest_dir: Path) -> None:
LOGGER.info("Updating wiki page")
wiki_home_file = wiki_dir / "Home.md"
wiki_home_content = wiki_home_file.read_text()
build_history_line_files = sorted(hist_line_dir.rglob("*.txt"))
build_history_lines = "\n".join(
hist_line_file.read_text() for hist_line_file in build_history_line_files
)
wiki_home_content = wiki_home_content.replace(
TABLE_BEGINNING, TABLE_BEGINNING + build_history_lines + "\n"
)
wiki_home_file.write_text(wiki_home_content)
LOGGER.info("Wiki home file updated")
for manifest_file in sorted(manifest_dir.rglob("*.md")):
shutil.copy(manifest_file, wiki_dir / "manifests" / manifest_file.name)
LOGGER.info(f"Manifest file added: {manifest_file.name}")
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
"--wiki-dir",
required=True,
type=Path,
help="Directory for wiki repo",
)
arg_parser.add_argument(
"--hist-line-dir",
required=True,
type=Path,
help="Directory to save history line",
)
arg_parser.add_argument(
"--manifest-dir",
required=True,
type=Path,
help="Directory to save manifest file",
)
args = arg_parser.parse_args()
update_wiki_page(args.wiki_dir, args.hist_line_dir, args.manifest_dir)

View File

@@ -43,7 +43,7 @@ def write_build_history_line(
f"[Build manifest](./{filename})", f"[Build manifest](./{filename})",
] ]
) )
build_history_line = "|".join([date_column, image_column, links_column]) + "|" build_history_line = f"| {date_column} | {image_column} | {links_column} |"
hist_line_dir.mkdir(parents=True, exist_ok=True) hist_line_dir.mkdir(parents=True, exist_ok=True)
(hist_line_dir / f"{filename}.txt").write_text(build_history_line) (hist_line_dir / f"{filename}.txt").write_text(build_history_line)