forked from google/docsy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds conditional-text shortcode * Documents conditional-text shortcode * Typo correction Co-authored-by: LisaFC <lcarey@google.com>
- Loading branch information
1 parent
198c1a0
commit de4aa36
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- Get the current buildcondition from the config and lowercase it --> | ||
{{ $condition := lower $.Site.Params.buildCondition }} | ||
|
||
{{ if ne $condition "" }} | ||
|
||
<!-- Get the parameters from the shortcode invocation and lowercase them. | ||
TODO: to enable multiple conditions, we could accept comma-separated lists and split them --> | ||
{{ $include_if := lower (.Get "include-if") }} | ||
{{ $exclude_if := lower (.Get "exclude-if") }} | ||
|
||
{{ if and (in $include_if $condition) (in $exclude_if $condition) }} | ||
<!-- condition appears in both parameters --> | ||
{{- errorf "Build condition %q appears in both include-if and exclude-if parameters of conditional-txt shortcode on page %s" $condition .Position -}} | ||
{{ end }} | ||
|
||
{{ if isset $.Params "include-if" }} | ||
<!-- WARNING substring matches are matches as well! That means, if include-if="foobar", and buildcondition is "foo", you have a match!--> | ||
{{ if in $include_if $condition }} | ||
<!-- Do not indent the next Inner line, because the inner becomes a blockquote if the conditional-text is nested in another shortcode --> | ||
{{ .Inner }} | ||
{{ else }} | ||
{{ end }} | ||
{{ else }} | ||
|
||
{{ if isset $.Params "exclude-if" }} | ||
<!-- WARNING substring matches are matches as well! That means, if exclude-if="foobar", and buildcondition is "foo", you have a match!--> | ||
{{ if in $exclude_if $condition }} | ||
{{ else }} | ||
<!-- Do not indent the next Inner line, because the inner becomes a blockquote if the conditional-text is nested in another shortcode --> | ||
{{ .Inner }} | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ end }} | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters