Skip to content

Commit 38d15d7

Browse files
authored
Merge pull request #13 from docsforadobe/change/common-config
Update repo to use common org-wide components
2 parents 0cc211f + 63cca1e commit 38d15d7

26 files changed

+901
-496
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jobs:
2222
- uses: actions/setup-python@v5
2323
with:
2424
python-version: 3.x
25+
26+
- name: Install Python dependencies
27+
uses: py-actions/py-dependency-install@v4
28+
2529
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
2630

2731
- uses: actions/cache@v4
@@ -30,11 +34,5 @@ jobs:
3034
path: .cache
3135
restore-keys: |
3236
mkdocs-material-
33-
- run: >
34-
pip install
35-
markdown_grid_tables
36-
mkdocs-exclude-search
37-
mkdocs-git-revision-date-localized-plugin
38-
mkdocs-material
39-
mkdocs-print-site-plugin
37+
4038
- run: mkdocs gh-deploy --force

docs/_global/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.sublime-project
2+
*.sublime-workspace
3+
.DS_Store
4+
.vscode/
5+
__pycache__/
6+
site/
7+
venv/
File renamed without changes.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Handles merging mkdocs config in a way the native inheritance feature doesn't quite cover
2+
#
3+
# This relies on a key in "extra.overrides"
4+
# Valid keys are `custom_dir: str` and `hooks: [-path/to.py, -path/to.py]`, e.g.
5+
#
6+
# ```yml
7+
# extra:
8+
# overrides:
9+
# custom_dir: overrides
10+
# extra_css:
11+
# - docs/_global/css/global.css
12+
# - docs/_global/css/global-syntax-highlight.css
13+
# extra_javascript:
14+
# - docs/_global/js/global.js
15+
# hooks:
16+
# - hooks/local_override.py
17+
# - hooks/local_override2.py
18+
# theme_features:
19+
# - theme.feature1
20+
# - theme.feature2
21+
# ```
22+
23+
import os
24+
25+
import mkdocs
26+
from mkdocs.config.defaults import MkDocsConfig
27+
from mkdocs.config.config_options import (Hooks, ListOfItems, File, FilesystemObject)
28+
from mkdocs.structure.files import (Files, File as FileStructure)
29+
30+
# Load any local files into mkdocs
31+
def append_local_files(files: Files, config: MkDocsConfig, local_files: list):
32+
for local_file_path in local_files:
33+
local_file = FileStructure(
34+
path= local_file_path,
35+
src_dir=config["docs_dir"] + "/../",
36+
dest_dir=config["site_dir"],
37+
use_directory_urls=False,
38+
)
39+
40+
files.append(local_file)
41+
42+
# Load any override theme features
43+
def merge_local_theme_features(config: MkDocsConfig, theme_features: list):
44+
for local_feature in theme_features:
45+
config.theme["features"].append(local_feature)
46+
47+
# Add additional theme_override folder
48+
def merge_local_theme_override(config: MkDocsConfig, custom_dir: str):
49+
try:
50+
local_override_path = FilesystemObject(exists=True).validate(custom_dir)
51+
except Exception as e:
52+
raise e
53+
54+
config.theme.dirs.insert(1, local_override_path)
55+
56+
# Load any override hooks
57+
def merge_local_hooks(config: MkDocsConfig, hooks: list):
58+
try:
59+
paths = ListOfItems(File(exists=True)).validate(hooks)
60+
except Exception as e:
61+
raise e
62+
63+
for name, path in zip(hooks, paths):
64+
config.plugins[name] = Hooks._load_hook(mkdocs, name, path)
65+
66+
def on_files(files: Files, config: MkDocsConfig):
67+
if "overrides" in config.extra:
68+
extra_overrides = config.extra["overrides"]
69+
70+
if "extra_css" in extra_overrides:
71+
extra_css = extra_overrides["extra_css"]
72+
append_local_files(files, config, extra_css)
73+
74+
if "extra_javascript" in extra_overrides:
75+
extra_javascript = extra_overrides["extra_javascript"]
76+
append_local_files(files, config, extra_javascript)
77+
78+
79+
def on_config(config: MkDocsConfig):
80+
if "overrides" in config.extra:
81+
extra_overrides = config.extra["overrides"]
82+
83+
if "hooks" in extra_overrides:
84+
hooks = extra_overrides["hooks"]
85+
merge_local_hooks(config, hooks)
86+
87+
if "custom_dir" in extra_overrides:
88+
custom_dir = extra_overrides["custom_dir"]
89+
merge_local_theme_override(config, custom_dir)
90+
91+
if "extra_css" in extra_overrides:
92+
extra_css = extra_overrides["extra_css"]
93+
config.extra_css.extend(extra_css)
94+
95+
if "extra_javascript" in extra_overrides:
96+
extra_javascript = extra_overrides["extra_javascript"]
97+
config.extra_javascript.extend(extra_javascript)
98+
99+
if "theme_features" in extra_overrides:
100+
theme_features = extra_overrides["theme_features"]
101+
merge_local_theme_features(config, theme_features)

