Improve boilerplates so they can now contain shortcodes (#3019)

This commit is contained in:
Martin Taillefer 2019-01-02 17:42:56 -08:00 committed by GitHub
parent 95c5e619e7
commit 1ca2020e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 8 deletions

View File

@ -540,6 +540,7 @@ Keycloak
OpenID
Istioctl
Boilerplates
boilerplates
- search.md
searchresults

View File

@ -1,2 +0,0 @@
This is some boilerplate *markdown* _text_.

View File

@ -450,8 +450,8 @@ which results in:
{{< boilerplate example >}}
You supply the name of a boilerplate file to insert at the current location. Boilerplates are
located in language-specific subdirectories of the `boilerplates` directory. Boilerplates are just
You supply the name of a boilerplate file to insert at the current location. Available boilerplates are
located in the `boilerplates` directory. Boilerplates are just
normal markdown files.
## Using tabs

View File

@ -0,0 +1,5 @@
This is some boilerplate *markdown* _text_.
{{< text plain >}}
A sample nested text block.
{{< /text >}}

View File

@ -0,0 +1,3 @@
---
headless: true
---

View File

@ -1,4 +1,26 @@
{{- /* Inserts a boilerplate markdown file into the document. See https://preliminary.istio.io/about/contribute/writing-a-new-topic/#embedding-boilerplate-text for details */ -}}
{{- $path := printf "boilerplates/%s/%s.md" .Site.Language.Lang (.Get 0) -}}
{{- $markdown := readFile $path -}}
{{- markdownify $markdown }}
{{/* This will try to find a resource in the "boilerplates" top-level content directory */}}
{{- $name := .Get 0 -}}
{{- $position := .Position }}
{{- if $name -}}
{{- $bundle := $.Site.GetPage "page" "boilerplates" -}}
{{- with $bundle -}}
{{- $pattern := printf "%s*" $name -}}
{{- $resource := $bundle.Resources.GetMatch $pattern -}}
{{- with $resource -}}
{{- .Content | safeHTML -}}
{{- else -}}
{{/* It is not a resource in the top-level boilerplates directory. Try to find the page relative to the current page instead. */}}
{{- $path := path.Join $.Page.Dir $name -}}
{{- $page := $.Page.Site.GetPage "page" $path -}}
{{- with $page }}
{{ .Content }}
{{- else -}}
{{ errorf "Could not find %s (%s)." $pattern $position }}
{{- end -}}
{{- end -}}
{{- else -}}
{{ errorf "'boilerplates' direcory was not found (%s)" $position }}
{{- end -}}
{{- else -}}
{{- errorf "Missing name in boilerplate (%s)" $position -}}
{{- end -}}