2022-2023, I used Powershell to generate and upload to SourceHut Pages

Table of Contents

1. How last iteration looked

param (
    [Parameter(Position = 0)]
    [ScriptBlock]$ScriptBlock = { }
)

$TheContentJob = & { $TempFile = New-TemporaryFile
Write-Information "Temporary file name '$TempFile'. " -InformationAction
Continue
& { Import-Module `
"C:\Users\Mika Feiler\$(
)\source\repos\DotnetTarGzipper\$(
)\bin\Release\net7.0\DotnetTarGzipper.dll"

$GemCap = $env:GemCap

Push-Location
Set-Location $GemCap
& 'C:\Program Files\Git\bin\bash.exe' `
-c 'date -d "$(grep "^## " tinylog.gmi | cut -c 4- | head -1)" \
+"# Mika Feiler%n=> tinylog.gmi %F Tinylog" > gemfeed-tinylog.gmi'
Pop-Location

Get-ChildItem $GemCap -File -Recurse -Name |
Where-Object { $_ -NotMatch "^(.*[\\\/])?\..*" } |
ForEach-Object { $_ -replace '\\', '/' } |
New-Tar (Resolve-Path $GemCap) |
Compress-Gzip |
Set-Content -Path $TempFile -AsByteStream

Write-Information "Finished creating archive. " -InformationAction Continue
} 1>$null
return $TempFile
} &

& ScriptBlock &

function Get-SrHtToken {
    $SrHtTokenKey = "SrHtToken_g.mikf.pl"
    $SrHtToken = Get-Secret $SrHtTokenKey -ErrorVariable NoSrhtToken
    if($NoSrhtToken.Exception -Is `
        [System.Management.Automation.ItemNotFoundException]) {
        Set-Secret $SrHtTokenKey ($SrHtToken = `
        Read-Host -AsSecureString -Prompt "Enter the token")
    }
    $SrHtToken
}
$TempFile = Get-ChildItem -Path (Wait-Job $TheContentJob | Receive-Job)
Invoke-WebRequest -Method Post `
-Uri "https://pages.sr.ht/publish/g.mikf.pl" `
-Authentication OAuth -Token (Get-SrHtToken) `
-Form @{
    protocol = "GEMINI"
    content = $TempFile
} `
-RetryIntervalSec 2 -MaximumRetryCount 3 |
ForEach-Object { Write-Host $_.RawContent }
Remove-Job $TheContentJob
Write-Information -InformationAction Continue "Actual:"
Get-FileHash -Algorithm SHA256 $TempFile | foreach-object { Write-Host
$_.Hash.ToLower() }

1.1. how it differed from one-before-last iteration

diff --git a/./before_changes.ps1 b/./after_changes.ps1
index 7f7f27a..42dfb08 100644
--- a/./before_changes.ps1
+++ b/./after_changes.ps1
@@ -1,4 +1,11 @@
+param (
+    [Parameter(Position = 0)]
+    [ScriptBlock]$ScriptBlock = { }
+)
+
+$TheContentJob = & { $TempFile = New-TemporaryFile
+Write-Information "Temporary file name '$TempFile'. " -InformationAction
Continue
-Import-Module `
+& { Import-Module `
 "C:\Users\Mika Feiler\$(
 )\source\repos\DotnetTarGzipper\$(
 )\bin\Release\net7.0\DotnetTarGzipper.dll"
@@ -12,10 +19,6 @@ Set-Location $GemCap
 +"# Mika Feiler%n=> tinylog.gmi %F Tinylog" > gemfeed-tinylog.gmi'
 Pop-Location

-$TempFile = New-TemporaryFile
-Write-Host "Temporary file name '$TempFile'. "
-$SrHtTokenKey = "SrHtToken_g.mikf.pl"
-
 Get-ChildItem $GemCap -File -Recurse -Name |
 Where-Object { $_ -NotMatch "^(.*[\\\/])?\..*" } |
 ForEach-Object { $_ -replace '\\', '/' } |
@@ -23,9 +26,15 @@ New-Tar (Resolve-Path $GemCap) |
 Compress-Gzip |
 Set-Content -Path $TempFile -AsByteStream