docs/_global/js/global.js

Whitespace-only changes.

docs/_global/mkdocs.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Shared config for all repos
2+
copyright: All content is copyright Adobe Systems Incorporated.
3+
4+
extra:
5+
homepage: https://docsforadobe.dev
6+
7+
# Using overrides here as we can't inherit "extra_css"
8+
overrides:
9+
extra_css:
10+
- docs/_global/css/global.css
11+
- docs/_global/css/global-syntax-highlight.css
12+
extra_javascript:
13+
- docs/_global/js/global.js
14+
15+
hooks:
16+
- docs/_global/hooks/merge_inherited_config.py
17+
18+
markdown_extensions:
19+
admonition: {}
20+
markdown_grid_tables: {}
21+
md_in_html: {}
22+
pymdownx.details: {}
23+
pymdownx.superfences: {}
24+
pymdownx.tabbed:
25+
alternate_style: true
26+
pymdownx.tasklist:
27+
custom_checkbox: true
28+
toc:
29+
title: Page Contents
30+
permalink: true
31+
toc_depth: 3
32+
33+
plugins:
34+
git-revision-date-localized: {}
35+
search:
36+
separator: '[\s\-,\.:!=\[\]()"/]+'
37+
38+
# Note: print-site must be last!
39+
print-site:
40+
add_cover_page: true
41+
add_print_site_banner: true
42+
cover_page_template: "docs/_global/overrides/templates/print_site_cover_page.tpl"
43+
print_page_title: "Offline Docs"
44+
print_site_banner_template: "docs/_global/overrides/templates/print_site_banner.tpl"
45+
46+
theme:
47+
name: material
48+
custom_dir: docs/_global/overrides
49+
features:
50+
- announce.dismiss
51+
- content.action.edit
52+
- content.action.view
53+
- search.highlight
54+
- search.suggest
55+
- toc.follow
56+
palette:
57+
# Palette toggle for dark mode
58+
- media: "(prefers-color-scheme: dark)"
59+
primary: black
60+
scheme: slate
61+
toggle:
62+
icon: material/brightness-4
63+
name: Switch to light mode
64+
65+
# Palette toggle for light mode
66+
- media: "(prefers-color-scheme: light)"
67+
primary: white
68+
scheme: default
69+
toggle:
70+
icon: material/brightness-7
71+
name: Switch to dark mode
File renamed without changes.

overrides/main.html renamed to docs/_global/overrides/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base.html" %}
22

33
{% block announce %}
4-
Welcome to the new scripting guide!
4+
Welcome to the new docsforadobe guide!
55

66
This is a work in progress.
77

docs/_global/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# docsforadobe.dev MkDocs Config
2+
3+
This repo holds the common components shared between this org's hosted MkDocs documentation projects.
4+
5+
The idea is that this repo will be kept up-to-date with global config, and each child repo will use a provided script to download the latest commit from this repo, and have its "local" MkDocs config point to the downloaded files from this repo.
6+
7+
In all cases, each child repo will be able to *override* config items here as needed.

docs/_global/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
markdown_grid_tables
2+
mkdocs
3+
mkdocs-git-revision-date-localized-plugin
4+
mkdocs-material
5+
mkdocs-print-site-plugin

0 commit comments

Comments
 (0)