Skip to content

Commit

Permalink
Merge pull request #206 from stan-dev/also-index-docs
Browse files Browse the repository at this point in the history
Merge docs search.json into top-level search.json
  • Loading branch information
WardBrian authored Jan 13, 2025
2 parents d3487a7 + d0984dd commit 46b7b1b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- master
workflow_dispatch:


concurrency:
group: production
cancel-in-progress: true
Expand All @@ -29,19 +28,19 @@ jobs:
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
# note: when updating, make sure merge_docs_search.py still works
version: 1.6.39

- name: Render with Quarto
run: |
mkdir -p site
quarto render --to html
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './_website'
path: "./_website"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
5 changes: 3 additions & 2 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ project:
title: "Stan"
type: website
output-dir: _website
post-render: quarto-config/generate_redirects.py redirects.txt --output_dir=_website
# TODO merge search.json with docs search.json
post-render:
- quarto-config/generate_redirects.py redirects.txt --output_dir=_website
- ./merge_docs_search.py --output_dir=_website
render:
- "index.qmd"
- "404.qmd"
Expand Down
41 changes: 41 additions & 0 deletions merge_docs_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Make it so that the top-level searching for the website includes the Stan
documentation stubs as well
"""

import pathlib
import argparse
import json

import requests


DOCS_JSON_URL = "https://mc-stan.org/docs/search.json"

arguments = argparse.ArgumentParser()
arguments.add_argument(
"--output_dir", type=pathlib.Path, default=pathlib.Path(__file__).parent
)

args = arguments.parse_args()

out = args.output_dir

search = out / "search.json"

search_data = json.loads(search.read_text())

docs_search = json.loads(requests.get(DOCS_JSON_URL).text)

for item in docs_search:
# need to add the /docs/ prefix to the objectID and href
objectID = item["objectID"]
href = item["href"]
item |= {
"objectID": f"docs/{objectID}",
"href": f"docs/{href}",
}

search_data.append(item)

search.write_text(json.dumps(search_data, indent=2))

0 comments on commit 46b7b1b

Please sign in to comment.