From 50cad5e38ca393d4f8c7ef5ca99f7feba5fff003 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 24 Nov 2023 15:51:27 -0800 Subject: [PATCH 1/5] tpl/transform: Add transform.XMLEscape template function Fixes #3268 --- content/en/functions/transform/XMLEscape.md | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 content/en/functions/transform/XMLEscape.md diff --git a/content/en/functions/transform/XMLEscape.md b/content/en/functions/transform/XMLEscape.md new file mode 100644 index 000000000..17ed2a13d --- /dev/null +++ b/content/en/functions/transform/XMLEscape.md @@ -0,0 +1,38 @@ +--- +title: transform.XMLEscape +description: Returns the given string, removing disallowed characters then escaping the result to its XML equivalent. +categories: [] +keywords: [] +action: + aliases: [] + related: [] + returnType: string + signatures: [transform.XMLEscape INPUT] +--- + +The `transform.XMLEscape` function removes [disallowed characters] as defined in the XML specification, then escapes the result by replacing the following characters with [HTML entities]: + +- `"` → `"` +- `'` → `'` +- `&` → `&` +- `<` → `<` +- `>` → `>` +- `\t` → ` ` +- `\n` → ` ` +- `\r` → ` ` + +For example: + +```go-html-template +transform.XMLEscape "

abc

