Skip to content

Commit 0287cee

Browse files
fix: build site from zensical config
1 parent 525164d commit 0287cee

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

.github/workflows/Build-Site.yml

Lines changed: 17 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,28 @@ 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 "import pathlib, yaml;`ntry:`n import tomllib`nexcept ModuleNotFoundError:`n import tomli as tomllib`nsource_path = pathlib.Path('outputs/site/zensical.toml'); target_path = pathlib.Path('outputs/site/mkdocs.yml')`nwith source_path.open('rb') as source_file:`n zensical = tomllib.load(source_file)`nproject = zensical.get('project', {}); theme = dict(project.get('theme', {})); theme.pop('variant', None); theme = {'name': 'material', **theme}`nmarkdown_extensions = [{name: value} if value else name for name, value in project.get('markdown_extensions', {}).items()]`nmkdocs = {'site_name': project.get('site_name'), 'repo_name': project.get('repo_name'), 'repo_url': project.get('repo_url'), 'theme': theme, 'plugins': project.get('plugins', ['search']), 'markdown_extensions': markdown_extensions}`nif 'extra' in project:`n mkdocs['extra'] = project['extra']`nwith target_path.open('w', encoding='utf-8') as target_file:`n yaml.safe_dump(mkdocs, target_file, sort_keys=False, allow_unicode=True)"
137+
144138
Show-FileContent -Path $mkdocsTargetPath
145139
}
146140

0 commit comments

Comments
 (0)