Skip to content

Commit 5b82463

Browse files
authored
👷 Upgrade build docs configs (#914)
1 parent b24cf43 commit 5b82463

File tree

10 files changed

+137
-38
lines changed

10 files changed

+137
-38
lines changed

.github/workflows/build-docs.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
docs: ${{ steps.filter.outputs.docs }}
1919
steps:
2020
- uses: actions/checkout@v4
21-
# For pull requests it's not necessary to checkout the code but for master it is
21+
# For pull requests it's not necessary to checkout the code but for the main branch it is
2222
- uses: dorny/paths-filter@v3
2323
id: filter
2424
with:
@@ -28,9 +28,12 @@ jobs:
2828
- docs/**
2929
- docs_src/**
3030
- requirements-docs.txt
31+
- requirements-docs-insiders.txt
3132
- pyproject.toml
3233
- mkdocs.yml
3334
- mkdocs.insiders.yml
35+
- mkdocs.maybe-insiders.yml
36+
- mkdocs.no-insiders.yml
3437
- .github/workflows/build-docs.yml
3538
- .github/workflows/deploy-docs.yml
3639
@@ -53,16 +56,15 @@ jobs:
5356
id: cache
5457
with:
5558
path: ${{ env.pythonLocation }}
56-
key: ${{ runner.os }}-python-docs-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-docs.txt') }}-v02
59+
key: ${{ runner.os }}-python-docs-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-docs.txt', 'requirements-docs-insiders.txt') }}-v02
5760
- name: Install docs extras
5861
if: steps.cache.outputs.cache-hit != 'true'
5962
run: pip install -r requirements-docs.txt
6063
- name: Install Material for MkDocs Insiders
6164
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' ) && steps.cache.outputs.cache-hit != 'true'
62-
run: |
63-
pip install git+https://${{ secrets.TYPER_MKDOCS_MATERIAL_INSIDERS }}@github.com/squidfunk/mkdocs-material-insiders.git
64-
pip install git+https://${{ secrets.TYPER_MKDOCS_MATERIAL_INSIDERS }}@github.com/pawamoy-insiders/griffe-typing-deprecated.git
65-
pip install git+https://${{ secrets.TYPER_MKDOCS_MATERIAL_INSIDERS }}@github.com/pawamoy-insiders/mkdocstrings-python.git
65+
run: pip install -r requirements-docs-insiders.txt
66+
env:
67+
TOKEN: ${{ secrets.TYPER_MKDOCS_MATERIAL_INSIDERS }}
6668
- uses: actions/cache@v4
6769
with:
6870
key: mkdocs-cards-${{ github.ref }}-v1

docs/css/termynal.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
position: relative;
2727
-webkit-box-sizing: border-box;
2828
box-sizing: border-box;
29+
/* Custom line-height */
2930
line-height: 1.2;
3031
}
3132

docs/js/custom.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ async function main() {
110110
setupTermynal()
111111
}
112112

113-
main()
113+
document$.subscribe(() => {
114+
main()
115+
})

docs/js/termynal.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ class Termynal {
249249
attrs += `${this.pfx}-${prop}="${line[prop]}" `
250250
}
251251
}
252-
253252
return attrs;
254253
}
255254
}

