diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-05-05 08:39:57 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-05-05 08:39:57 +0200 |
| commit | e21a3141ca659bf6140dc1350b4552b6ddddf357 (patch) | |
| tree | 4761c2a3d3741730d950672fda35ad4caefe207d /layouts | |
| parent | 1529a435c59cdc689572f76a1db52ba89918269a (diff) | |
| download | gohugo-theme-ed-e21a3141ca659bf6140dc1350b4552b6ddddf357.tar.gz | |
Add Highlight.js support
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/partials/custom-scripts.html | 5 | ||||
| -rw-r--r-- | layouts/partials/head.html | 5 | ||||
| -rw-r--r-- | layouts/partials/hljs.html | 15 | ||||
| -rw-r--r-- | layouts/partials/scripts.html | 1 | ||||
| -rw-r--r-- | layouts/partials/styles.html | 27 |
5 files changed, 43 insertions, 10 deletions
diff --git a/layouts/partials/custom-scripts.html b/layouts/partials/custom-scripts.html new file mode 100644 index 0000000..c275701 --- /dev/null +++ b/layouts/partials/custom-scripts.html @@ -0,0 +1,5 @@ +{{- /* Head custom scripts area start */ -}} +{{- /* A partial to be overwritten by the user. */ -}} +{{- /* Simply place a custom-scripts.html into your local /layouts/partials-directory. */ -}} +{{- /* Its content will appear before any scripts in <head>. */ -}} +{{- /* Head custom scripts area end */ -}} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 7d06d79..f11c57d 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -16,8 +16,9 @@ <meta name="author" content="{{ (partial "author.html" . ) }}"> {{ hugo.Generator }} - {{ partial "styles.html" . -}} - {{ partial "scripts.html" . -}} + {{- partial "styles.html" . }} + {{- partial "hljs.html" . }} + {{- partial "custom-scripts.html" . }} {{- /* Favicons */}} <link rel="icon" href="{{ site.Params.assets.favicon | default "favicon.ico" | relURL }}" sizes="any"><!-- 32×32 --> diff --git a/layouts/partials/hljs.html b/layouts/partials/hljs.html new file mode 100644 index 0000000..db01de9 --- /dev/null +++ b/layouts/partials/hljs.html @@ -0,0 +1,15 @@ +{{- /* Highlight.js */}} +{{- $isHLJSdisabled := (site.Params.assets.disable_highlight_js | default .Params.disable_highlight_js ) }} +{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }} + {{- if not site.Params.assets.disable_fingerprinting }} + {{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | minify | fingerprint }} + <script crossorigin="anonymous" src="{{ $highlight.RelPermalink }}" integrity="{{ $highlight.Data.Integrity }}"></script> + {{- else }} + {{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | minify }} + <script crossorigin="anonymous" src="{{ $highlight.RelPermalink }}"></script> + {{- end }} +{{- end }} + <script> + hljs.highlightAll(); + hljs.configure({ ignoreUnescapedHTML: true }); + </script> diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html deleted file mode 100644 index e6462a9..0000000 --- a/layouts/partials/scripts.html +++ /dev/null @@ -1 +0,0 @@ -{{/* For Users's overwrite */}} diff --git a/layouts/partials/styles.html b/layouts/partials/styles.html index f50dad5..af7c709 100644 --- a/layouts/partials/styles.html +++ b/layouts/partials/styles.html @@ -1,8 +1,21 @@ -{{- $sass := resources.Get "sass/style.scss" -}} +{{- /* Styles */}} +{{- $theme := resources.Get "sass/style.scss" | resources.ToCSS }} + +{{- /* include hljs' css if hljs is on */}} +{{- $isHLJSdisabled := (site.Params.assets.disable_highlight_js | default false) }} +{{- $hljs := (cond ($isHLJSdisabled) (" " | resources.FromString "assets/css/hljs-blank.css") (resources.Get "css/hljs/hljs-default.min.css")) }} + +{{- /* order is important */}} +{{- $core := (slice $theme $hljs) | resources.Concat "assets/css/core.css" }} +{{- $extended := (resources.Match "css/extended/*.css") | resources.Concat "assets/css/extended.css" }} + +{{- /* bundle all required css */}} +{{- /* Add extended css after theme style */ -}} +{{- $stylesheet := (slice $core $extended) | resources.Concat "assets/css/stylesheet.css" | minify }} + {{- if not site.Params.assets.disable_fingerprinting -}} -{{- $style := $sass | resources.ToCSS | minify | fingerprint -}} -<link rel="stylesheet" href="{{ $style.RelPermalink }}"> -{{- else -}} -{{- $style := $sass | resources.ToCSS | minify -}} -<link rel="stylesheet" href="{{ $style.RelPermalink }}"> -{{- end -}} + {{- $stylesheet := $stylesheet | fingerprint }} + {{ printf `<link crossorigin="anonymous" href="%s" integrity="%s" rel="preload stylesheet" as="style">` $stylesheet.RelPermalink $stylesheet.Data.Integrity | safeHTML }} +{{- else }} + <link crossorigin="anonymous" href="{{ $stylesheet.RelPermalink }}" rel="preload stylesheet" as="style"> +{{- end }} |
