From e7a3759f0ab2737afe69d04dddddccef7efbe36d Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Fri, 27 Oct 2023 21:57:55 +0200 Subject: [PATCH] feat: add properylist shortcode (#455) --- exampleSite/data/properties/demo.yaml | 32 ++++++++++++ .../properties/shortcode-propertylist.yaml | 15 ++++++ layouts/shortcodes/propertylist.html | 52 +++++++++++++++++++ src/sass/_shortcodes.scss | 43 ++++++++++++++- 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 exampleSite/data/properties/demo.yaml create mode 100644 exampleSite/data/properties/shortcode-propertylist.yaml create mode 100644 layouts/shortcodes/propertylist.html diff --git a/exampleSite/data/properties/demo.yaml b/exampleSite/data/properties/demo.yaml new file mode 100644 index 0000000..ea21dfc --- /dev/null +++ b/exampleSite/data/properties/demo.yaml @@ -0,0 +1,32 @@ +--- +properties: + - name: prop1 + type: string + description: Dummy description of the prop1 string property. + required: true + + - name: prop2 + type: int + defaultValue: 10 + description: Another description for the integer property called prop2. + required: false + tags: + - tag1 + - tag2 + + - name: prop3 + type: bool + defaultValue: false + description: | + A `bool` property with a complex multiline description and embedded Markdown: + + - List item 1 + - List item 2 + + More description how to use this property. + required: false + + - name: a-prop + type: string + description: Property to demonstrate sorting. + required: true diff --git a/exampleSite/data/properties/shortcode-propertylist.yaml b/exampleSite/data/properties/shortcode-propertylist.yaml new file mode 100644 index 0000000..4fe0fb2 --- /dev/null +++ b/exampleSite/data/properties/shortcode-propertylist.yaml @@ -0,0 +1,15 @@ +--- +properties: + - name: name + type: string + description: Name of the file from the `data/properties/` directory. + required: true + - name: sort + type: string + description: Field name to use for sorting. + required: false + - name: order + type: string + description: Sort order, only applied if `sort` is set. Supported values are `asc|desc`. + required: false + defaultValue: asc diff --git a/layouts/shortcodes/propertylist.html b/layouts/shortcodes/propertylist.html new file mode 100644 index 0000000..090e941 --- /dev/null +++ b/layouts/shortcodes/propertylist.html @@ -0,0 +1,52 @@ +{{- $name := .Get "name" -}} +{{- $sort := .Get "sort" -}} +{{- $order := default "asc" (.Get "order") -}} +{{- $showAnchor := (and (default true .Page.Params.geekblogAnchor) (default true .Page.Site.Params.geekblogAnchor)) -}} + +{{- if .Site.Data.properties }} +
+ {{- with (index .Site.Data.properties (split $name ".")) }} + {{- $properties := .properties }} + {{- with $sort }} + {{- $properties = (sort $properties . $order) }} + {{- end }} + {{- range $properties }} +
+ {{ .name }} + {{- if .required }} + required + {{- else }} + optional + {{- end }} + {{- with .type }} + {{ . }} + {{- end }} + + {{- with .tags }} + {{- range . }} + {{ . }} + {{- end }} + {{- end }} + {{- if $showAnchor }} + + + + {{- end }} +
+
+
+ {{- with .description }} + {{ . | $.Page.RenderString }} + {{- end }} +
+
+ {{- with default "none" (.defaultValue | string) }} + Default: + {{ . }} + {{- end }} +
+
+ {{- end }} + {{- end }} +
+{{- end }} diff --git a/src/sass/_shortcodes.scss b/src/sass/_shortcodes.scss index 5851b4b..b195e89 100644 --- a/src/sass/_shortcodes.scss +++ b/src/sass/_shortcodes.scss @@ -230,7 +230,7 @@ padding: $padding-4 $padding-16; } - .gblog-page__anchor { + .gblog-post__anchor { display: none; } } @@ -246,6 +246,47 @@ } } +// {{< propertylist >}} +.gblog-props { + &__title, + &__default { + padding: 0; + margin: 0; + font-family: "Liberation Mono", monospace; + } + + &__meta { + gap: 0.5em; + line-height: normal; + margin-bottom: $padding-4; + + &:hover .gblog-post__anchor svg.gblog-icon { + color: var(--control-icons); + } + } + + @each $name, $color in $hint-colors { + &__tag.#{$name} { + border-color: scale-color($color, $lightness: 90%, $saturation: -30%); + background-color: scale-color($color, $lightness: 95%, $saturation: -30%); + } + } + + &__tag { + font-size: $font-size-14; + font-weight: normal; + background-color: $gray-100; + border: $border-1 solid $gray-200; + border-radius: $border-radius; + padding: $padding-2 $padding-4; + color: $body-font-color; + } + + &__default { + font-size: $font-size-14; + } +} + // {{% progress %}} .gblog-progress { margin-bottom: $padding-16;