From c1f15c2162a30d020f66e200be366905bfbe3b25 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 11 Jul 2022 14:37:17 +0200 Subject: [PATCH] feat: add new boxes shortcode (#274) --- .../content/posts/advanced/shortcodes.md | 37 ++++++++++++++++++ layouts/shortcodes/box.html | 19 ++++++++++ layouts/shortcodes/boxes.html | 25 ++++++++++++ src/sass/_shortcodes.scss | 38 +++++++++++++++++++ src/sass/_utils.scss | 5 +++ 5 files changed, 124 insertions(+) create mode 100644 layouts/shortcodes/box.html create mode 100644 layouts/shortcodes/boxes.html diff --git a/exampleSite/content/posts/advanced/shortcodes.md b/exampleSite/content/posts/advanced/shortcodes.md index 76181bf..54d23f2 100644 --- a/exampleSite/content/posts/advanced/shortcodes.md +++ b/exampleSite/content/posts/advanced/shortcodes.md @@ -303,6 +303,43 @@ prompts feud gait, quid exercise emeritus bis e. In pro quints consequent. {{< /tab >}} {{< /tabs >}} +## Boxes + +Boxes can be used to create a simple grid. + +### Attributes + +| Name | Description | default | +| ---------------- | ----------------------------------------------------------------------------------- | --------- | +| size | size of each box (regular\|large) | regular | +| icon (optional) | title bar icon, need to be an icon from an [SVG sprite](/posts/features/icon-sets/) | undefined | +| title (optional) | title bar text | undefined | + +### Usage + + +```tpl +{{}} +{{}}mail@example.com{{}} +{{}}@john:example.com{{}} +{{}}john@example.com{{}} +{{}}You can also find us on the Fediverse.{{}} +{{}} +``` + +### Example + + + +{{< boxes "contact" >}} +{{< box size=large title=E-Mail icon=gblog_email >}}mail@example.com{{< /box >}} +{{< box size=large title=Matrix icon=gblog_matrix >}}@john:example.com{{< /box >}} +{{< box size=large title=XMPP icon=gblog_xmpp >}}john@example.com{{< /box >}} +{{< box size=large title=Others >}}You can also find us on the Fediverse.{{< /box >}} +{{< /boxes >}} + + + ## Mermaid [Mermaid](https://mermaidjs.github.io/) is library for generating SVG charts and diagrams from text. diff --git a/layouts/shortcodes/box.html b/layouts/shortcodes/box.html new file mode 100644 index 0000000..7b48c4c --- /dev/null +++ b/layouts/shortcodes/box.html @@ -0,0 +1,19 @@ +{{ if .Parent }} + {{- $group := printf "grid-%s" (.Parent.Get 0) }} + {{- $class := default "" (.Get "class") }} + {{- $size := default "regular" (.Get "size" | lower) }} + {{- $icon := default "" (.Get "icon") }} + {{- $title := default "" (.Get "title") }} + + {{- if not (in (slice "regular" "large") $size) }} + {{- $size = "regular" }} + {{- end }} + + {{ if not (.Parent.Scratch.Get $group) }} + {{ .Parent.Scratch.Set $group slice }} + {{ end }} + + {{ .Parent.Scratch.Add $group (dict "Class" $class "Size" $size "Icon" $icon "Title" $title "Content" .Inner) }} +{{ else }} + {{ errorf "%q: 'box' shortcode must be inside 'boxes' shortcode" .Page.Path }} +{{ end }} diff --git a/layouts/shortcodes/boxes.html b/layouts/shortcodes/boxes.html new file mode 100644 index 0000000..eead05c --- /dev/null +++ b/layouts/shortcodes/boxes.html @@ -0,0 +1,25 @@ +{{- if .Inner }}{{ end }} +{{- $id := .Get 0 }} +{{- $group := printf "grid-%s" $id }} + + +
+ {{- range $index, $box := .Scratch.Get $group }} +
+ {{ if or $box.Title $box.Icon }} +
+ {{- with $box.Icon }} + + {{- end }} + {{ with $box.Title }}{{ . }}{{ end }} +
+ {{ end }} +
+ {{ .Content | $.Page.RenderString }} +
+
+ {{- end }} +
diff --git a/src/sass/_shortcodes.scss b/src/sass/_shortcodes.scss index 4dc4e83..45c2bd6 100644 --- a/src/sass/_shortcodes.scss +++ b/src/sass/_shortcodes.scss @@ -132,6 +132,44 @@ } } +// {{< box >}} +.gblog-box { + background: var(--accent-color-lite); + border: $border-1 solid var(--accent-color); + border-radius: $border-radius; + text-align: center; + flex: 1 1 0; + + &--regular { + font-size: $font-size-base; + padding: $padding-4 $padding-8; + min-width: 8rem; + } + + &--large { + font-size: $font-size-20; + padding: $padding-8 $padding-16; + min-width: 12rem; + } + + &__title { + word-wrap: break-word; + overflow-wrap: anywhere; + gap: $padding-8; + + svg.gblog-icon { + width: 1.3rem; + height: 1.3rem; + min-width: 1.3rem; + } + } + + &__text { + margin: $padding-8 0; + font-size: $font-size-16; + } +} + // {{< hint >}} .gblog-hint { @each $name, $color in $hint-colors { diff --git a/src/sass/_utils.scss b/src/sass/_utils.scss index 4949516..bdd50b4 100644 --- a/src/sass/_utils.scss +++ b/src/sass/_utils.scss @@ -29,6 +29,11 @@ background: var(--accent-color-lite); } +.flex-gap { + flex-wrap: wrap; + gap: $padding-16; +} + .justify-start { justify-content: flex-start; }