diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1f2d96bd..bdc9c751 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,7 +6,7 @@ on: paths: - 'Documentation/**' - 'Harmony/**' - - 'Lib.Harmony/**' + - 'scripts/generate_llm_pack.py' - '.github/workflows/docs.yml' jobs: @@ -30,10 +30,35 @@ jobs: - name: Build Documentation run: docfx Documentation/docfx.json + - name: Install Python dependencies + run: pip install pyyaml + + - name: Generate LLM Pack + run: python scripts/generate_llm_pack.py + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 if: github.ref == 'refs/heads/master' with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs - force_orphan: true \ No newline at end of file + force_orphan: true + - name: Build Library + run: dotnet build -c Debug -f net35 .\Lib.Harmony\Lib.Harmony.csproj + + - name: Build Documentation + run: docfx Documentation/docfx.json + + - name: Install Python dependencies + run: pip install pyyaml + + - name: Generate LLM Pack + run: python scripts/generate_llm_pack.py + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + if: github.ref == 'refs/heads/master' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs + force_orphan: true \ No newline at end of file diff --git a/scripts/generate_llm_pack.py b/scripts/generate_llm_pack.py new file mode 100644 index 00000000..94994d22 --- /dev/null +++ b/scripts/generate_llm_pack.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +from pathlib import Path +import json + +import yaml + +OUT_DIR = Path('docs', 'llm-pack') +OUT_DIR.mkdir(parents=True, exist_ok=True) +OUT_FILE = OUT_DIR / 'harmony.cards.jsonl' + +cards = [] + +# API +for path in Path('Documentation/api').rglob('*.yml'): + with path.open(encoding='utf-8') as f: + data = yaml.safe_load(f) + for item in data.get('items', []): + uid = item.get('uid') + kind = (item.get('type') or '').lower() + if not uid or not kind: + continue + summary = item.get('summary') + signature = item.get('syntax', {}).get('content') + remarks = item.get('remarks') + parent = item.get('parent') + href = item.get('href') + if href: + doc_url = f'https://harmony.pardeike.net/docs/{href.lstrip("/")}' + else: + doc_page = uid if not parent or parent == 'HarmonyLib' else parent + doc_url = f'https://harmony.pardeike.net/docs/api/{doc_page}.html' + cards.append({ + 'id': uid, + 'kind': kind, + 'summary': summary, + 'signature': signature, + 'remarks': remarks, + 'doc_url': doc_url, + 'examples': None + }) + +# Articles +for path in Path('Documentation/articles').rglob('*.md'): + with path.open(encoding='utf-8') as f: + lines = [line.strip() for line in f] + lines = [l for l in lines if l] + if not lines: + continue + summary = lines[0] + remarks = '\n'.join(lines[1:5]) if len(lines) > 1 else None + rel = path.relative_to('Documentation') + slug = rel.with_suffix('').as_posix() + doc_url = f'https://harmony.pardeike.net/docs/{slug}.html' + cards.append({ + 'id': slug, + 'kind': 'article', + 'summary': summary, + 'signature': None, + 'remarks': remarks, + 'doc_url': doc_url, + 'examples': None + }) + +with OUT_FILE.open('w', encoding='utf-8') as out: + for card in cards: + out.write(json.dumps(card, ensure_ascii=False) + '\n')