Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc edits #2853

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions content/en/functions/crypto/FNV32a.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ categories: []
keywords: []
action:
aliases: []
related:
- functions/hash/Xxhash
- functions/crypto/HMAC
- functions/crypto/MD5
- functions/crypto/SHA1
- functions/crypto/SHA256
related: []
returnType: int
signatures: [crypto.FNV32a STRING]
expiryDate: 2025-07-31 # deprecated 2024-07-31
Expand Down
6 changes: 1 addition & 5 deletions content/en/functions/data/GetCSV.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ categories: []
keywords: []
action:
aliases: [getCSV]
related:
- functions/data/GetJSON
- functions/resources/Get
- functions/resources/GetRemote
- methods/page/Resources
related: []
returnType: '[][]string'
signatures: ['data.GetCSV SEPARATOR INPUT... [OPTIONS]']
toc: true
Expand Down
6 changes: 1 addition & 5 deletions content/en/functions/data/GetJSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ categories: []
keywords: []
action:
aliases: [getJSON]
related:
- functions/data/GetCSV
- functions/resources/Get
- functions/resources/GetRemote
- methods/page/Resources
related: []
returnType: any
signatures: ['data.GetJSON INPUT... [OPTIONS]']
toc: true
Expand Down
2 changes: 1 addition & 1 deletion content/en/functions/js/Babel.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: js.Babel
description: Compiles the given JavaScript resource with Babel.
description: Compile the given JavaScript resource with Babel.
categories: []
keywords: []
action:
Expand Down
2 changes: 1 addition & 1 deletion content/en/functions/js/Build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: js.Build
description: Bundles, transpiles, tree shakes, and minifies JavaScript resources.
description: Bundle, transpile, tree shake, and minify JavaScript resources.
categories: []
keywords: []
action:
Expand Down
6 changes: 1 addition & 5 deletions content/en/functions/resources/Babel.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ description: Compiles the given JavaScript resource with Babel.
categories: []
keywords: []
action:
related:
- functions/js/Batch
- functions/js/Build
- functions/resources/Fingerprint
- functions/resources/Minify
related: []
returnType: resource.Resource
signatures: ['resources.Babel [OPTIONS] RESOURCE']
toc: true
Expand Down
6 changes: 1 addition & 5 deletions content/en/functions/resources/PostCSS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ description: Processes the given resource with PostCSS using any PostCSS plugin.
categories: []
keywords: []
action:
related:
- functions/resources/Fingerprint
- functions/resources/Minify
- functions/resources/PostProcess
- functions/css/Sass
related: []
returnType: resource.Resource
signatures: ['resources.PostCSS [OPTIONS] RESOURCE']
toc: true
Expand Down
2 changes: 1 addition & 1 deletion content/en/functions/resources/PostProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Call `resources.PostProcess` when one or more of the steps in the transformation

A prime use case for this is purging unused CSS rules using the [PurgeCSS] plugin for the PostCSS Node.js package.

## CSS Purging
## CSS purging

