Skip to content

Commit

Permalink
✨ feat: Asciinema shortcode (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomy0000000 committed May 8, 2023
1 parent 4deb13c commit f1e2627
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ mainSections = ["posts"]
[privacy.dailymotion]
disable = false
playerId = "xc41k" # https://www.dailymotion.com/partner/x2r8l7z/embed/players/configurator/xc41k
[privacy.asciinema]
disable = false
2 changes: 1 addition & 1 deletion content/posts/ais3-2020-pre-exam-write-up/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ I'm using Keyboard Maestro on Mac, but I believe any QuickMacro on any platform

It'll work like this:

<script src="https://asciinema.org/a/339381.js" id="asciicast-339381" async></script>
{{< asciinema id="339381" >}}

During this iteration, the corrrect letter is `i`, which is kind of hard to find the difference.

Expand Down
2 changes: 1 addition & 1 deletion content/posts/ais3-2020-pre-exam-write-up/index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ print(s.recv(1024).strip().decode())

啊執行起來就會像下面這樣

<script src="https://asciinema.org/a/339381.js" id="asciicast-339381" async></script>
{{< asciinema id="339381" >}}

這一次 Iteration 的答案是`i`哦,你猜對了嗎:)

Expand Down
45 changes: 45 additions & 0 deletions layouts/shortcodes/asciinema.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{/* https://asciinema.org/docs/embedding */}}
{{/* Ideally .Page.Site.Config.Privacy.Asciinema */}}
{{- $pc := .Page.Site.Params.privacy.asciinema -}}
{{- if not $pc.Disable -}}
{{- if .IsNamedParams -}}
{{- $id := .Get "id" -}}
{{- $startAt := (default 0 (.Get "startAt")) -}}
{{- $autoplay := (default false (.Get "autoplay")) -}}
{{- $preload := (default true (.Get "preload")) -}}
{{- $loop := (default false (.Get "loop")) -}}
{{- $speed := (default 1 (.Get "speed")) -}}
{{- $idleTimeLimit := .Get "idleTimeLimit" -}}
{{- $theme := .Get "theme" -}}
{{- $cols := .Get "cols" -}}
{{- $rows := .Get "rows" -}}
{{- $caption := .Get "caption" }}
{{- if $id -}}
<script
src="https://asciinema.org/a/{{ $id }}.js"
id="asciicast-{{ $id }}"
data-startAt="{{ $startAt }}"
data-autoplay="{{ $autoplay }}"
data-preload="{{ $preload }}"
data-loop="{{ $loop }}"
data-speed="{{ $speed }}"
{{ if $idleTimeLimit }}data-idleTimeLimit="{{ $idleTimeLimit }}"{{ end }}
{{ if $theme }}data-theme="{{ $theme }}"{{ end }}
{{ if $cols }}data-cols="{{ $cols }}"{{ end }}
{{ if $rows }}data-rows="{{ $rows }}"{{ end }}
async
></script>
{{- if $caption -}}
<figcaption class="text-center">{{ $caption | markdownify }}</figcaption>
{{- end -}}
{{- else -}}
{{- template "__asciinema_error" . -}}
{{- end -}}
{{- else -}}
{{- template "__asciinema_error" . -}}
{{- end -}}
{{- end -}}

{{- define "__asciinema_error" -}}
{{- errorf "The %q shortcode requires one named parameters: id. See %s" .Name .Position -}}
{{- end -}}

0 comments on commit f1e2627

Please sign in to comment.