Skip to content

Commit 579c33a

Browse files
fix: build site from zensical config
1 parent 525164d commit 579c33a

1 file changed

Lines changed: 59 additions & 23 deletions

File tree

.github/workflows/Build-Site.yml

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ jobs:
3939
name: docs
4040
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
4141

42-
- name: Install mkdocs-material
42+
- name: Install site dependencies
4343
shell: pwsh
4444
run: |
4545
pip install mkdocs-material
4646
pip install mkdocs-git-authors-plugin
4747
pip install mkdocs-git-revision-date-localized-plugin
4848
pip install mkdocs-git-committers-plugin-2
49+
pip install pyyaml
50+
pip install tomli
4951
5052
- name: Structure site
5153
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
@@ -111,36 +113,70 @@ jobs:
111113
Write-Host "Readme Target Path: $readmeTargetPath"
112114
}
113115
114-
LogGroup 'Build docs - Create mkdocs.yml' {
116+
LogGroup 'Build docs - Create mkdocs.yml from zensical.toml' {
115117
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
116-
$possiblePaths = @(
117-
'.github/mkdocs.yml',
118-
'docs/mkdocs.yml',
119-
'mkdocs.yml'
120-
)
121-
122-
$mkdocsSourcePath = $null
123-
foreach ($path in $possiblePaths) {
124-
$candidatePath = Join-Path -Path $rootPath -ChildPath $path
125-
if (Test-Path -Path $candidatePath) {
126-
$mkdocsSourcePath = $candidatePath
127-
break
128-
}
129-
}
118+
$zensicalSourcePath = Join-Path -Path $rootPath -ChildPath '.github/zensical.toml'
130119
131-
if (-not $mkdocsSourcePath) {
132-
throw "Mkdocs source file not found in any of the expected locations: $($possiblePaths -join ', ')"
120+
if (-not (Test-Path -Path $zensicalSourcePath)) {
121+
throw "Zensical source file not found at expected location: .github/zensical.toml"
133122
}
134123
135124
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
136125
137-
Write-Host "Mkdocs Source Path: $mkdocsSourcePath"
126+
Write-Host "Zensical Source Path: $zensicalSourcePath"
138127
Write-Host "Mkdocs Target Path: $mkdocsTargetPath"
139128
140-
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
141-
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
142-
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
143-
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
129+
$zensicalContent = Get-Content -Path $zensicalSourcePath -Raw
130+
$zensicalContent = $zensicalContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
131+
$zensicalContent = $zensicalContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
132+
133+
$zensicalInputPath = Join-Path -Path $SiteOutputPath -ChildPath 'zensical.toml'
134+
$zensicalContent | Set-Content -Path $zensicalInputPath -Force
135+
136+
python3 -c @'
137+
import pathlib
138+
139+
import yaml
140+
141+
try:
142+
import tomllib
143+
except ModuleNotFoundError:
144+
import tomli as tomllib
145+
146+
source_path = pathlib.Path('outputs/site/zensical.toml')
147+
target_path = pathlib.Path('outputs/site/mkdocs.yml')
148+
149+
with source_path.open('rb') as source_file:
150+
zensical = tomllib.load(source_file)
151+
152+
project = zensical.get('project', {})
153+
theme = dict(project.get('theme', {}))
154+
theme.pop('variant', None)
155+
theme = {'name': 'material', **theme}
156+
157+
markdown_extensions = []
158+
for name, value in project.get('markdown_extensions', {}).items():
159+
if value:
160+
markdown_extensions.append({name: value})
161+
else:
162+
markdown_extensions.append(name)
163+
164+
mkdocs = {
165+
'site_name': project.get('site_name'),
166+
'repo_name': project.get('repo_name'),
167+
'repo_url': project.get('repo_url'),
168+
'theme': theme,
169+
'plugins': project.get('plugins', ['search']),
170+
'markdown_extensions': markdown_extensions,
171+
}
172+
173+
if 'extra' in project:
174+
mkdocs['extra'] = project['extra']
175+
176+
with target_path.open('w', encoding='utf-8') as target_file:
177+
yaml.safe_dump(mkdocs, target_file, sort_keys=False, allow_unicode=True)
178+
'@
179+
144180
Show-FileContent -Path $mkdocsTargetPath
145181
}
146182

0 commit comments

Comments
 (0)