mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 07:18:57 +00:00
feat: add env shortcode for conditional content rendering based on Hugo environment
This commit is contained in:
@@ -194,8 +194,6 @@ function isObjectLiteral(str) {
|
||||
|
||||
## Gist Embed
|
||||
|
||||
```md
|
||||
{{</* gist Lruihao fb8b2d0353465c4d40bf74818db80710 */>}}
|
||||
```
|
||||
|
||||
<!-- {{< gist Lruihao fb8b2d0353465c4d40bf74818db80710 >}} -->
|
||||
{{< env "production" >}}
|
||||
{{< gist Lruihao fb8b2d0353465c4d40bf74818db80710 >}}
|
||||
{{< /env >}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251222034819-3fa866fa" -}}
|
||||
{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251222065334-6cf32775" -}}
|
||||
{{- .Store.Set "this" dict -}}
|
||||
|
||||
{{- partial "init/detection-env.html" . -}}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{{- /*
|
||||
A shortcode to conditionally render content based on the current Hugo environment.
|
||||
Hugo environments (development, production, etc.) usage reference:
|
||||
- https://gohugo.io/functions/hugo/environment/
|
||||
- https://gohugo.io/configuration/all/#environment
|
||||
|
||||
For example, to render content only in the "production" environment:
|
||||
{{< env "production" >}}
|
||||
This content is only visible in production.
|
||||
{{< /env >}}
|
||||
*/ -}}
|
||||
|
||||
{{- $env := .Get 0 -}}
|
||||
{{- if eq $env hugo.Environment -}}
|
||||
{{- .Inner | .Page.RenderString -}}
|
||||
{{- else if hugo.IsServer -}}
|
||||
<details>
|
||||
<summary>[Hugo Server]: Click to expand <strong><code>{{ $env }}</code></strong> environment content.</summary>
|
||||
<pre><code>{{- printf `%s` "\n" | trim .Inner -}}</code></pre>
|
||||
</details>
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user