" → <p>abc</p> +``` + +When using `transform.XMLEscape` in a template rendered by Go's [html/template] package, declare the string to be safe HTML to avoid double escaping. For example, in an RSS template: + +{{< code file="layouts/_default/rss.xml" >}} +{{ .Summary | transform.XMLEscape | safeHTML }} +{{< /code >}} + +[disallowed characters]: https://www.w3.org/TR/xml/#charsets +[html entities]: https://developer.mozilla.org/en-us/docs/glossary/entity +[html/template]: https://pkg.go.dev/html/template From f57fdb44bf6ae8ba1287f56bf70a8c264471c879 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Wed, 29 Nov 2023 14:03:40 -0800 Subject: [PATCH 2/5] deps: Update github.com/tdewolff/minify/v2 v2.20.7 => v2.20.8 Closes #5748 --- data/docs.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/data/docs.yaml b/data/docs.yaml index 2cdb0dd53..48a12f522 100644 --- a/data/docs.yaml +++ b/data/docs.yaml @@ -824,6 +824,8 @@ chroma: - Aliases: - typoscripthtmldata Name: TypoScriptHtmlData + - Aliases: null + Name: ucode - Aliases: - v - vlang @@ -1254,6 +1256,9 @@ config: keepEndTags: true keepQuotes: false keepWhitespace: false + templateDelims: + - "" + - "" js: keepVarNames: false precision: 0 @@ -2741,6 +2746,21 @@ tpl: map[string]interface {}{ "Hugo": "Rocks!", } + TestDeprecationErr: + Aliases: null + Args: null + Description: "" + Examples: null + TestDeprecationInfo: + Aliases: null + Args: null + Description: "" + Examples: null + TestDeprecationWarn: + Aliases: null + Args: null + Description: "" + Examples: null Timer: Aliases: null Args: null @@ -4364,6 +4384,16 @@ tpl: - - '{{ "hello = \"Hello World\"" | resources.FromString "data/greetings.toml" | transform.Unmarshal }}' - map[hello:Hello World] + XMLEscape: + Aliases: null + Args: + - s + Description: |- + XMLEscape returns the given string, removing disallowed characters then + escaping the result to its XML equivalent. + Examples: + - - '{{ transform.XMLEscape "

abc

" }}' + - '<p>abc</p>' urls: AbsLangURL: Aliases: From a703dab53161ea4c0c05dc2da43300da95b7a90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 4 Dec 2023 15:24:34 +0100 Subject: [PATCH 3/5] docs: Regen docs helper --- data/docs.yaml | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/data/docs.yaml b/data/docs.yaml index 2cdb0dd53..dc81ad8bc 100644 --- a/data/docs.yaml +++ b/data/docs.yaml @@ -824,6 +824,8 @@ chroma: - Aliases: - typoscripthtmldata Name: TypoScriptHtmlData + - Aliases: null + Name: ucode - Aliases: - v - vlang @@ -1254,6 +1256,9 @@ config: keepEndTags: true keepQuotes: false keepWhitespace: false + templateDelims: + - "" + - "" js: keepVarNames: false precision: 0 @@ -1563,8 +1568,6 @@ config: getenv: - ^HUGO_ - ^CI$ - goTemplates: - allowActionJSTmpl: false http: mediaTypes: null methods: @@ -2741,6 +2744,21 @@ tpl: map[string]interface {}{ "Hugo": "Rocks!", } + TestDeprecationErr: + Aliases: null + Args: null + Description: "" + Examples: null + TestDeprecationInfo: + Aliases: null + Args: null + Description: "" + Examples: null + TestDeprecationWarn: + Aliases: null + Args: null + Description: "" + Examples: null Timer: Aliases: null Args: null @@ -4364,6 +4382,16 @@ tpl: - - '{{ "hello = \"Hello World\"" | resources.FromString "data/greetings.toml" | transform.Unmarshal }}' - map[hello:Hello World] + XMLEscape: + Aliases: null + Args: + - s + Description: |- + XMLEscape returns the given string, removing disallowed characters then + escaping the result to its XML equivalent. + Examples: + - - '{{ transform.XMLEscape "

abc

" }}' + - '<p>abc</p>' urls: AbsLangURL: Aliases: From be98a37e1d2ade20fc35f0411cb487edba8daf8b Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Mon, 4 Dec 2023 07:43:38 -0800 Subject: [PATCH 4/5] docs: Adjust last merge from docs repository --- content/en/functions/hugo/index.md | 117 ----------- content/en/functions/images/index.md | 300 --------------------------- 2 files changed, 417 deletions(-) delete mode 100644 content/en/functions/hugo/index.md delete mode 100644 content/en/functions/images/index.md diff --git a/content/en/functions/hugo/index.md b/content/en/functions/hugo/index.md deleted file mode 100644 index 761c8d604..000000000 --- a/content/en/functions/hugo/index.md +++ /dev/null @@ -1,117 +0,0 @@ ---- -title: hugo -description: Provides global access to Hugo-related data. -categories: [functions] -keywords: [] -menu: - docs: - parent: functions -function: - aliases: [] - returnType: - signatures: [hugo] -relatedFunctions: - - hugo - - page - - site -aliases: [/functions/hugo] ---- - -`hugo` returns an instance that contains the following functions: - -`hugo.BuildDate` -: (`string`) The compile date of the current Hugo binary formatted per [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) (e.g., `2023-05-23T08:14:20Z`). - -`hugo.CommitHash` -: (`string`) The Git commit hash of the Hugo binary (e.g., `0a95d6704a8ac8d41cc5ca8fffaad8c5c7a3754a`). - -`hugo.Deps` -: (`[]*hugo.Dependency`) See [hugo.Deps](#hugodeps). - -`hugo.Environment` -: (`string`) The current running environment as defined through the `--environment` CLI flag (e.g., `development`, `production`). - -`hugo.Generator` -: (`template.HTML`) Renders an HTML `meta` element identifying the software that generated the site (e.g., ``). - -`hugo.GoVersion` -: (`string`) The Go version used to compile the Hugo binary (e.g., `go1.20.4`). {{< new-in "0.101.0" >}} - -`hugo.IsDevelopment` -: (`bool`) Returns `true` if `hugo.Environment` is "development". - -`hugo.IsExtended` -: (`bool`) Returns `true` if the Hugo binary is the extended version. - -`hugo.IsProduction` -: (`bool`) Returns `true` if `hugo.Environment` is "production". - -`hugo.IsServer` -: (`bool`) Returns `true` if the site is being served with Hugo's built-in server. - -`hugo.Version` -: (`hugo.VersionString`) The current version of the Hugo binary (e.g., `0.112.1`). - -`hugo.WorkingDir` -: (`string`) The project working directory (e.g., `/home/user/projects/my-hugo-site`). {{< new-in "0.112.0" >}} - -## hugo.Deps - -{{< new-in "0.92.0" >}} - -`hugo.Deps` returns a list of dependencies for a project (either Hugo Modules or local theme components). - -Each dependency contains: - -Owner -: (`*hugo.Dependency`) In the dependency tree, this is the first module that defines this module as a dependency (e.g., `github.com/gohugoio/hugo-mod-bootstrap-scss/v5`). - -Path -: (`string`) The module path or the path below your `themes` directory (e.g., `github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2`). - -Replace -: (`*hugo.Dependency`) Replaced by this dependency. - -Time -: (`time.Time`) The time that the version was created (e.g., `2022-02-13 15:11:28 +0000 UTC`). - -Vendor -: (`bool`) Returns `true` if the dependency is vendored. - -Version -: (`string`) The module version (e.g., `v2.21100.20000`). - -An example table listing the dependencies: - -```html -

Dependencies

- - - - - - - - - - - - - {{ range $index, $element := hugo.Deps }} - - - - - - - - - {{ end }} - -
#OwnerPathVersionTimeVendor
{{ add $index 1 }}{{ with $element.Owner }}{{ .Path }}{{ end }} - {{ $element.Path }} - {{ with $element.Replace }} - => {{ .Path }} - {{ end }} - {{ $element.Version }}{{ with $element.Time }}{{ . }}{{ end }}{{ $element.Vendor }}
-``` diff --git a/content/en/functions/images/index.md b/content/en/functions/images/index.md deleted file mode 100644 index 3b71652cf..000000000 --- a/content/en/functions/images/index.md +++ /dev/null @@ -1,300 +0,0 @@ ---- -title: Image filters -description: The images namespace provides a list of filters and other image related functions. -categories: [functions] -keywords: [] -aliases: [/functions/imageconfig/] -menu: - docs: - parent: functions -keywords: [images] -toc: true ---- - -See [images.Filter](#filter) for how to apply these filters to an image. - -## Process - -{{< new-in "0.119.0" >}} - -{{< funcsig >}} -images.Process SRC SPEC -{{< /funcsig >}} - -A general purpose image processing function. - -This filter has all the same options as the [Process](/content-management/image-processing/#process) method, but using it as a filter may be more effective if you need to apply multiple filters to an image: - -```go-html-template -{{ $filters := slice - images.Grayscale - (images.GaussianBlur 8) - (images.Process "resize 200x jpg q30") -}} -{{ $img = $img | images.Filter $filters }} -``` - -## Overlay - -{{< funcsig >}} -images.Overlay SRC X Y -{{< /funcsig >}} - -Overlay creates a filter that overlays the source image at position x y, e.g: - - -```go-html-template -{{ $logoFilter := (images.Overlay $logo 50 50 ) }} -{{ $img := $img | images.Filter $logoFilter }} -``` - -A shorter version of the above, if you only need to apply the filter once: - -```go-html-template -{{ $img := $img.Filter (images.Overlay $logo 50 50 )}} -``` - -The above will overlay `$logo` in the upper left corner of `$img` (at position `x=50, y=50`). - -## Opacity - -{{< new-in "0.119.0" >}} - -{{< funcsig >}} -images.Opacity SRC OPACITY -{{< /funcsig >}} - -Opacity creates a filter that changes the opacity of an image. -The OPACITY parameter must be in range (0, 1). - -```go-html-template -{{ $img := $img.Filter (images.Opacity 0.5 )}} -``` - -This filter is most useful for target formats that support transparency, e.g. PNG. If the source image is e.g. JPG, the most effective way would be to combine it with the [`Process`] filter: - -```go-html-template -{{ $png := $jpg.Filter - (images.Opacity 0.5) - (images.Process "png") -}} -``` - -## Text - -Using the `Text` filter, you can add text to an image. - -{{< funcsig >}} -images.Text TEXT MAP) -{{< /funcsig >}} - -The following example will add the text `Hugo rocks!` to the image with the specified color, size and position. - -```go-html-template -{{ $img := resources.Get "/images/background.png" }} -{{ $img = $img.Filter (images.Text "Hugo rocks!" (dict - "color" "#ffffff" - "size" 60 - "linespacing" 2 - "x" 10 - "y" 20 -))}} -``` - -You can load a custom font if needed. Load the font as a Hugo `Resource` and set it as an option: - -```go-html-template -{{ $font := resources.GetRemote "https://github.com/google/fonts/raw/main/apache/roboto/static/Roboto-Black.ttf" }} -{{ $img := resources.Get "/images/background.png" }} -{{ $img = $img.Filter (images.Text "Hugo rocks!" (dict - "font" $font -))}} -``` - -## Padding - -Padding creates a filter that resizes the image canvas without resizing the image. The last argument is the canvas color, expressed as an RGB or RGBA [hexadecimal color]. The default value is `ffffffff` (opaque white). The preceding arguments are the padding values, in pixels, using the CSS [shorthand property] syntax. Negative padding values will crop the image. - -[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color -[shorthand property]: https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties#edges_of_a_box - -{{% funcsig %}} -images.Padding V1 [V2] [V3] [V4] [COLOR] -{{% /funcsig %}} - -This example resizes the image to 300px wide, converts it to the WebP format, adds 20px vertical padding and 50px horizontal padding, then sets the canvas color to dark green with 33% opacity. - -```go-html-template -{{ $img := resources.Get "images/a.jpg" }} -{{ $filters := slice - (images.Process "resize 300x webp") - (images.Padding 20 50 "#0705") -}} -{{ $img = $img.Filter $filters }} -``` - -To add a 2px gray border to an image: - -```go-html-template -{{ $img = $img.Filter (images.Padding 2 "#777") }} -``` - -## Brightness - -{{< funcsig >}} -images.Brightness PERCENTAGE -{{< /funcsig >}} - -Brightness creates a filter that changes the brightness of an image. -The percentage parameter must be in range (-100, 100). - -### ColorBalance - -{{< funcsig >}} -images.ColorBalance PERCENTAGERED PERCENTAGEGREEN PERCENTAGEBLUE -{{< /funcsig >}} - -ColorBalance creates a filter that changes the color balance of an image. -The percentage parameters for each color channel (red, green, blue) must be in range (-100, 500). - -## Colorize - -{{< funcsig >}} -images.Colorize HUE SATURATION PERCENTAGE -{{< /funcsig >}} - -Colorize creates a filter that produces a colorized version of an image. -The hue parameter is the angle on the color wheel, typically in range (0, 360). -The saturation parameter must be in range (0, 100). -The percentage parameter specifies the strength of the effect, it must be in range (0, 100). - -## Contrast - -{{< funcsig >}} -images.Contrast PERCENTAGE -{{< /funcsig >}} - -Contrast creates a filter that changes the contrast of an image. -The percentage parameter must be in range (-100, 100). - -## Gamma - -{{< funcsig >}} -images.Gamma GAMMA -{{< /funcsig >}} - -Gamma creates a filter that performs a gamma correction on an image. -The gamma parameter must be positive. Gamma = 1 gives the original image. -Gamma less than 1 darkens the image and gamma greater than 1 lightens it. - -## GaussianBlur - -{{< funcsig >}} -images.GaussianBlur SIGMA -{{< /funcsig >}} - -GaussianBlur creates a filter that applies a gaussian blur to an image. - -## Grayscale - -{{< funcsig >}} -images.Grayscale -{{< /funcsig >}} - -Grayscale creates a filter that produces a grayscale version of an image. - -## Hue - -{{< funcsig >}} -images.Hue SHIFT -{{< /funcsig >}} - -Hue creates a filter that rotates the hue of an image. -The hue angle shift is typically in range -180 to 180. - -## Invert - -{{< funcsig >}} -images.Invert -{{< /funcsig >}} - -Invert creates a filter that negates the colors of an image. - -## Pixelate - -{{< funcsig >}} -images.Pixelate SIZE -{{< /funcsig >}} - -Pixelate creates a filter that applies a pixelation effect to an image. - -## Saturation - -{{< funcsig >}} -images.Saturation PERCENTAGE -{{< /funcsig >}} - -Saturation creates a filter that changes the saturation of an image. - -## Sepia - -{{< funcsig >}} -images.Sepia PERCENTAGE -{{< /funcsig >}} - -Sepia creates a filter that produces a sepia-toned version of an image. - -## Sigmoid - -{{< funcsig >}} -images.Sigmoid MIDPOINT FACTOR -{{< /funcsig >}} - -Sigmoid creates a filter that changes the contrast of an image using a sigmoidal function and returns the adjusted image. -It's a non-linear contrast change useful for photo adjustments as it preserves highlight and shadow detail. - -## UnsharpMask - -{{< funcsig >}} -images.UnsharpMask SIGMA AMOUNT THRESHOLD -{{< /funcsig >}} - -UnsharpMask creates a filter that sharpens an image. -The sigma parameter is used in a gaussian function and affects the radius of effect. -Sigma must be positive. Sharpen radius roughly equals 3 * sigma. -The amount parameter controls how much darker and how much lighter the edge borders become. Typically between 0.5 and 1.5. -The threshold parameter controls the minimum brightness change that will be sharpened. Typically between 0 and 0.05. - -## Other Functions - -### Filter - -{{< funcsig >}} -IMAGE | images.Filter FILTERS... -{{< /funcsig >}} - -Can be used to apply a set of filters to an image: - -```go-html-template -{{ $img := $img | images.Filter (images.GaussianBlur 6) (images.Pixelate 8) }} -``` - -Also see the [Filter Method](/content-management/image-processing/#filter). - -### ImageConfig - -Parses the image and returns the height, width, and color model. - -The `imageConfig` function takes a single parameter, a file path (_string_) relative to the _project's root directory_, with or without a leading slash. - -{{< funcsig >}} -images.ImageConfig PATH -{{< /funcsig >}} - -```go-html-template -{{ with (imageConfig "favicon.ico") }} -favicon.ico: {{ .Width }} x {{ .Height }} -{{ end }} -``` - -[`Process`]: #process From 0dfc00b0f4222f7489c7e1022b57802b2f542b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 5 Dec 2023 16:19:43 +0100 Subject: [PATCH 5/5] docs: Regen docshelper --- data/docs.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/data/docs.yaml b/data/docs.yaml index dc81ad8bc..f59974724 100644 --- a/data/docs.yaml +++ b/data/docs.yaml @@ -19,9 +19,15 @@ chroma: - ada95 - ada2005 Name: Ada + - Aliases: + - agda + Name: Agda - Aliases: - al Name: AL + - Aliases: + - alloy + Name: Alloy - Aliases: - ng2 Name: Angular2 @@ -198,6 +204,9 @@ chroma: - Aliases: - dart Name: Dart + - Aliases: + - dax + Name: Dax - Aliases: - diff - udiff @@ -330,6 +339,9 @@ chroma: - handlebars - hbs Name: Handlebars + - Aliases: + - hare + Name: Hare - Aliases: - haskell - hs @@ -501,6 +513,9 @@ chroma: - obj-c - objc Name: Objective-C + - Aliases: + - objectpascal + Name: ObjectPascal - Aliases: - ocaml Name: OCaml