Skip to content

Commit

Permalink
Add two versioning shortcodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwcarlson committed Sep 1, 2023
1 parent fd4ff7e commit a454455
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions themes/psh-docs/layouts/shortcodes/version/only.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- Markdown passed between shortcode `vendor/inner` will render only if the current version = first passed variable -->
<!-- For example, -->
<!-- {{< vendor/only "1" >}} -->
<!-- platform variable:get -->
<!-- {{< /vendor/only >}} -->
<!-- When the site is built, the `platform` command will appear iff vendor.config.version = 1 in params.yaml -->
{{- $version := .Site.Params.vendor.config.version -}}
{{- if eq $version ( int (.Get 0)) -}}
{{- .Inner | .Page.RenderString -}}
{{- end -}}
18 changes: 18 additions & 0 deletions themes/psh-docs/layouts/shortcodes/version/specific.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Markdown processes 2 versions, rendering only if key matches current version -->
<!-- Key 1: Version 1; the first Inner prior to the dividing character -->
<!-- Key 2: Version 2; the second Inner after the dividing character -->
<!-- For example, -->
<!-- {{< vendor/specific >}} -->
<!-- platform variable:get -->
<!-- \<---\> -->
<!-- friday variable:get -->
<!-- {{< /vendor/specific}} -->
{{- $page := .Page -}}
{{- $version := .Site.Params.vendor.config.version -}}
{{- $splitVersionChar := "<--->" -}}
{{- range $k, $v := split .Inner $splitVersionChar -}}
{{- $current := add $k 1 -}}
{{- if eq $current $version -}}
{{- $v | $page.RenderString -}}
{{- end -}}
{{- end -}}

0 comments on commit a454455

Please sign in to comment.