|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Project License |
| 4 | +.DESCRIPTION |
| 5 | + The License for the project |
| 6 | +.NOTES |
| 7 | + The License for the project |
| 8 | +#> |
| 9 | +param( |
| 10 | +# We can provide the repository url by hard-coding it, |
| 11 | +# or it can be provided in site or page metadata. |
| 12 | +# If we do not provide either, we can also look at the `$gitHubEvent` |
| 13 | +[uri] |
| 14 | +$RepositoryUrl, |
| 15 | + |
| 16 | +# We can provide the changelog path by hard-coding it, or it can provided in site or page metadata. |
| 17 | +[string] |
| 18 | +$LicensePath = '../LICENSE.txt' |
| 19 | +) |
| 20 | + |
| 21 | +# Push into this location, in case we are building this file interactively. |
| 22 | +if ($PSScriptRoot) { Push-Location $PSScriptRoot} |
| 23 | + |
| 24 | +if (-not $RepositoryUrl) { |
| 25 | + if ($gitHubEvent.repository.html_url) { |
| 26 | + $repositoryUrl = $gitHubEvent.repository.html_url |
| 27 | + } else { |
| 28 | + return |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +# Get my own help |
| 33 | +$myHelp = Get-Help $MyInvocation.MyCommand.ScriptBlock.File |
| 34 | +if ($myHelp) { |
| 35 | + # If we have page metadata |
| 36 | + if ($page -is [Collections.IDictionary]) { |
| 37 | + # Replace 'Project' in the title with the url, to make the title and description more helpful |
| 38 | + $page.Title = $myHelp.SYNOPSIS -replace 'Project', { |
| 39 | + $RepositoryUrl.Segments[-1] -replace '/' |
| 40 | + } |
| 41 | + $page.Description = $myHelp.Description.text -join [Environment]::NewLine -replace 'The Project', { |
| 42 | + $RepositoryUrl.Segments[-1] -replace '/' |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + # If we have notes, replace the project with our name |
| 47 | + $myNotes = $myHelp.alertSet.alert.text -join [Environment]::NewLine -replace 'The Project', { |
| 48 | + $RepositoryUrl.Segments[-1] -replace '/' |
| 49 | + } |
| 50 | + if ($myNotes) { |
| 51 | + # and convert our notes from markdown. |
| 52 | + (ConvertFrom-Markdown -InputObject $myNotes).Html |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +# Break up the space a bit with horizontal rules. |
| 57 | + |
| 58 | +"<hr/>" |
| 59 | +# Display source for this page |
| 60 | +"<details>" |
| 61 | + "<summary>View Source</summary>" |
| 62 | + "<pre>" |
| 63 | + "<code class='language-PowerShell'>" |
| 64 | + [Web.HttpUtility]::HtmlEncode($MyInvocation.MyCommand.ScriptBlock) |
| 65 | + "</code>" |
| 66 | + "</pre>" |
| 67 | +"</details>" |
| 68 | + |
| 69 | +# Break up the space a bit with horizontal rules. |
| 70 | +"<hr/>" |
| 71 | + |
| 72 | +# Get our license |
| 73 | +"<pre class='license'>" |
| 74 | +[Web.HttpUtility]::HtmlEncode( |
| 75 | + (Get-ChildItem -Path $LicensePath | Get-Content -Raw) |
| 76 | +) |
| 77 | +"</pre>" |
| 78 | + |
| 79 | +# If we pushed into the location, pop back out. |
| 80 | +if ($PSScriptRoot) { Pop-Location} |
| 81 | + |
| 82 | +# We're done! |
0 commit comments