Skip to content

Commit

Permalink
Support custom headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Brose authored and Caleb Brose committed Jan 7, 2021
1 parent 959a716 commit 7889427
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 |

## How it works

Expand Down
19 changes: 19 additions & 0 deletions action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -93,6 +94,11 @@ Function ProcessSourceFile()
$content = $override.NewContent
}

if ($customWikiFileHeaderFormat)
{
$content = AddCustomHeader $content
}

$outputPath = $wikiRepoPath + "/" + $outputFileName

$content | Set-Content -Path $outputPath
Expand Down Expand Up @@ -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()]
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7889427

Please sign in to comment.