-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathexample-bookshop.html
More file actions
86 lines (79 loc) · 3.71 KB
/
example-bookshop.html
File metadata and controls
86 lines (79 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{{/*
Copyright © 2022 - 2025 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
This source code adapts the original embedded shortcode as maintained by the The Bootstrap Authors. It introduces
the following modifications:
- Added validation of shortcode arguments
- Modified the layout
- Added support to render bookshop components
The original source code is available on:
Source: https://github.com/twbs/bootstrap/blob/main/site/layouts/shortcodes/example.html
Copyright (c) 2011-2023 The Bootstrap Authors. Licensed under The MIT License (MIT).
*/}}
{{ $error := false -}}
{{/* Initialize arguments */}}
{{- $args := partial "utilities/InitArgs.html" (dict "structure" "example" "args" .Params "named" .IsNamedParams "group" "shortcode") -}}
{{- if or $args.err $args.warnmsg -}}
{{- partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "shortcodes/example-bookshop.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"file" page.File
"position" .Position
)}}
{{ $error = $args.err }}
{{- end -}}
{{/* Initialize local arguments */}}
{{- $lang := $args.lang -}}
{{- $showPreview := or $args.showPreview $args.show_preview }}
{{- $showMarkup := or $args.showMarkup $args.show_markup }}
{{- if eq $lang "hugo" }}{{ $lang = "markdown" }}{{ end -}}
{{- $content := .InnerDeindent -}}
{{- $data := "" -}}
{{- $partial := "" -}}
{{- $type := "shortcode" }}
{{- if eq $lang "hugo" }}{{ $lang = "markdown" }}{{ end -}}
{{- if eq $lang "bookshop" }}
{{ $type = "bookshop" }}
{{ $frontmatter := slice "yml" "yaml" "toml" "json" }}
{{ $inputRE := findRESubmatch `\x60\x60\x60(?:yml|yaml|json|toml)(\r\n|\r|\n)([\s\S]*?)\x60\x60\x60` $content 1 }}
{{ if and $inputRE (eq (len (index $inputRE 0)) 3) }}
{{ $lang = (trim (index (split $content "\n") 2) "\x60") | default "yml" }}
{{ $content = index (index $inputRE 0) 2 }}
{{ $data = index (unmarshal $content) 0 }}
{{ $component_name := (index $data "_bookshop_name") }}
{{ if not $component_name }}
{{ errorf "Expected '_bookshop_name': %s" .Position -}}
{{ $error = true }}
{{ else }}
{{ $partial = partial "_bookshop/helpers/component.html" (slice $component_name $data "p-1 p-md-4" "m-n1 m-md-n4") }}
{{ end }}
{{ else }}
{{ errorf "Expected frontmatter codeblock as input: %s" .Position -}}
{{ $error = true }}
{{ end }}
{{ end -}}
{{/* Main code */}}
{{ if not $error }}
<div class="rounded border mb-3">
{{- if eq $showPreview true -}}
<div {{ with $args.id }}id="{{ . }}"{{ end }} class="rounded-top p-3 {{ with $args.class }} {{ . }}{{ end }}">
{{ if eq $type "bookshop" }}
{{ $partial | safeHTML }}
{{ else }}
{{- $content | .Page.RenderString | safeHTML -}}
{{ end }}
</div>
{{- end -}}
{{- if eq $showMarkup true -}}
<div class="d-flex align-items-center ps-3 pe-3 py-1{{ if $showPreview }} border-top{{ else }} rounded-top{{ end }} border-bottom syntax-highlight">
<small class="font-monospace text-body text-uppercase">{{ $lang }}</small>
</div>
<div class="rounded-bottom syntax-highlight border-none">
{{- highlight (trim $content "\r\n") $lang "" | safeHTML -}}
</div>
{{- end -}}
</div>
{{ end }}