-Write-Host "Finished creating archive. "
+Write-Information "Finished creating archive. " -InformationAction Continue
+} 1>$null
+return $TempFile
+} &
+
+& ScriptBlock &

 function Get-SrHtToken {
+    $SrHtTokenKey = "SrHtToken_g.mikf.pl"
     $SrHtToken = Get-Secret $SrHtTokenKey -ErrorVariable NoSrhtToken
     if($NoSrhtToken.Exception -Is `
         [System.Management.Automation.ItemNotFoundException]) {
@@ -34,12 +43,16 @@ function Get-SrHtToken {
     }
     $SrHtToken
 }
+$TempFile = Get-ChildItem -Path (Wait-Job $TheContentJob | Receive-Job)
 Invoke-WebRequest -Method Post `
 -Uri "https://pages.sr.ht/publish/g.mikf.pl" `
 -Authentication OAuth -Token (Get-SrHtToken) `
 -Form @{
     protocol = "GEMINI"
-    content = Get-ChildItem $TempFile
+    content = $TempFile
 } `
 -RetryIntervalSec 2 -MaximumRetryCount 3 |
 ForEach-Object { Write-Host $_.RawContent }
+Remove-Job $TheContentJob
+Write-Information -InformationAction Continue "Actual:"
+Get-FileHash -Algorithm SHA256 $TempFile | foreach-object { Write-Host
$_.Hash.ToLower() }

1.2. how one-before-last iteration looked like

Import-Module `
"C:\Users\Mika Feiler\$(
)\source\repos\DotnetTarGzipper\$(
)\bin\Release\net7.0\DotnetTarGzipper.dll"

$GemCap = $env:GemCap

Push-Location
Set-Location $GemCap
& 'C:\Program Files\Git\bin\bash.exe' `
-c 'date -d "$(grep "^## " tinylog.gmi | cut -c 4- | head -1)" \
+"# Mika Feiler%n=> tinylog.gmi %F Tinylog" > gemfeed-tinylog.gmi'
Pop-Location

$TempFile = New-TemporaryFile
Write-Host "Temporary file name '$TempFile'. "
$SrHtTokenKey = "SrHtToken_g.mikf.pl"

Get-ChildItem $GemCap -File -Recurse -Name |
Where-Object { $_ -NotMatch "^(.*[\\\/])?\..*" } |
ForEach-Object { $_ -replace '\\', '/' } |
New-Tar (Resolve-Path $GemCap) |
Compress-Gzip |
Set-Content -Path $TempFile -AsByteStream

Write-Host "Finished creating archive. "

function Get-SrHtToken {
    $SrHtToken = Get-Secret $SrHtTokenKey -ErrorVariable NoSrhtToken
    if($NoSrhtToken.Exception -Is `
        [System.Management.Automation.ItemNotFoundException]) {
        Set-Secret $SrHtTokenKey ($SrHtToken = `
        Read-Host -AsSecureString -Prompt "Enter the token")
    }
    $SrHtToken
}
Invoke-WebRequest -Method Post `
-Uri "https://pages.sr.ht/publish/g.mikf.pl" `
-Authentication OAuth -Token (Get-SrHtToken) `
-Form @{
    protocol = "GEMINI"
    content = Get-ChildItem $TempFile
} `
-RetryIntervalSec 2 -MaximumRetryCount 3 |
ForEach-Object { Write-Host $_.RawContent }

1.2.1. its output

Temporary file name 'C:\Users\Mika Feiler\AppData\Local\Temp\tmp7B90.tmp'.
Finished creating archive.
HTTP/1.1 200 OK
Date: Tue, 20 Dec 2022 19:04:25 GMT
Content-Length: 65
Content-Type: text/plain; charset=utf-8

8c55789c139f9c386c3a00565b8f22448355cc684a549f1fcad8348517f0e7b3
with sometimes the
Finished creating archive.
Vault SecretStore requires a password.
Enter password:
in between, except on first run when it's
Get-Secret: C:\Users\Mika Feiler\thingie_gem.ps1:29
Line |
  29 |      $SrHtToken = Get-Secret $SrHtTokenKey -ErrorVariable NoSrhtToken
     |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The secret SrHtToken_g.mikf.pl was not found.
Enter the token: ********************************************************************************************

1.2.2. Usage prerequisites

  • path to gemini capsule repository directory as GemCap environment variable
  • Register-SecretVault -ModuleName Microsoft.Powershell.SecretStore -DefaultVault
  • compiled New-Tar and Compress-Gzip cmdlets I wrote for the purpose