From f1e26277bedad175343f5e63929cd150864df744 Mon Sep 17 00:00:00 2001 From: Tomy Hsieh Date: Mon, 8 May 2023 16:37:59 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Asciinema=20shortcode=20(#4?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/_default/params.toml | 2 + .../ais3-2020-pre-exam-write-up/index.en.md | 2 +- .../index.zh-tw.md | 2 +- layouts/shortcodes/asciinema.html | 45 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 layouts/shortcodes/asciinema.html diff --git a/config/_default/params.toml b/config/_default/params.toml index 26facfc..13962b5 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -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 diff --git a/content/posts/ais3-2020-pre-exam-write-up/index.en.md b/content/posts/ais3-2020-pre-exam-write-up/index.en.md index 40ee231..192cb1d 100644 --- a/content/posts/ais3-2020-pre-exam-write-up/index.en.md +++ b/content/posts/ais3-2020-pre-exam-write-up/index.en.md @@ -195,7 +195,7 @@ I'm using Keyboard Maestro on Mac, but I believe any QuickMacro on any platform It'll work like this: - +{{< asciinema id="339381" >}} During this iteration, the corrrect letter is `i`, which is kind of hard to find the difference. diff --git a/content/posts/ais3-2020-pre-exam-write-up/index.zh-tw.md b/content/posts/ais3-2020-pre-exam-write-up/index.zh-tw.md index 9512090..551848c 100644 --- a/content/posts/ais3-2020-pre-exam-write-up/index.zh-tw.md +++ b/content/posts/ais3-2020-pre-exam-write-up/index.zh-tw.md @@ -193,7 +193,7 @@ print(s.recv(1024).strip().decode()) 啊執行起來就會像下面這樣 - +{{< asciinema id="339381" >}} 這一次 Iteration 的答案是`i`哦,你猜對了嗎:) diff --git a/layouts/shortcodes/asciinema.html b/layouts/shortcodes/asciinema.html new file mode 100644 index 0000000..935c0df --- /dev/null +++ b/layouts/shortcodes/asciinema.html @@ -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 -}} + + {{- if $caption -}} +
{{ $caption | markdownify }}
+ {{- 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 -}}