Load presets from front matter + allow both bundled and global bergamot files

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2024-09-15 16:18:48 -07:00
parent dee7579b29
commit 3a281dfa8a
3 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<script>
window.addEventListener('load', function() {
window.Bergamot.renderPresets['{{ .name }}'] =
{{ readFile (printf "static/bergamot/rendering/%s" .file) }};
{{ .file }};
});
</script>

View File

@ -63,10 +63,18 @@
{{ partial "defercss.html" (dict "url" $bergamotStyle.Permalink "extra" "") }}
{{ if .Params.bergamot.render_presets }}
{{ range $name, $rulefile := .Params.bergamot.render_presets }}
{{ partial "bergamotrenderpreset.html" (dict "name" $name "file" $rulefile) }}
{{ $file := default (resources.Get $rulefile) (page.Resources.Get $rulefile) }}
{{ partial "bergamotrenderpreset.html" (dict "name" $name "file" $file.Content) }}
{{ end }}
{{ else }}
{{ partial "bergamotrenderpreset.html" (dict "name" "default" "file" "minimal.bergamot") }}
{{ partial "bergamotrenderpreset.html" (dict "name" "default" "file" (resources.Get "bergamot/rendering/minimal.bergamot").Content) }}
{{ end }}
{{ if .Params.bergamot.presets }}
{{ range $name, $preset := .Params.bergamot.presets }}
{{ $file := default (resources.Get $preset.file) (page.Resources.Get $preset.file) }}
{{ $info := dict "name" $name "prompt" $preset.prompt "query" $preset.query "file" $file.Content "renderPreset" $preset.render_preset }}
{{ partial "bergamotpreset.html" $info }}
{{ end }}
{{ end }}
{{ end }}