{{% note %}}
There are several ways to set up CSS purging with PostCSS in Hugo. If you have a simple project, you should consider going the simpler route and drop the use of `resources.PostProcess` and just extract keywords from the templates. See the [Tailwind documentation](https://tailwindcss.com/docs/controlling-file-size/#app) for examples.
Expand Down
6 changes: 1 addition & 5 deletions content/en/functions/resources/ToCSS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ description: Transpiles Sass to CSS.
categories: []
keywords: []
action:
related:
- functions/resources/Fingerprint
- functions/resources/Minify
- functions/css/PostCSS
- functions/resources/PostProcess
related: []
returnType: resource.Resource
signatures: ['resources.ToCSS [OPTIONS] RESOURCE']
toc: true
Expand Down
2 changes: 1 addition & 1 deletion content/en/getting-started/configuration-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ target

If `enable` is set to `true`, creates a `hugo_stats.json` file in the root of your project. This file contains arrays of the `class` attributes, `id` attributes, and tags of every HTML element within your published site. Use this file as data source when [removing unused CSS] from your site. This process is also known as pruning, purging, or tree shaking.

[removing unused CSS]: /hugo-pipes/postprocess/#css-purging-with-postcss
[removing unused CSS]: /functions/resources/postprocess/#css-purging

Exclude `class` attributes, `id` attributes, or tags from `hugo_stats.json` with the `disableClasses`, `disableIDs`, and `disableTags` keys.

Expand Down
14 changes: 1 addition & 13 deletions content/en/hugo-pipes/bundling.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ menu:
parent: hugo-pipes
weight: 90
weight: 90
action:
aliases: []
returnType: resource.Resource
signatures: ['resources.Concat TARGETPATH [RESOURCE...]']
---

## Usage

Asset files of the same MIME type can be bundled into one resource using `resources.Concat` which takes two arguments, the target path for the created resource bundle and a slice of resource objects to be concatenated.

```go-html-template
{{ $plugins := resources.Get "js/plugins.js" }}
{{ $global := resources.Get "js/global.js" }}
{{ $js := slice $plugins $global | resources.Concat "js/bundle.js" }}
```
See the [`resources.Concat`](/functions/resources/concat/) function.
20 changes: 2 additions & 18 deletions content/en/hugo-pipes/fingerprint.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
---
title: Fingerprint
linkTitle: Fingerprinting and SRI hashing
description: Process a given resource, adding a hash string of the resource's content.
description: Cryptographically hash the content of the given resource.
categories: [asset management]
keywords: []
menu:
docs:
parent: hugo-pipes
weight: 100
weight: 100
action:
aliases: [fingerprint]
returnType: resource.Resource
signatures: ['resources.Fingerprint [ALGORITHM] RESOURCE']
---

## Usage

Fingerprinting and [SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) can be applied to any asset file using `resources.Fingerprint` which takes two arguments, the resource object and an optional [hash algorithm](https://en.wikipedia.org/wiki/Secure_Hash_Algorithms).

The default hash algorithm is `sha256`. Other available algorithms are `sha384` and (as of Hugo `0.55`) `sha512` and `md5`.

Any so processed asset will bear a `.Data.Integrity` property containing an integrity string, which is made up of the name of the hash algorithm, one hyphen and the base64-encoded hash sum.

```go-html-template
{{ $js := resources.Get "js/global.js" }}
{{ $secureJS := $js | resources.Fingerprint "sha512" }}
<script src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
```
See the [`resources.Fingerprint`](/functions/resources/fingerprint/) function.
17 changes: 2 additions & 15 deletions content/en/hugo-pipes/minification.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
---
title: Minify
linkTitle: Asset minification
description: Minifies a given resource.
description: Minify a given resource.
categories: [asset management]
keywords: []
menu:
docs:
parent: hugo-pipes
weight: 80
weight: 80
action:
aliases: [minify]
returnType: resource.Resource
signatures: [resources.Minify RESOURCE]
---

## Usage

Any CSS, JS, JSON, HTML, SVG, or XML resource can be minified using `resources.Minify` which takes for argument the resource object.

```go-html-template
{{ $css := resources.Get "css/main.css" }}
{{ $style := $css | resources.Minify }}
```

Note that you can also minify the final HTML output to `/public` by running `hugo --minify`.
See the [`resources.Minify`](/functions/resources/minify/) function.
122 changes: 2 additions & 120 deletions content/en/hugo-pipes/postcss.md
Original file line number Diff line number Diff line change
@@ -1,131 +1,13 @@
---
title: PostCSS
description: Process CSS files with PostCSS, using any of the available plugins.
description: Process the given resource with PostCSS using any PostCSS plugin.
categories: [asset management]
keywords: []
menu:
docs:
parent: hugo-pipes
weight: 40
weight: 40
toc: true
action:
aliases: [postCSS]
returnType: resource.Resource
signatures: ['css.PostCSS [OPTIONS] RESOURCE']
---

## Setup

Follow the steps below to transform CSS using any of the [available PostCSS plugins](https://www.postcss.parts/).

Step 1
: Install [Node.js](https://nodejs.org/en/download).

Step 2
: Install the required Node.js packages in the root of your project. For example, to add vendor prefixes to CSS rules:

```sh
npm i -D postcss postcss-cli autoprefixer
```

Step 3
: Create a PostCSS configuration file in the root of your project. You must name this file `postcss.config.js` or one of the other [supported file names]. For example:

[supported file names]: https://github.com/postcss/postcss-load-config#usage

{{< code file=postcss.config.js >}}
module.exports = {
plugins: [
require('autoprefixer')
]
};
{{< /code >}}

{{% note %}}
If you are a Windows user, and the path to your project contains a space, you must place the PostCSS configuration within the package.json file. See [this example](https://github.com/postcss/postcss-load-config#packagejson) and issue [#7333](https://github.com/gohugoio/hugo/issues/7333).
{{% /note %}}

Step 4
: Place your CSS file within the `assets` directory.

Step 5
: Capture the CSS file as a resource and pipe it through `css.PostCSS` (alias `postCSS`):

{{< code file=layouts/partials/css.html >}}
{{ with resources.Get "css/main.css" | postCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{< /code >}}

If starting with a Sass file within the `assets` directory:

{{< code file=layouts/partials/css.html >}}
{{ with resources.Get "sass/main.scss" | toCSS | postCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{< /code >}}

## Options

The `css.PostCSS` method takes an optional map of options.

config
: (`string`) The directory that contains the PostCSS configuration file. Default is the root of the project directory.

noMap
: (`bool`) Default is `false`. If `true`, disables inline sourcemaps.

inlineImports
: (`bool`) Default is `false`. Enable inlining of @import statements. It does so recursively, but will only import a file once.
URL imports (e.g. `@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');`) and imports with media queries will be ignored.
Note that this import routine does not care about the CSS spec, so you can have @import anywhere in the file.
Hugo will look for imports relative to the module mount and will respect theme overrides.

skipInlineImportsNotFound
: (`bool`) Default is `false`. If you have regular CSS imports in your CSS that you want to preserve, you can either use imports with URL or media queries (Hugo does not try to resolve those) or set `skipInlineImportsNotFound` to true.

{{< code file=layouts/partials/css.html >}}
{{ $opts := dict "config" "config-directory" "noMap" true }}
{{ with resources.Get "css/main.css" | postCSS $opts }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{< /code >}}

## No configuration file

To avoid using a PostCSS configuration file, you can specify a minimal configuration using the options map.

use
: (`string`) A space-delimited list of PostCSS plugins to use.

parser
: (`string`) A custom PostCSS parser.

stringifier
: (`string`) A custom PostCSS stringifier.

syntax
: (`string`) Custom postcss syntax.

{{< code file=layouts/partials/css.html >}}
{{ $opts := dict "use" "autoprefixer postcss-color-alpha" }}
{{ with resources.Get "css/main.css" | postCSS $opts }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{< /code >}}

## Check Hugo environment

The current Hugo environment name (set by `--environment` or in configuration or OS environment) is available in the Node context, which allows constructs like this:

{{< code file=postcss.config.js >}}
module.exports = {
plugins: [
require('autoprefixer'),
...process.env.HUGO_ENVIRONMENT === 'production'
? [purgecss]
: []
]
}
{{< /code >}}
See the [`css.PostCSS`](/functions/css/postcss/) function.
Loading