diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/css/_shame.css b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/css/_shame.css index 634adbf06..30e0c412d 100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/css/_shame.css +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/css/_shame.css @@ -18,3 +18,8 @@ h6:first-of-type { h6 ~ p { margin: 0.5em 0 2em 0; } + +/* QR codes */ +img.qrcode { + width: initial; +} diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/output/css/app.css b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/output/css/app.css index b9518491c..b6343c7be 100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/output/css/app.css +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/output/css/app.css @@ -5333,6 +5333,11 @@ h6:first-of-type { h6 ~ p { margin: 0.5em 0 2em 0; } +/* QR codes */ +img.qrcode { + width: auto; + width: initial; +} .nested-blockquote blockquote { border-left: 4px solid #0594CB; padding-left: 1em; diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml b/docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml index ca02ecc6f..705ca9746 100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml @@ -5,15 +5,6 @@ utm_campaign = "hugosponsor" bgcolor = "#ffffff" -[[banners]] - name = "Route4Me" - link = "https://route4me.com/" - title = "Route Planning & Route Optimization Software" - no_query_params = true - utm_campaign = "hugosponsor" - bgcolor = "#334799" - link_attr = "style='color: #ffffff; font-weight: bold; text-decoration: none; text-align: center'" - [[banners]] name = "GoLand" title = "The complete IDE crafted for professional Go developers." @@ -21,3 +12,11 @@ link = "https://www.jetbrains.com/go/?utm_source=OSS&utm_medium=referral&utm_campaign=hugo" logo = "images/sponsors/goland.svg" bgcolor = "#f4f4f4" + +[[banners]] + name = "Your Company?" + link = "https://bep.is/en/hugo-sponsor-2023-01/" + utm_campaign = "hugosponsor" + show_on_hover = true + bgcolor = "#4e4f4f" + link_attr = "style='color: #ffffff; font-weight: bold; text-decoration: none; text-align: center'" diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/_default/_markup/render-link.html b/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/_default/_markup/render-link.html index 9b6cad114..3dcb77dc3 100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/_default/_markup/render-link.html +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/_default/_markup/render-link.html @@ -98,12 +98,7 @@ either of these shortcodes in conjunction with this render hook. {{- end }} {{- /* Determine content path for warning and error messages. */}} -{{- $contentPath := "" }} -{{- with .Page.File }} - {{- $contentPath = .Path }} -{{- else }} - {{- $contentPath = .Path }} -{{- end }} +{{- $contentPath := .Page.String }} {{- /* Parse destination. */}} {{- $u := urls.Parse .Destination }} diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/include.html b/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/include.html index 9ad6e4ecb..9456e197e 100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/include.html +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/include.html @@ -10,7 +10,7 @@ You must call this shortcode using the {{% %}} notation. */}} {{- with .Get 0 }} - {{- with site.GetPage . }} + {{- with $.Page.GetPage . }} {{- .RenderShortcodes }} {{- else }} {{- errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }} diff --git a/docs/_vendor/modules.txt b/docs/_vendor/modules.txt index 5ff5b9db1..a5092f11e 100644 --- a/docs/_vendor/modules.txt +++ b/docs/_vendor/modules.txt @@ -1,2 +1 @@ -# github.com/gohugoio/gohugoioTheme v0.0.0-20241119115653-b92d27ede3e1 - +# github.com/gohugoio/gohugoioTheme v0.0.0-20250106044328-feb60697e056 diff --git a/docs/content/en/content-management/related.md b/docs/content/en/content-management/related.md index 0a97bd7cb..44b115a64 100644 --- a/docs/content/en/content-management/related.md +++ b/docs/content/en/content-management/related.md @@ -21,12 +21,12 @@ To list up to 5 related pages (which share the same _date_ or _keyword_ paramete {{< code file=layouts/partials/related.html >}} {{ $related := .Site.RegularPages.Related . | first 5 }} {{ with $related }} -

See Also

- +

See Also

+ {{ end }} {{< /code >}} diff --git a/docs/content/en/functions/collections/Dictionary.md b/docs/content/en/functions/collections/Dictionary.md index 2ac875d28..07d1eb0f2 100644 --- a/docs/content/en/functions/collections/Dictionary.md +++ b/docs/content/en/functions/collections/Dictionary.md @@ -7,7 +7,7 @@ action: aliases: [dict] related: - functions/collections/Slice - returnType: mapany + returnType: map[string]any signatures: ['collections.Dictionary [VALUE...]'] aliases: [/functions/dict] --- diff --git a/docs/content/en/functions/collections/Querify.md b/docs/content/en/functions/collections/Querify.md index 07e27bd7e..0eb409421 100644 --- a/docs/content/en/functions/collections/Querify.md +++ b/docs/content/en/functions/collections/Querify.md @@ -1,6 +1,6 @@ --- title: collections.Querify -description: Returns a URL query string composed of the given key-value pairs. +description: Returns a URL query string composed of the given key-value pairs, encoded and sorted by key. categories: [] keywords: [] action: @@ -13,18 +13,18 @@ action: aliases: [/functions/querify] --- -Specify the key-value pairs as individual arguments, or as a slice. The following are equivalent: - +Specify the key-value pairs as a map, a slice, or a sequence of scalar values. For example, the following are equivalent: ```go-html-template -{{ collections.Querify "a" 1 "b" 2 }} +{{ collections.Querify (dict "a" 1 "b" 2) }} {{ collections.Querify (slice "a" 1 "b" 2) }} +{{ collections.Querify "a" 1 "b" 2 }} ``` To append a query string to a URL: ```go-html-template -{{ $qs := collections.Querify "a" 1 "b" 2 }} +{{ $qs := collections.Querify (dict "a" 1 "b" 2) }} {{ $href := printf "https://example.org?%s" $qs }} Link @@ -35,3 +35,16 @@ Hugo renders this to: ```html Link ``` + +You can also pass in a map from your site configuration or front matter. For example: + +{{< code-toggle file=content/example.md fm=true >}} +title = 'Example' +[params.query] +a = 1 +b = 2 +{{< /code-toggle >}} + +```go-html-template +{{ collections.Querify .Params.query }} +``` diff --git a/docs/content/en/functions/js/Babel.md b/docs/content/en/functions/js/Babel.md index 4271cd35e..9485b4d05 100644 --- a/docs/content/en/functions/js/Babel.md +++ b/docs/content/en/functions/js/Babel.md @@ -3,8 +3,9 @@ title: js.Babel description: Compiles the given JavaScript resource with Babel. categories: [] keywords: [] +weight: 100 action: - aliases: [babel] + aliases: [babel,/hugo-pipes/babel/] related: - functions/js/Build - functions/resources/Fingerprint diff --git a/docs/content/en/functions/js/Batch.md b/docs/content/en/functions/js/Batch.md new file mode 100644 index 000000000..4299654dc --- /dev/null +++ b/docs/content/en/functions/js/Batch.md @@ -0,0 +1,331 @@ +--- +title: js.Batch +description: Build JavaScript bundle groups with global code splitting and flexible hooks/runners setup. +weight: 50 +categories: [] +keywords: [] +action: + aliases: [] + related: + - functions/js/Build + - functions/js/Babel + - functions/resources/Fingerprint + - functions/resources/Minify + returnType: js.Batcher + signatures: ['js.Batch [ID]'] +toc: true +--- + +{{% note %}} +For a runnable example of this feature, see [this test and demo repo](https://github.com/bep/hugojsbatchdemo/). +{{% /note %}} + +The Batch `ID` is used to create the base directory for this batch. Forward slashes are allowed. `js.Batch` returns an object with an API with this structure: + +* [Group] + * [Script] + * [SetOptions] + * [Instance] + * [SetOptions] + * [Runner] + * [SetOptions] + * [Config] + * [SetOptions] + + +## Group + +The `Group` method take an `ID` (`string`) as argument. No slashes. It returns an object with these methods: + + +#### Script + +The `Script` method takes an `ID` (`string`) as argument. No slashes. It returns an [OptionsSetter] that can be used to set [script options] for this script. + +```go-html-template +{{ with js.Batch "js/mybatch" }} + {{ with .Group "mygroup" }} + {{ with .Script "myscript" }} + {{ .SetOptions (dict "resource" (resources.Get "myscript.js")) }} + {{ end }} + {{ end }} +{{ end }} +``` + +`SetOptions` takes a [script options] map. Note that if you want the script to be handled by a [runner], you need to set the `export` option to match what you want to pass on to the runner (default is `*`). + +#### Instance + +The `Instance` method takes two `string` arguments `SCRIPT_ID` and `INSTANCE_ID`. No slashes. It returns an [OptionsSetter] that can be used to set [params options] for this instance. + +```go-html-template +{{ with js.Batch "js/mybatch" }} + {{ with .Group "mygroup" }} + {{ with .Instance "myscript" "myinstance" }} + {{ .SetOptions (dict "params" (dict "param1" "value1")) }} + {{ end }} + {{ end }} +{{ end }} +``` + +`SetOptions` takes a [params options] map. The instance options will be passed to any [runner] script in the same group, as JSON. + + +#### Runner + +The `Runner` method takes an `ID` (`string`) as argument. No slashes. It returns an [OptionsSetter] that can be used to set [script options] for this runner. + +```go-html-template +{{ with js.Batch "js/mybatch" }} + {{ with .Group "mygroup" }} + {{ with .Runner "myrunner" }} + {{ .SetOptions (dict "resource" (resources.Get "myrunner.js")) }} + {{ end }} + {{ end }} +{{ end }} +``` + +`SetOptions` takes a [script options] map. + +The runner will receive a data structure with all instances for that group with a live binding of the [JavaScript import] of the defined `export`. + +The runner script's export must be a function that takes one argument, the group data structure. An example of a group data structure as JSON is: + +```json +{ + "id": "leaflet", + "scripts": [ + { + "id": "mapjsx", + "binding": JAVASCRIPT_BINDING, + "instances": [ + { + "id": "0", + "params": { + "c": "h-64", + "lat": 48.8533173846729, + "lon": 2.3497416090232535, + "r": "map.jsx", + "title": "Cathédrale Notre-Dame de Paris", + "zoom": 23 + } + }, + { + "id": "1", + "params": { + "c": "h-64", + "lat": 59.96300872062237, + "lon": 10.663529183196863, + "r": "map.jsx", + "title": "Holmenkollen", + "zoom": 3 + } + } + ] + } + ] +} +``` + +Below is an example of a runner script that uses React to render elements. Note that the export (`default`) must match the `export` option in the [script options] (`default` is the default value for runner scripts) (runnable versions of examples on this page can be found at [js.Batch Demo Repo]): + + +```js +import * as ReactDOM from 'react-dom/client'; +import * as React from 'react'; + +export default function Run(group) { + console.log('Running react-create-elements.js', group); + const scripts = group.scripts; + for (const script of scripts) { + for (const instance of script.instances) { + /* This is a convention in this project. */ + let elId = `${script.id}-${instance.id}`; + let el = document.getElementById(elId); + if (!el) { + console.warn(`Element with id ${elId} not found`); + continue; + } + const root = ReactDOM.createRoot(el); + const reactEl = React.createElement(script.binding, instance.params); + root.render(reactEl); + } + } +} +``` + + + +#### Config + +Returns an [OptionsSetter] that can be used to set [build options] for the batch. + +These are mostly the same as for [js.Build], but note that: + +* `targetPath` is set automatically (there may be multiple outputs). +* `format` must be `esm`, currently the only format supporting [code splitting]. +* `params` will be available in the `@params/config` namespace in the scripts. This way you can import both the [script] or [runner] params and the [config] params with: + +```js +import * as params from "@params"; +import * as config from "@params/config"; +``` + +Setting the `Config` for a batch can be done from any template (including shortcode templates), but will only be set once (the first will win): + +```go-html-template +{{ with js.Batch "js/mybatch" }} + {{ with .Config }} + {{ .SetOptions (dict + "target" "es2023" + "format" "esm" + "jsx" "automatic" + "loaders" (dict ".png" "dataurl") + "minify" true + "params" (dict "param1" "value1") + ) + }} + {{ end }} +{{ end }} +``` + +## Options + +### Build Options + +format +: (`string`) Currently only `esm` is supported in [ESBuild's code splitting]. + +{{% include "./_common/options.md" %}} + +### Script Options + +resource +: The resource to build. This can be a file resource or a virtual resource. + +export +: The export to bind the runner to. Set it to `*` to export the [entire namespace](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import). Default is `default` for [runner] scripts and `*` for other [scripts](#script). + +importContext +: An additional context for resolving imports. Hugo will always check this one first before falling back to `assets` and `node_modules`. A common use of this is to resolve imports inside a page bundle. See [import context](#import-context). + +params +: A map of parameters that will be passed to the script as JSON. These gets bound to the `@params` namespace: +```js +import * as params from '@params'; +``` + +### Script Options + +### Params Options + +params +: A map of parameters that will be passed to the script as JSON. + +### Import Context + +Hugo will, by default, first try to resolve any import in [assets](/hugo-pipes/introduction/#asset-directory) and, if not found, let [ESBuild] resolve it (e.g. from `node_modules`). The `importContext` option can be used to set the first context for resolving imports. A common use of this is to resolve imports inside a [page bundle](/content-management/page-bundles/). + +```go-html-template +{{ $common := resources.Match "/js/headlessui/*.*" }} +{{ $importContext := (slice $.Page ($common.Mount "/js/headlessui" ".")) }} +``` + +You can pass any object that implements [Resource.Get](/methods/page/resources/#get). Pass a slice to set multiple contexts. + +The example above uses [`Resources.Mount`] to resolve a folder inside `assets` relative to the page bundle. + +### OptionsSetter + +An `OptionsSetter` is a special object that is returned once only. This means that you should wrap it with [with]: + +```go-html-template +{{ with .Script "myscript" }} + {{ .SetOptions (dict "resource" (resources.Get "myscript.js"))}} +{{ end }} +``` + +## Build + +The `Build` method returns an object with the following structure: + +* Groups (map) + * [`Resources`] + +Eeach [`Resource`] will be of media type `application/javascript` or `text/css`. + + In a template you would typically handle one group with a given `ID` (e.g. scripts for the current section). Because of the concurrent build, this needs to be done in a [`templates.Defer`] block: + +{{% note %}} +The [`templates.Defer`] acts as a synchronisation point to handle scripts added concurrently by different templates. If you have a setup with where the batch is created in one go (in one template), you don't need it. + +See [this discussion](https://discourse.gohugo.io/t/js-batch-with-simple-global-script/53002/5?u=bep) for more. + +[`templates.Defer`]: /functions/templates/defer/ +{{% /note %}} + +```go-html-template +{{ $group := .group }} +{{ with (templates.Defer (dict "key" $group "data" $group )) }} + {{ with (js.Batch "js/mybatch") }} + {{ with .Build }} + {{ with index .Groups $ }} + {{ range . }} + {{ $s := . }} + {{ if eq $s.MediaType.SubType "css" }} + + {{ else }} + + {{ end }} + {{ end }} + {{ end }} + {{ end }} +{{ end }} +``` + + +## Known Issues + +In the official documentation for [ESBuild's code splitting], there's a warning note in the header. The two issues are: + +* `esm` is currently the only implemented output format. This means that it will not work for very old browsers. See [caniuse](https://caniuse.com/?search=ESM). +* There's a known import ordering issue. + +We have not seen the ordering issue as a problem during our [extensive testing](https://github.com/bep/hugojsbatchdemo) of this new feature with different libraries. There are two main cases: + +1. Undefined execution order of imports, see [this comment](https://github.com/evanw/esbuild/issues/399#issuecomment-1458680887) +2. Only one execution order of imports, see [this comment](https://github.com/evanw/esbuild/issues/399#issuecomment-735355932) + +Many would say that both of the above are [code smells](https://en.wikipedia.org/wiki/Code_smell). The first one has a simple workaround in Hugo. Define the import order in its own script and make sure it gets passed early to ESBuild, e.g. by putting it in a script group with a name that comes early in the alphabet. + +```js +import './lib2.js'; +import './lib1.js'; + +console.log('entrypoints-workaround.js'); + +``` + +[build options]: #build-options +[`Resource`]: https://gohugo.io/methods/resource/ +[`Resources`]: /methods/page/resources/ +[`Resources.Mount`]: /methods/page/resources/#mount +[`templates.Defer`]: /functions/templates/defer/ +[code splitting]: https://esbuild.github.io/api/#splitting +[config]: #config +[ESBuild's code splitting]: https://esbuild.github.io/api/#splitting +[ESBuild]: https://github.com/evanw/esbuild +[group]: #group +[instance]: #instance +[JavaScript import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import +[js.Batch Demo Repo]: https://github.com/bep/hugojsbatchdemo/ +[js.Build]: https://gohugo.io/hugo-pipes/js/#options +[map]: https://gohugo.io/functions/collections/dictionary/ +[OptionsSetter]: #optionssetter +[page bundles]: https://gohugo.io/content-management/page-bundles/ +[params options]: #params-options +[runner]: #runner +[script options]: #script-options +[script]: #script +[SetOptions]: #optionssetter +[with]: https://gohugo.io/functions/go-template/with/ diff --git a/docs/content/en/functions/js/Build.md b/docs/content/en/functions/js/Build.md index 2a948416e..0e5fd3c0a 100644 --- a/docs/content/en/functions/js/Build.md +++ b/docs/content/en/functions/js/Build.md @@ -1,6 +1,7 @@ --- title: js.Build description: Bundles, transpiles, tree shakes, and minifies JavaScript resources. +weight: 30 categories: [] keywords: [] action: @@ -45,94 +46,10 @@ targetPath : (`string`) If not set, the source path will be used as the base target path. Note that the target path's extension may change if the target MIME type is different, e.g. when the source is TypeScript. -params -: (`map` or `slice`) Params that can be imported as JSON in your JS files, e.g. - -```go-html-template -{{ $js := resources.Get "js/main.js" | js.Build (dict "params" (dict "api" "https://example.org/api")) }} -``` -And then in your JS file: - -```js -import * as params from '@params'; -``` - -Note that this is meant for small data sets, e.g. configuration settings. For larger data, please put/mount the files into `/assets` and import them directly. - -minify -: (`bool`)Let `js.Build` handle the minification. - -inject -: (`slice`) This option allows you to automatically replace a global variable with an import from another file. The path names must be relative to `assets`. See https://esbuild.github.io/api/#inject - -shims -: (`map`) This option allows swapping out a component with another. A common use case is to load dependencies like React from a CDN (with _shims_) when in production, but running with the full bundled `node_modules` dependency during development: - -```go-html-template -{{ $shims := dict "react" "js/shims/react.js" "react-dom" "js/shims/react-dom.js" }} -{{ $js = $js | js.Build dict "shims" $shims }} -``` - -The _shim_ files may look like these: - -```js -// js/shims/react.js -module.exports = window.React; -``` - -```js -// js/shims/react-dom.js -module.exports = window.ReactDOM; -``` - -With the above, these imports should work in both scenarios: - -```js -import * as React from 'react'; -import * as ReactDOM from 'react-dom/client'; -``` - -target -: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020` or `esnext`. Default is `esnext`. - -externals -: (`slice`) External dependencies. Use this to trim dependencies you know will never be executed. See https://esbuild.github.io/api/#external - -defines -: (`map`) Allow to define a set of string replacement to be performed when building. Should be a map where each key is to be replaced by its value. - -```go-html-template -{{ $defines := dict "process.env.NODE_ENV" `"development"` }} -``` - format : (`string`) The output format. One of: `iife`, `cjs`, `esm`. Default is `iife`, a self-executing function, suitable for inclusion as a ` -``` +See [JS functions](/functions/js/). diff --git a/docs/content/en/methods/menu-entry/Name.md b/docs/content/en/methods/menu-entry/Name.md index d77c65cb5..fb5fc1b5b 100644 --- a/docs/content/en/methods/menu-entry/Name.md +++ b/docs/content/en/methods/menu-entry/Name.md @@ -9,9 +9,9 @@ action: signatures: [MENUENTRY.Name] --- -If you define the menu entry [automatically], the `Name` method returns the page’s [`LinkTitle`], falling back to its [`Title`]. +If you define the menu entry [automatically], the `Name` method returns the page's [`LinkTitle`], falling back to its [`Title`]. -If you define the menu entry [in front matter] or [in site configuration], the `Name` method returns the `name` property, falling back to the page’s `LinkTitle`, then to its `Title`. +If you define the menu entry [in front matter] or [in site configuration], the `Name` method returns the `name` property of the given menu entry. If the `name` is not defined, and the menu entry resolves to a page, the `Name` returns the page [`LinkTitle`], falling back to its [`Title`]. [`LinkTitle`]: /methods/page/linktitle/ [`Title`]: /methods/page/title/ diff --git a/docs/content/en/methods/menu-entry/Title.md b/docs/content/en/methods/menu-entry/Title.md index 4082e4e93..64bba2d44 100644 --- a/docs/content/en/methods/menu-entry/Title.md +++ b/docs/content/en/methods/menu-entry/Title.md @@ -9,20 +9,14 @@ action: signatures: [MENUENTRY.Title] --- -If you define the menu entry [automatically], the `Title` method returns the page’s [`LinkTitle`], falling back to its [`Title`]. +The `Title` method returns the `title` property of the given menu entry. If the `title` is not defined, and the menu entry resolves to a page, the `Title` returns the page [`Title`]. -If you define the menu entry [in front matter] or [in site configuration], the `Title` method returns the `title` property, falling back to the page’s `LinkTitle`, then to its `Title`. - -[`LinkTitle`]: /methods/page/linktitle/ [`Title`]: /methods/page/title/ -[automatically]: /content-management/menus/#define-automatically -[in front matter]: /content-management/menus/#define-in-front-matter -[in site configuration]: /content-management/menus/#define-in-site-configuration ```go-html-template