Skip to content

Commit

Permalink
Replace font names in README.md
Browse files Browse the repository at this point in the history
Replacements in an au_SearchReplace function is applied to each single lines.
Font names in README is multiline, therefore we replace README in an
au_BeforeUpdate() function.

ref. majkinetor/au#163
  • Loading branch information
kai2nenobu committed Aug 13, 2022
1 parent 3fba185 commit 8ae2376
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions font-hackgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ This directory contains sources of two packages, [![font-hackgen][font-hackgen_v

This package installs following fonts on system font folder (`C:\Windows\Fonts`).

<!-- Begin font names -->
- `HackGen`
- `HackGen Console`
- `HackGen35`
- `HackGen35 Console`
<!-- End font names -->

If the installation or update of this package fails, it may be for the following reasons.

Expand All @@ -29,10 +31,12 @@ Remove the HackGen or close any applications that use HackGen before trying to i

このパッケージは以下のフォントをシステム全体にインストールします。(`C:\Windows\Fonts`にインストールされます)

<!-- Begin font names -->
- `HackGen`
- `HackGen Console`
- `HackGen35`
- `HackGen35 Console`
<!-- End font names -->

このパッケージのインストールやアップデートに失敗する場合、以下の理由が考えられます。

Expand Down
22 changes: 13 additions & 9 deletions font-hackgen/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ function global:au_GetLatest {
}

function global:au_SearchReplace {
# Replacement for font names
if ($Latest.Stream -eq 'nerd') {
$fontReplacement = 'HackGen${1}Nerd${3}'
} else {
$fontReplacement = 'HackGen${1}${3}'
}
@{
".\font-hackgen.nuspec" = @{
'(/HackGen/blob/)[^/<]*' = "`${1}$($Latest.Tag)"
Expand All @@ -58,10 +52,20 @@ function global:au_SearchReplace {
".\tools\ChocolateyBeforeModify.ps1" = @{
"'common-(.*)\.ps1'" = "'common-$($Latest.PackageName).ps1'"
}
".\README.md" = @{
'`HackGen(35)?(Nerd)?( Console)?`' = '`' + $fontReplacement + '`'
}
}
}

function global:au_BeforeUpdate() {
# Load font names from a common file
. "tools/common-$($Latest.PackageName).ps1"
$fontNames = ($hackgenFonts.Values | ForEach-Object { "- ``$_``" }) -join "`n"
$regex = '(<!-- Begin font names -->)([^<]*)(<!-- End font names -->)'
$fontNamesReplacement = '$1' + "`n" + $fontNames + "`n" + '$3'
# Replace font names in README.md
$readme = Get-Content -Raw -Path README.md -Encoding UTF8
$readme | % { $_ -replace $regex,$fontNamesReplacement } `
| % { [Text.Encoding]::UTF8.GetBytes($_) } `
| Set-Content -Encoding Byte -Path README.md
}

Update-Package

0 comments on commit 8ae2376

Please sign in to comment.