This commit is contained in:
Florian Albrechtskirchinger 2024-01-28 16:25:47 -07:00 committed by GitHub
commit e24ddc14b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 69 additions and 2 deletions

1
.gitignore vendored
View File

@ -32,6 +32,7 @@
/docs/mkdocs/docs/__pycache__/ /docs/mkdocs/docs/__pycache__/
/docs/mkdocs/docs/examples/ /docs/mkdocs/docs/examples/
/docs/mkdocs/docs/images/json.gif /docs/mkdocs/docs/images/json.gif
/docs/mkdocs/scripts/__pycache__/
/docs/mkdocs/site/ /docs/mkdocs/site/
/docs/mkdocs/venv/ /docs/mkdocs/venv/

View File

@ -0,0 +1,9 @@
---
x-nlohmann-json-is-internal: true
---
# Developer Documentation
!!! missing
This section is under construction.

View File

@ -293,6 +293,8 @@ nav:
- 'NLOHMANN_JSON_VERSION_MAJOR': api/macros/nlohmann_json_version_major.md - 'NLOHMANN_JSON_VERSION_MAJOR': api/macros/nlohmann_json_version_major.md
- 'NLOHMANN_JSON_VERSION_MINOR': api/macros/nlohmann_json_version_major.md - 'NLOHMANN_JSON_VERSION_MINOR': api/macros/nlohmann_json_version_major.md
- 'NLOHMANN_JSON_VERSION_PATCH': api/macros/nlohmann_json_version_major.md - 'NLOHMANN_JSON_VERSION_PATCH': api/macros/nlohmann_json_version_major.md
- Internal:
- api/internal/index.md
# Extras # Extras
extra: extra:
@ -358,6 +360,9 @@ plugins:
'api/basic_json/operator_literal_json.md': api/operator_literal_json.md 'api/basic_json/operator_literal_json.md': api/operator_literal_json.md
'api/basic_json/operator_literal_json_pointer.md': api/operator_literal_json_pointer.md 'api/basic_json/operator_literal_json_pointer.md': api/operator_literal_json_pointer.md
'api/json_pointer/operator_string.md': api/json_pointer/operator_string_t.md 'api/json_pointer/operator_string.md': api/json_pointer/operator_string_t.md
- mkdocs-simple-hooks:
hooks:
on_page_context: scripts.internal_section:on_page_context
extra_css: extra_css:
- css/custom.css - css/custom.css

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import glob import glob
import os.path import os.path
@ -8,6 +8,28 @@ import sys
warnings = 0 warnings = 0
def filter_internal(files):
try:
import mkdocs.utils.meta
except ModuleNotFoundError:
print('Module mkdocs.utils.meta not found. Cannot exclude internal documentation pages from checks.')
return files
internal_paths = []
for file in files:
_, data = mkdocs.utils.meta.get_data(file)
if data.get('x-nlohmann-json-is-internal', False):
internal_paths.append(os.path.dirname(file))
def parent_of(path, parent):
return os.path.commonpath([parent]) == os.path.commonpath([path, parent])
return [
file for file in files
if not any(parent_of(file, path) for path in internal_paths)
]
def report(rule, location, description): def report(rule, location, description):
global warnings global warnings
warnings += 1 warnings += 1
@ -45,7 +67,7 @@ def check_structure():
'Version history' 'Version history'
] ]
files = sorted(glob.glob('api/**/*.md', recursive=True)) files = sorted(filter_internal(glob.glob('api/**/*.md', recursive=True)))
for file in files: for file in files:
with open(file) as file_content: with open(file) as file_content:
section_idx = -1 # the index of the current h2 section section_idx = -1 # the index of the current h2 section

View File

@ -0,0 +1,30 @@
import sys
from copy import deepcopy
from mkdocs.structure.nav import Navigation, Section, Page
def _get_internal_sections(items, current_page):
res = []
sections = [item for item in items if isinstance(item, Section)]
while sections:
for section in sections[:]:
for item in section.children:
if isinstance(item, Section):
sections.append(item)
elif isinstance(item, Page):
if item.meta.get("x-nlohmann-json-is-internal", False):
res.append(section)
sections.remove(section)
return res
def on_page_context(context, page, config, nav):
sys.setrecursionlimit(1200)
nav = deepcopy(nav)
context["nav"] = nav
sections = _get_internal_sections(nav.items, page)
for section in sections:
if not section.active:
section.children = [child for child in section.children if child.is_index]
return context