mkdocs.insiders.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
plugins:
2-
social:
32
typeset:
3+
markdown_extensions:
4+
material.extensions.preview:
5+
targets:
6+
include:
7+
- ./*

mkdocs.yml

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,40 @@ theme:
2626
icon: material/lightbulb-outline
2727
name: Switch to system preference
2828
features:
29-
- search.suggest
30-
- search.highlight
29+
- content.code.annotate
30+
- content.code.copy
31+
# - content.code.select
32+
- content.footnote.tooltips
3133
- content.tabs.link
32-
- navigation.indexes
3334
- content.tooltips
35+
- navigation.footer
36+
- navigation.indexes
37+
- navigation.instant
38+
- navigation.instant.prefetch
39+
- navigation.instant.preview
40+
- navigation.instant.progress
3441
- navigation.path
35-
- content.code.annotate
36-
- content.code.copy
37-
- content.code.select
3842
# - navigation.tabs
43+
# - navigation.tabs.sticky
44+
- navigation.top
45+
- navigation.tracking
46+
- search.highlight
47+
- search.share
48+
- search.suggest
49+
- toc.follow
50+
3951
icon:
4052
repo: fontawesome/brands/github-alt
4153
logo: img/icon.svg
4254
favicon: img/favicon.png
4355
language: en
4456
repo_name: tiangolo/typer
4557
repo_url: https://github.com/tiangolo/typer
46-
edit_uri: ""
4758
plugins:
48-
search: null
59+
# Material for MkDocs
60+
search:
61+
social:
62+
# Other plugins
4963
redirects:
5064
redirect_maps:
5165
typer-cli.md: tutorial/typer-command.md
@@ -121,36 +135,69 @@ nav:
121135
- release-notes.md
122136

123137
markdown_extensions:
138+
# Python Markdown
139+
abbr:
140+
attr_list:
141+
footnotes:
142+
md_in_html:
143+
tables:
124144
toc:
125145
permalink: true
126-
markdown.extensions.attr_list:
127-
markdown.extensions.tables:
128-
markdown.extensions.md_in_html:
129146

147+
# Python Markdown Extensions
148+
pymdownx.betterem:
149+
smart_enable: all
150+
pymdownx.caret:
151+
pymdownx.highlight:
152+
line_spans: __span
153+
pymdownx.inlinehilite:
154+
pymdownx.keys:
155+
pymdownx.mark:
130156
pymdownx.superfences:
131157
custom_fences:
132158
- name: mermaid
133159
class: mermaid
134-
format: !!python/name:pymdownx.superfences.fence_code_format ''
135-
pymdownx.betterem:
136-
pymdownx.blocks.details:
160+
format: !!python/name:pymdownx.superfences.fence_code_format
161+
pymdownx.tilde:
162+
163+
# pymdownx blocks
137164
pymdownx.blocks.admonition:
138165
types:
139166
- note
140-
- info
167+
- attention
168+
- caution
169+
- danger
170+
- error
141171
- tip
172+
- hint
142173
- warning
143-
- danger
144-
- check
174+
# Custom types
175+
- info
176+
pymdownx.blocks.details:
145177
pymdownx.blocks.tab:
146178
alternate_style: True
179+
180+
# Other extensions
147181
mdx_include:
148182
base_path: docs
149183

150184
extra:
151185
analytics:
152186
provider: google
153187
property: G-T78C5GNRXK
188+
feedback:
189+
title: Was this page helpful?
190+
ratings:
191+
- icon: material/emoticon-happy-outline
192+
name: This page was helpful
193+
data: 1
194+
note: >-
195+
Thanks for your feedback!
196+
- icon: material/emoticon-sad-outline
197+
name: This page could be improved
198+
data: 0
199+
note: >-
200+
Thanks for your feedback!
154201
social:
155202
- icon: fontawesome/brands/github-alt
156203
link: https://github.com/tiangolo/typer
@@ -172,3 +219,6 @@ extra_css:
172219
extra_javascript:
173220
- js/termynal.js
174221
- js/custom.js
222+
223+
hooks:
224+
- scripts/mkdocs_hooks.py

requirements-docs-insiders.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
git+https://${TOKEN}@github.com/squidfunk/[email protected]
2+
git+https://${TOKEN}@github.com/pawamoy-insiders/griffe-typing-deprecated.git
3+
git+https://${TOKEN}@github.com/pawamoy-insiders/mkdocstrings-python.git

requirements-docs.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
-e .
22

3-
mkdocs-material==9.4.7
3+
mkdocs-material==9.5.18
44
mdx-include >=1.4.1,<2.0.0
5-
mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0
65
mkdocs-redirects>=1.2.1,<1.3.0
76
pyyaml >=5.3.1,<7.0.0
87
# For Material for MkDocs, Chinese search
98
# jieba==0.42.1
109
# For image processing by Material for MkDocs
1110
pillow==10.3.0
1211
# For image processing by Material for MkDocs
13-
cairosvg==2.7.0
14-
mkdocstrings[python]==0.23.0
15-
griffe-typingdoc==0.2.2
12+
cairosvg==2.7.1
13+
# mkdocstrings[python]==0.25.1
14+
# Enable griffe-typingdoc once dropping Python 3.7 and upgrading typing-extensions
15+
# griffe-typingdoc==0.2.5
1616
# For griffe, it formats with black
17-
black==24.3.0
17+
# black==24.3.0
18+
mkdocs-macros-plugin==1.0.5

scripts/docs.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
from importlib import metadata
88
from pathlib import Path
99

10-
import mkdocs.commands.build
11-
import mkdocs.commands.serve
12-
import mkdocs.config
13-
import mkdocs.utils
1410
import typer
1511

1612
logging.basicConfig(level=logging.INFO)
@@ -93,8 +89,11 @@ def live() -> None:
9389
en.
9490
"""
9591
# Enable line numbers during local development to make it easier to highlight
96-
os.environ["LINENUMS"] = "true"
97-
mkdocs.commands.serve.serve(dev_addr="127.0.0.1:8008")
92+
subprocess.run(
93+
["mkdocs", "serve", "--dev-addr", "127.0.0.1:8008", "--dirty"],
94+
env={**os.environ, "LINENUMS": "true"},
95+
check=True,
96+
)
9897

9998

10099
@app.command()

scripts/mkdocs_hooks.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Any, List, Union
2+
3+
from mkdocs.config.defaults import MkDocsConfig
4+
from mkdocs.structure.files import Files
5+
from mkdocs.structure.nav import Link, Navigation, Section
6+
from mkdocs.structure.pages import Page
7+
8+
9+
def generate_renamed_section_items(
10+
items: List[Union[Page, Section, Link]], *, config: MkDocsConfig
11+
) -> List[Union[Page, Section, Link]]:
12+
new_items: List[Union[Page, Section, Link]] = []
13+
for item in items:
14+
if isinstance(item, Section):
15+
new_title = item.title
16+
new_children = generate_renamed_section_items(item.children, config=config)
17+
first_child = new_children[0]
18+
if isinstance(first_child, Page):
19+
if first_child.file.src_path.endswith("index.md"):
20+
# Read the source so that the title is parsed and available
21+
first_child.read_source(config=config)
22+
new_title = first_child.title or new_title
23+
# Creating a new section makes it render it collapsed by default
24+
# no idea why, so, let's just modify the existing one
25+
# new_section = Section(title=new_title, children=new_children)
26+
item.title = new_title
27+
item.children = new_children
28+
new_items.append(item)
29+
else:
30+
new_items.append(item)
31+
return new_items
32+
33+
34+
def on_nav(
35+
nav: Navigation, *, config: MkDocsConfig, files: Files, **kwargs: Any
36+
) -> Navigation:
37+
new_items = generate_renamed_section_items(nav.items, config=config)
38+
return Navigation(items=new_items, pages=nav.pages)

0 commit comments

Comments
 (0)