diff --git a/CHANGELOG.md b/CHANGELOG.md index a64e1c0b..bbd9db4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,29 @@ ## Unreleased +### New Hugo renderer + +The main aspect of this release is a new and improved Hugo renderer when live editing on CloudCannon. Alongside being more reliable, this unlocks many templating functions that were previously unavailable, such as: + +* `newScratch` +* `absURL` +* `highlight` +* `humanize` + +Additionally, functions that would previously cause a full error (such as `resources.Get`) will now return `nil`, and as such can be handled gracefully inside a component. + +Looking forward, this release also paves the path for supporting site actions like `site.GetPage` in the visual editor, as well as using custom non-Bookshop Hugo partials in the visual editor. + +As with all releases, your repository can be upgraded to the latest Bookshop by running: +``` +npx @bookshop/up@latest +``` + +### Other changes +* Hugo WebAssembly files are now preloaded in CloudCannon, so loading the visual editor should be significantly faster +* Improved data binding support for Hugo template files, and generally fixed many issues with complex templating +* Reduced noise in the developer console when live editing Hugo Bookshop sites + ## v3.3.3 (December 2, 2022) * Added a `markdownify` filter to Eleventy Bookshop diff --git a/guides/hugo.adoc b/guides/hugo.adoc index a349da1d..9919d7f3 100644 --- a/guides/hugo.adoc +++ b/guides/hugo.adoc @@ -2013,204 +2013,12 @@ Bookshop's Eleventy live editing is built on top of the liquidjs package. As suc endif::Eleventy[] ifdef::hugo[] -Bookshop's Hugo live editing is built on top of the core Go text/template package. As such, not all Hugo features are supported within Bookshop components. Generally, functions that interact with Hugo or the site as a whole are unavailable. The following tables describe the features and functions currently supported in live-edited Bookshop components. -NOTE: Work is underway to expand support for many of the functions below. Open a GitHub issue if there is a specific function you need for your workflow. +Bookshop's Hugo editing is based upon a subset of Hugo running in the browser. As such, not all Hugo features will be available within Bookshop components. -++++ -
Bookshop Hugo Support Matrix -++++ - -[cols="1,1"] -|=== -|Hugo Feature |Supported in Bookshop - -|link:https://gohugo.io/templates/partials/#returning-a-value-from-a-partial[Partial return values] -|❌ - -|link:https://gohugo.io/functions/scratch/[.Scratch and newScratch] -|❌ -|=== - -For unsupported functions, see <> - -[cols="1,1"] -|=== -|Template Function |Supported in Bookshop - -|templates.* -|❌ -|os.* -|❌ -|urls.* -|❌ -|lang / i18n -|❌ -|hugo -|❌ -|apply -|❌ -|anchorize -|❌ -|absURL / absLangURL -|❌ -|humanize -|❌ -|now -|❌ -|Image Filters -|❌ -|partialCached -|❌ -|getenv -|❌ -|fileExists / readDir / readFile -|❌ -|ref / relref -|❌ -|relURL / relLangURL -|❌ -|site.BaseURL / site.Title / site.Copyright -|✅ -|Other site.* functions -|❌ -|highlight -|ℹ️ Will pass through the input string unchanged (i.e. it won't work, but it won't error) -|markdownify -|ℹ️ Uses a different markdown implementation. Output isn't guaranteed to match Hugo 1:1 -|strings.* -|✅ -|reflect.* -|✅ -|plainify -|✅ -|emojify -|✅ -|htmlEscape/htmlUnescape -|✅ -|merge -|✅ -|symdiff -|✅ -|complement -|✅ -|append -|✅ -|group -|✅ -|hmac -|✅ -|transform.Unmarshal -|✅ -|errorf and warnf -|✅ -|float -|✅ -|cond -|✅ -|ge/gt/le/lt/ne -|✅ -|after -|✅ -|base64 -|✅ -|chomp -|✅ -|countrunes -|✅ -|countwords -|✅ -|default -|✅ -|delimit -|✅ -|dict -|✅ -|echoParam -|✅ -|eq -|✅ -|findRE -|✅ -|first -|✅ -|hasPrefix -|✅ -|in -|✅ -|index -|✅ -|int -|✅ -|intersect -|✅ -|isset -|✅ -|jsonify -|✅ -|last -|✅ -|len -|✅ -|lower -|✅ -|Math -|✅ -|md5 -|✅ -|path.* -|✅ -|pluralize -|✅ -|print -|✅ -|printf -|✅ -|println -|✅ -|querify -|✅ -|range -|✅ -|replace -|✅ -|replaceRE -|✅ - -|=== +As a general rule: Functions that access files directly (such as `resources.Get`), or access other parts of the site (such as `site.GetPage`), will not return anything useful in the visual editor. -[cols="1,1"] -|=== -|Page Function |Supported in Bookshop - -|.AddDate -|❌ -|.Format -|❌ -|.Get -|❌ -|.GetPage -|❌ -|.HasMenuCurrent -|❌ -|.IsMenuCurrent -|❌ -|.Param -|❌ -|.Render -|❌ -|.RenderString -|❌ -|.Scratch -|❌ -|.Unix -|❌ - -|=== - -++++ -
-++++ +If you're encountering an unsupported function, such as finding that `resources.Get` returns `nil`, see <> endif::hugo[] diff --git a/javascript-modules/engines/hugo-engine/lib/engine.js b/javascript-modules/engines/hugo-engine/lib/engine.js index e45a7e50..851dec74 100644 --- a/javascript-modules/engines/hugo-engine/lib/engine.js +++ b/javascript-modules/engines/hugo-engine/lib/engine.js @@ -348,7 +348,8 @@ export class Engine { try { return JSON.parse(output); } catch (e) { - console.warn(`Error evaluating \`${str}\` in the Hugo engine`, output); + logger?.log?.(`Error evaluating \`${str}\` in the Hugo engine`); + logger?.log?.(output); return null; } }