Skip to content

Commit 7889427

Browse files
Caleb BroseCaleb Brose
Caleb Brose
authored and
Caleb Brose
committed
Support custom headers
1 parent 959a716 commit 7889427

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Syncs markdown documentation files in a repo to its wiki
1010
| rootDocsFolder | Relative path within the repo to the root documentation folder | No, default is the repo's root |
1111
| convertRootReadmeToHomePage | If true, the `README.md` file at the root of the repo will be renamed to `Home.md` in the wiki so that it is used as the wiki homepage | No, default is false |
1212
| useHeaderForWikiName | If true, will extract the top-line header (denoted by a single `#`) and use that as the wiki page's name. Note: if this results in a name collision the sync will fail | No, default is false and wiki names will be the relative path to the file with `/` converted to `__` (e.g. `path/to/doc.md` becomes `path__to_doc.md`) |
13+
| useHeaderForWikiName | If set, inserts a header at the top of each wiki file with the given format<br/>Supports the following format subsitutions:<br/>- `{sourceFileLink}`: the absolute url to the source file in the repo | No, default will not add a header |
1314

1415
## How it works
1516

action.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $defaultBranch = Get-ActionInput defaultBranch
1414
$rootDocsFolder = Get-ActionInput rootDocsFolder
1515
$convertRootReadmeToHomePage = Get-ActionInput convertRootReadmeToHomePage
1616
$useHeaderForWikiName = Get-ActionInput useHeaderForWikiName
17+
$customWikiFileHeaderFormat = Get-ActionInput customWikiFileHeaderFormat
1718

1819
$repositoryName = $env:GITHUB_REPOSITORY
1920
$repositoryUrl = "https://github.com/$repositoryName"
@@ -93,6 +94,11 @@ Function ProcessSourceFile()
9394
$content = $override.NewContent
9495
}
9596

97+
if ($customWikiFileHeaderFormat)
98+
{
99+
$content = AddCustomHeader $content
100+
}
101+
96102
$outputPath = $wikiRepoPath + "/" + $outputFileName
97103

98104
$content | Set-Content -Path $outputPath
@@ -199,6 +205,19 @@ Function UpdateFileLinks()
199205
$content | % { $linkRegex.Replace($_, $evaluator) }
200206
}
201207

208+
Function AddCustomHeader()
209+
{
210+
[cmdletbinding()]
211+
param([string]$content, $file, [string[]]$directories)
212+
213+
$header = $customWikiFileHeaderFormat
214+
215+
$sourceFileLink = "$repositoryUrl/$($directories -join "/")/$($file.Name)"
216+
$header = $header -replace "{sourceFileLink}", $sourceFileLink
217+
218+
"$header`n`n$content"
219+
}
220+
202221
Function ProcessWikiDirectory()
203222
{
204223
[cmdletbinding()]

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ inputs:
2626
required: false
2727
default: false
2828

29+
customWikiFileHeaderFormat:
30+
description: |
31+
If set, inserts a header at the top of each wiki file with the given format
32+
Supports the following format subsitutions:
33+
- {sourceFileLink}: the absolute url to the source file in the repo
34+
required: false
35+
default:
36+
2937
branding:
3038
color: purple
3139
icon: terminal

0 commit comments

Comments
 (0)