Skip to content

Commit

Permalink
Try make asciinema load faster
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Mar 15, 2024
1 parent 329eff8 commit 94dbeb6
Show file tree
Hide file tree
Showing 47 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
# Publish prerelease docs
Install-Module HelpOut -Scope CurrentUser -RequiredVersion 0.5 -Force
& .\PwshSpectreConsole.Docs\src\powershell\UpdateDocs.ps1 -NonInteractive
& .\PwshSpectreConsole.Docs\src\powershell\UpdateDocs.ps1 -NonInteractive -Branch "prerelease"
git config --global user.name 'Shaun Lawrie (via GitHub Actions)'
git config --global user.email '[email protected]'
git add PwshSpectreConsole.Docs/src/content || true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Get Started
---

import Asciinema from '../../../components/Asciinema.astro'
import readspectreselectionExample1 from '../../../assets/examples/readspectreselectionExample1.cast?url'
import readspectremultiselectionExample1 from '../../../assets/examples/readspectremultiselectionExample1.cast?url'

### Demo

Expand Down Expand Up @@ -34,7 +36,7 @@ Write-SpectreHost "Your chosen color is '$color'"
> Example of a user being prompted with a select list:
<Asciinema
src="/examples/readspectreselectionExample1.cast"
src={readspectreselectionExample1}
settings={{
loop: false,
poster: 'npt:0:0',
Expand All @@ -59,7 +61,7 @@ Write-SpectreHost "Your favourite fruits are $($chosenItems -join ', ')"
> Example of a user being prompted with a multi-select list:
<Asciinema
src="/examples/readspectremultiselectionExample1.cast"
src={readspectremultiselectionExample1}
settings={{
loop: false,
poster: 'npt:0:0',
Expand Down
5 changes: 3 additions & 2 deletions PwshSpectreConsole.Docs/src/powershell/Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ function Get-GitCommitDatesForHashFile {

$script:AsciiCastTemplate = @'
<Asciinema
src="CAST_URL"
src={CAST_NAME}
settings={{
loop: false,
preload: true,
poster: 'npt:0:0.5',
terminalLineHeight: 1.1,
theme: "spectre"
Expand All @@ -230,5 +231,5 @@ function Get-AsciiCastTemplate {
[string] $Name
)

return $script:AsciiCastTemplate -replace "CAST_URL", $Name
return $script:AsciiCastTemplate -replace "CAST_NAME", $Name
}
6 changes: 3 additions & 3 deletions PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if($IsLinux) {
$env:TEMP = "/tmp"
}
$outputPath = "$PSScriptRoot/../content/docs/reference/"
$asciiCastOutputPath = "$PSScriptRoot/../../public/examples/"
$asciiCastOutputPath = "$PSScriptRoot/../assets/examples/"
$stagingPath = "$env:TEMP/refs-staging"
if(Test-Path $stagingPath) {
Remove-Item $stagingPath -Force -Recurse
Expand Down Expand Up @@ -162,10 +162,10 @@ foreach ($doc in $docs) {

$castName = ($doc.Name -replace '.md$', '' -replace '-', '').ToLower() + "Example$example"
Set-Content -Path "$asciiCastOutputPath\$castName.cast" -Value $recording
$castUrl = "/examples/$castName.cast"
$imports += "import $castName from '../../../../assets/examples/$castName.cast?url'`n"

# Replace the code block with the ascii cast
$castTemplate = Get-AsciiCastTemplate -Name $castUrl
$castTemplate = Get-AsciiCastTemplate -Name $castName
$content = $content -replace "(?ms)> EXAMPLE $example.+?(``````.+?``````)", "> EXAMPLE $example`n`n`$1`n$castTemplate"
}
$content = $content -replace "### Description", "$imports`n### Description"
Expand Down

0 comments on commit 94dbeb6

Please sign in to comment.