From 7889427f76af2c35672b72aa6449f78041bed1d1 Mon Sep 17 00:00:00 2001 From: Caleb Brose <{ID}+{username}@users.noreply.github.com> Date: Wed, 6 Jan 2021 17:36:50 -0800 Subject: [PATCH] Support custom headers --- README.md | 1 + action.ps1 | 19 +++++++++++++++++++ action.yml | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 91d60d7..445ce0c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Syncs markdown documentation files in a repo to its wiki | rootDocsFolder | Relative path within the repo to the root documentation folder | No, default is the repo's root | | 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 | | 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`) | +| useHeaderForWikiName | If set, inserts a header at the top of each wiki file with the given format
Supports the following format subsitutions:
- `{sourceFileLink}`: the absolute url to the source file in the repo | No, default will not add a header | ## How it works diff --git a/action.ps1 b/action.ps1 index 4f86ddf..5866a4d 100644 --- a/action.ps1 +++ b/action.ps1 @@ -14,6 +14,7 @@ $defaultBranch = Get-ActionInput defaultBranch $rootDocsFolder = Get-ActionInput rootDocsFolder $convertRootReadmeToHomePage = Get-ActionInput convertRootReadmeToHomePage $useHeaderForWikiName = Get-ActionInput useHeaderForWikiName +$customWikiFileHeaderFormat = Get-ActionInput customWikiFileHeaderFormat $repositoryName = $env:GITHUB_REPOSITORY $repositoryUrl = "https://github.com/$repositoryName" @@ -93,6 +94,11 @@ Function ProcessSourceFile() $content = $override.NewContent } + if ($customWikiFileHeaderFormat) + { + $content = AddCustomHeader $content + } + $outputPath = $wikiRepoPath + "/" + $outputFileName $content | Set-Content -Path $outputPath @@ -199,6 +205,19 @@ Function UpdateFileLinks() $content | % { $linkRegex.Replace($_, $evaluator) } } +Function AddCustomHeader() +{ + [cmdletbinding()] + param([string]$content, $file, [string[]]$directories) + + $header = $customWikiFileHeaderFormat + + $sourceFileLink = "$repositoryUrl/$($directories -join "/")/$($file.Name)" + $header = $header -replace "{sourceFileLink}", $sourceFileLink + + "$header`n`n$content" +} + Function ProcessWikiDirectory() { [cmdletbinding()] diff --git a/action.yml b/action.yml index d6587cb..a429f80 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,14 @@ inputs: required: false default: false + customWikiFileHeaderFormat: + description: | + If set, inserts a header at the top of each wiki file with the given format + Supports the following format subsitutions: + - {sourceFileLink}: the absolute url to the source file in the repo + required: false + default: + branding: color: purple icon: terminal