Skip to content

Commit

Permalink
feat: add hugo/preview shortcode, a alias of hugo/shortcode-example (#66
Browse files Browse the repository at this point in the history
)
  • Loading branch information
razonyang authored Sep 5, 2024
1 parent 944db1e commit d110a07
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[hugo_preview_result]
other = "Result"

[hugo_preview_source]
other = "Source"

[parameter_context]
other = "Context"

Expand Down
6 changes: 6 additions & 0 deletions i18n/vi.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[hugo_preview_result]
other = "Result"

[hugo_preview_source]
other = "Source"

[parameter_context]
other = "Context"

Expand Down
6 changes: 6 additions & 0 deletions i18n/zh-hans.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[hugo_preview_result]
other = "结果"

[hugo_preview_source]
other = "源码"

[parameter_context]
other = "上下文"

Expand Down
6 changes: 6 additions & 0 deletions i18n/zh-hant.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[hugo_preview_result]
other = "結果"

[hugo_preview_source]
other = "源碼"

[parameter_context]
other = "上下文"

Expand Down
15 changes: 15 additions & 0 deletions layouts/partials/hugo/preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- $source := trim .Source "\r\n" -}}
<div class="hugo-preview">
<div class="hugo-preview-source">
<div class="hugo-preview-source-title" style="font-weight: bold; margin-bottom: .25rem;">
{{- i18n "hugo_preview_source" | default "Source" -}}
</div>
{{- highlight $source "markdown" -}}
</div>
<div class="hugo-preview-result">
<div class="hugo-preview-result-title" style="font-weight: bold; margin-bottom: .25rem;">
{{- i18n "hugo_preview_result" | default "Result" -}}
</div>
{{- $source | .Page.RenderString }}
</div>
</div>
1 change: 1 addition & 0 deletions layouts/shortcodes/hugo/preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- partial "hugo/preview" (dict "Source" .Inner "Page" .Page) }}
4 changes: 1 addition & 3 deletions layouts/shortcodes/hugo/shortcode-example.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{{- $inner := trim .Inner "\r\n" -}}
{{- highlight $inner "markdown" -}}
{{- $inner | .Page.RenderString }}
{{- partial "hugo/preview" (dict "Source" .Inner "Page" .Page) }}

0 comments on commit d110a07

Please sign in to comment.