mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-14 05:34:21 -04:00
feat: add docs and sync with wiki & website
This commit is contained in:
parent
1fc89d01eb
commit
5906d9621e
28 changed files with 2594 additions and 0 deletions
61
.github/scripts/sync-wiki.py
vendored
Normal file
61
.github/scripts/sync-wiki.py
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python3
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
DOCS_DIR = Path("docs")
|
||||
WIKI_DIR = Path("wiki-temp")
|
||||
|
||||
FRONTMATTER_RE = re.compile(r"\A---\s*\n.*?^---\s*\n", re.DOTALL | re.MULTILINE)
|
||||
DOCS_LINK_RE = re.compile(r"\[([^\]]+)\]\(/docs/(?:[^/)]+/)*([^/)#]+)(#[^)]+)?\)")
|
||||
|
||||
|
||||
def collect_all_files() -> list[tuple[Path, str]]:
|
||||
files = []
|
||||
|
||||
def from_dir(directory: Path) -> list[Path]:
|
||||
meta = directory / "meta.json"
|
||||
if meta.exists():
|
||||
data = json.loads(meta.read_text())
|
||||
return [directory / f"{p}.md" for p in data.get("pages", []) if (directory / f"{p}.md").exists()]
|
||||
return sorted(directory.glob("*.md"))
|
||||
|
||||
for src in from_dir(DOCS_DIR):
|
||||
files.append((src, "Home" if src.stem == "index" else src.stem))
|
||||
|
||||
for subdir in sorted(DOCS_DIR.iterdir()):
|
||||
if subdir.is_dir():
|
||||
for src in from_dir(subdir):
|
||||
files.append((src, src.stem))
|
||||
|
||||
return files
|
||||
|
||||
|
||||
def main() -> None:
|
||||
files = collect_all_files()
|
||||
|
||||
contents = {src: src.read_text() for src, _ in files}
|
||||
|
||||
for src, dest_name in files:
|
||||
text = FRONTMATTER_RE.sub("", contents[src], count=1).lstrip("\n")
|
||||
text = DOCS_LINK_RE.sub(lambda m: f"[{m.group(1)}]({m.group(2)}{m.group(3) or ''})", text)
|
||||
(WIKI_DIR / f"{dest_name}.md").write_text(text)
|
||||
|
||||
lines: list[str] = []
|
||||
current_section = None
|
||||
for src, dest_name in files:
|
||||
section = "General" if src.parent == DOCS_DIR else src.parent.name.replace("-", " ").title()
|
||||
if section != current_section:
|
||||
if current_section is not None:
|
||||
lines.append("")
|
||||
lines.append(f"## {section}\n")
|
||||
current_section = section
|
||||
if dest_name != "Home":
|
||||
title = dest_name.replace("-", " ").replace("_", " ").title()
|
||||
lines.append(f"- [[{dest_name}|{title}]]")
|
||||
|
||||
(WIKI_DIR / "_Sidebar.md").write_text("\n".join(lines))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
42
.github/workflows/sync-website.yml
vendored
Normal file
42
.github/workflows/sync-website.yml
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
name: Sync website
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- docs/**
|
||||
|
||||
concurrency:
|
||||
group: sync-website
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
sync-website:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
token: ${{ github.token }}
|
||||
|
||||
- name: Checkout website
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: mangowm/mangowm.github.io
|
||||
path: website
|
||||
token: ${{ secrets.WEBSITE_SYNC_TOKEN }}
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Sync docs
|
||||
run: |
|
||||
rm -rf website/apps/web/content/docs
|
||||
cp -r docs website/apps/web/content/docs
|
||||
|
||||
- name: Commit and push
|
||||
working-directory: website
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add apps/web/content/docs
|
||||
git diff --staged --quiet || git commit -m "sync from mango @ ${{ github.sha }}"
|
||||
git push
|
||||
40
.github/workflows/sync-wiki.yml
vendored
Normal file
40
.github/workflows/sync-wiki.yml
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
name: Sync wiki
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- docs/**
|
||||
|
||||
concurrency:
|
||||
group: sync-wiki
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
sync-wiki:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Clone wiki
|
||||
run: |
|
||||
git clone --depth 1 \
|
||||
https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.wiki.git \
|
||||
wiki-temp
|
||||
|
||||
- name: Sync docs to wiki
|
||||
run: |
|
||||
find wiki-temp -not -path 'wiki-temp/.git*' -type f -delete
|
||||
python3 .github/scripts/sync-wiki.py
|
||||
|
||||
- name: Commit and push
|
||||
working-directory: wiki-temp
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add -A
|
||||
git diff --staged --quiet || git commit -m "sync from ${{ github.sha }}"
|
||||
git push
|
||||
Loading…
Add table
Add a link
Reference in a new issue