refactor asciinema

This commit is contained in:
Balakrishnan Balasubramanian 2025-05-26 17:48:23 -04:00
parent 55ab032dbf
commit 595325b5ad
4 changed files with 15 additions and 11 deletions

View File

@ -5,18 +5,14 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' data: ;{{ if .Params.asciinema }}script-src 'self' 'unsafe-inline' 'unsafe-eval';{{ end }}"> <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' data: {{ partial "asciinema/csp" . }} ;">
<link rel="alternate" type="application/rss+xml" href="/posts/index.xml"> <link rel="alternate" type="application/rss+xml" href="/posts/index.xml">
<!-- Diable favicon requests: https://stackoverflow.com/a/13416784 --> <!-- Diable favicon requests: https://stackoverflow.com/a/13416784 -->
<link rel="icon" href="data:;base64,iVBORw0KGgo="> <link rel="icon" href="data:;base64,iVBORw0KGgo=">
{{ if .Params.asciinema }} {{ partial "asciinema/head" . }}
{{ with resources.Get "vendor/asciinema/asciinema-player.css" | minify | fingerprint }} {{- if isset .Site.Params "onionlocation" -}}
<link rel="stylesheet" type="text/css" href="{{ .RelPermalink }}" />
{{ end }}
{{ end }}
{{- if isset .Site.Params "onionlocation" }}
<meta http-equiv="onion-location" content="{{ urls.JoinPath .Site.Params.OnionLocation .RelPermalink }}"> <meta http-equiv="onion-location" content="{{ urls.JoinPath .Site.Params.OnionLocation .RelPermalink }}">
{{- end }} {{- end -}}
<title>{{ block "title" . }}{{ .Site.Title }}{{ end }}</title> <title>{{ block "title" . }}{{ .Site.Title }}{{ end }}</title>
<link rel="stylesheet" href="{{ "css/styles.css" | relURL }}"> <link rel="stylesheet" href="{{ "css/styles.css" | relURL }}">
<link id="theme_css" rel="stylesheet" href="{{ "css/themes" | relURL }}/{{ .Site.Params.ThemeStyle | default $themeStyleDefault }}"> <link id="theme_css" rel="stylesheet" href="{{ "css/themes" | relURL }}/{{ .Site.Params.ThemeStyle | default $themeStyleDefault }}">

View File

@ -0,0 +1,3 @@
{{- /* This renders as &#39;unsafe-eval&#39; . This seems to be work fine
though. TODO: how to render as proper single quotes? */ -}}
{{- if .Params.asciinema -}}'unsafe-eval'{{- end -}}

View File

@ -0,0 +1,8 @@
{{ if .Params.asciinema }}
{{ with resources.Get "vendor/asciinema/asciinema-player.css" | minify | fingerprint }}
<link rel="stylesheet" type="text/css" href="{{ .RelPermalink }}" />
{{ end }}
{{ with resources.Get "vendor/asciinema/asciinema-player.min.js" | fingerprint }}
<script src="{{ .RelPermalink }}"></script>
{{ end }}
{{ end }}

View File

@ -1,7 +1,4 @@
<div id='{{ .Get "key" }}'></div> <div id='{{ .Get "key" }}'></div>
{{ with resources.Get "vendor/asciinema/asciinema-player.min.js" | fingerprint }}
<script src="{{ .RelPermalink }}"></script>
{{ end }}
<script> <script>
AsciinemaPlayer.create('casts/{{ .Get "key" }}.cast', document.getElementById('{{ .Get "key" }}'), { AsciinemaPlayer.create('casts/{{ .Get "key" }}.cast', document.getElementById('{{ .Get "key" }}'), {
{{ if .Get "cols" }}cols: "{{ .Get "cols" }}",{{ end }} {{ if .Get "cols" }}cols: "{{ .Get "cols" }}",{{ end }}