mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-26 00:08:53 +00:00
Compare commits
185 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 76a5e1880a | |||
| 0bb337b22a | |||
| 03dc9170b3 | |||
| c829b736cc | |||
| 995a2159e5 | |||
| f88f0a9f59 | |||
| dd3f2731e0 | |||
| f772998fa3 | |||
| 8a55df7af2 | |||
| 52c9bd7908 | |||
| 44da086082 | |||
| 2ffaf1fc1e | |||
| a808f6e40d | |||
| 94f3908ec6 | |||
| 75fcc7524a | |||
| 33d1f2c853 | |||
| 64da6d7c62 | |||
| 70db201ed4 | |||
| 8a468df065 | |||
| b5fa03d3aa | |||
| 9da472dd3b | |||
| 615e45d6e8 | |||
| 635532a20f | |||
| a243a6154c | |||
| 9c71f600bf | |||
| 420527fc6b | |||
| 7fe786e3b0 | |||
| 03b244fc0b | |||
| 961181334f | |||
| e35b7f049d | |||
| 7d90277a28 | |||
| 0796fa7ace | |||
| 6bf15241a1 | |||
| 861ede6d10 | |||
| f228c87d41 | |||
| 1b701b72ca | |||
| a32d70b712 | |||
| 948cfb98f9 | |||
| 8930802ef2 | |||
| 7df45f615a | |||
| f961093ea9 | |||
| 89b8c32200 | |||
| 984358f047 | |||
| d1f191c58d | |||
| a198116669 | |||
| ce2470e701 | |||
| 921db7b52c | |||
| 786ce71e59 | |||
| 5ad2846161 | |||
| 36ad9f583a | |||
| 7c0a0bc979 | |||
| d83ce27ae0 | |||
| 5a5f4a5495 | |||
| c6acc246ab | |||
| 29ed932513 | |||
| 7b4ddd1863 | |||
| 671897ae91 | |||
| a879ebfaaa | |||
| 499794d19e | |||
| feb3d494b9 | |||
| 65c82178b7 | |||
| 332d5ec823 | |||
| 212cc11ada | |||
| dfb35dcd7a | |||
| ef053faa6a | |||
| af91eb1997 | |||
| a5ec542393 | |||
| 884439b9a2 | |||
| 128fb17c2b | |||
| e46d37a984 | |||
| 790a8aa474 | |||
| fe06735214 | |||
| d15baf53a9 | |||
| 4d22555aeb | |||
| ce1a7e0bce | |||
| c86d9f4aa8 | |||
| e8988c3141 | |||
| 70a9068aa6 | |||
| 9d66d513ce | |||
| f013346667 | |||
| 96e06e1ab8 | |||
| 19a5cec0b9 | |||
| 134674f00d | |||
| 147f605f7d | |||
| 1f35beb918 | |||
| 2a4fd58818 | |||
| 93c8c7d345 | |||
| 95e5e9f4ab | |||
| a00b5c72ac | |||
| cf9c8f93ca | |||
| 11f09f59fc | |||
| 2602796cf1 | |||
| 72495f9fba | |||
| 4a9485336a | |||
| 1d018ef857 | |||
| 121bc6ceb2 | |||
| 0d29fc81bb | |||
| bb57404f3d | |||
| 781fabf4e4 | |||
| cf18b827e2 | |||
| 98ad9b3c03 | |||
| ff2903a931 | |||
| 7d1b1fb33d | |||
| b89e7fe675 | |||
| e8fefc8388 | |||
| a043d3ec63 | |||
| 77a1147056 | |||
| 341f575d2d | |||
| 248241b6e1 | |||
| 4e47d95db9 | |||
| 03b4b54220 | |||
| 79be0532f1 | |||
| 0f440460c8 | |||
| 4e17421ec2 | |||
| b01ecd4cd4 | |||
| ca68936d61 | |||
| 45c00b7c16 | |||
| 28d882ab70 | |||
| b0fd7ee2e1 | |||
| bba860e3ed | |||
| 59f35cd985 | |||
| 21e9868fe2 | |||
| 2760288c6d | |||
| c270975049 | |||
| ea8b48af64 | |||
| 076dfe13d0 | |||
| e41a06447d | |||
| 90d9f812b2 | |||
| 80e60847fb | |||
| df5421918a | |||
| aeb9a5cc02 | |||
| c4bbc2805c | |||
| d8c70218b7 | |||
| ee4f1acd93 | |||
| b6133657e0 | |||
| 4bc7caea14 | |||
| 7711ba4d0c | |||
| d2c821b5c7 | |||
| 4f444c810c | |||
| fe6c72652f | |||
| 4ed7600fd6 | |||
| cbe4339a5f | |||
| 6475d308ec | |||
| 67aede4364 | |||
| 87f194b249 | |||
| 5f01b0603d | |||
| c23d97904f | |||
| 5d51b82a7e | |||
| d81e3c29c0 | |||
| 7c65a4dbc0 | |||
| d31a9275c6 | |||
| 6a2a03806d | |||
| cf1de598d9 | |||
| c36608c584 | |||
| 1e4037cade | |||
| 2f361a8e25 | |||
| 81d77620c6 | |||
| 5559263326 | |||
| 97f990cc4f | |||
| 656fc04035 | |||
| a20cb5b1c0 | |||
| b99634e253 | |||
| 4d775cbe95 | |||
| fdd977e95d | |||
| ae7bf74b3e | |||
| 123018de21 | |||
| ba5d812673 | |||
| be4a0df3a2 | |||
| e4cf565c0d | |||
| 9e64953338 | |||
| f0cfc28c00 | |||
| 16e854a437 | |||
| f8b5fa09a6 | |||
| 86fbb0f7a8 | |||
| 7d4af7a179 | |||
| 28147cb040 | |||
| db40fada48 | |||
| b88fa8cc66 | |||
| 88d838a971 | |||
| e51e761d9c | |||
| 7011239205 | |||
| 694906f6f1 | |||
| d27b9c06bd | |||
| 62cef3678b | |||
| ff22c62a32 |
@@ -4,7 +4,7 @@ parameters:
|
||||
defaults: &defaults
|
||||
resource_class: large
|
||||
docker:
|
||||
- image: bepsays/ci-hugoreleaser:1.22600.20100
|
||||
- image: bepsays/ci-hugoreleaser:1.22600.20500
|
||||
environment: &buildenv
|
||||
GOMODCACHE: /root/project/gomodcache
|
||||
version: 2
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
environment:
|
||||
<<: [*buildenv]
|
||||
docker:
|
||||
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22600.20100
|
||||
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22600.20500
|
||||
steps:
|
||||
- *restore-cache
|
||||
- &attach-workspace
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
have_fun: false
|
||||
memory_config:
|
||||
disabled: false
|
||||
code_review:
|
||||
disable: false
|
||||
comment_severity_threshold: HIGH
|
||||
max_review_comments: -1
|
||||
pull_request_opened:
|
||||
help: true
|
||||
summary: false
|
||||
code_review: false
|
||||
include_drafts: false
|
||||
ignore_patterns: []
|
||||
@@ -16,8 +16,8 @@ jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.25.x, 1.26.x]
|
||||
os: [ubuntu-latest, windows-latest] # macos disabled for now because of disk space issues.
|
||||
go-version: [1.26.x]
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
@@ -39,9 +39,6 @@ jobs:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
check-latest: true
|
||||
cache: true
|
||||
cache-dependency-path: |
|
||||
**/go.sum
|
||||
**/go.mod
|
||||
- name: Install Node
|
||||
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
||||
with:
|
||||
@@ -54,6 +51,7 @@ jobs:
|
||||
run: |
|
||||
gem install asciidoctor -v "2.0.26"
|
||||
gem install asciidoctor-diagram -v "3.1.0"
|
||||
gem install asciidoctor-html5s -v "0.5.1"
|
||||
- name: Install GoAT
|
||||
run: go install github.com/blampe/goat/cmd/goat@177de93b192b8ffae608e5d9ec421cc99bf68402
|
||||
- name: Install Python
|
||||
@@ -62,9 +60,11 @@ jobs:
|
||||
python-version: "3.x"
|
||||
- name: Install Mage
|
||||
run: go install github.com/magefile/mage@v1.15.0
|
||||
- name: Install gotmplfmt
|
||||
run: go install github.com/gohugoio/gotmplfmt@latest
|
||||
- name: Install docutils
|
||||
run: |
|
||||
pip install docutils
|
||||
pip install docutils Pygments
|
||||
rst2html --version
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Install pandoc on Linux
|
||||
@@ -108,6 +108,9 @@ jobs:
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Install staticcheck
|
||||
run: go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Check embedded go template formatting
|
||||
run: "diff <(gotmplfmt -d tpl/tplimpl/embedded/templates) <(printf '')"
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Run staticcheck
|
||||
run: |
|
||||
|
||||
+3
-1
@@ -4,4 +4,6 @@ imports.*
|
||||
dist/
|
||||
public/
|
||||
.DS_Store
|
||||
cache/filecache/_gen/
|
||||
cache/filecache/_gen/
|
||||
.claude/
|
||||
dump.txt
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
* Brevity is good.
|
||||
* Assume that the maintainers and readers of the code you write are Go experts:
|
||||
* Don't use comments to explain the obvious.
|
||||
@@ -7,9 +8,12 @@
|
||||
* Never export symbols that's not needed outside of the package.
|
||||
* Avoid global state at (almost) all cost.
|
||||
* This is a project with a long history; assume that a similiar problem has been solved before, look hard for helper functions before creating new ones.
|
||||
* In tests, almost always write end-to-end integration tests using `hugolib.Test` or one of its siblings. Write unit tests only for isolated utilities.
|
||||
* In tests, use `qt` matchers (e.g. `b.Assert(err, qt.ErrorMatches, ...)`) instead of raw `if`/`t.Fatal` checks.
|
||||
* In tests, always use the latest Hugo specification, e.g. for layouts, it's `layouts/page.html` and not `layouts/_default/single.html`, `layouts/list.html` and not `layouts/_default/list.html`
|
||||
* Never name tests `TestIssue1234`; if this e.g. is about fixing an issue, use the issue ID as a suffix, as in `TestUpperCaseTitlesCreatesHavocIssue1234`. And note: No underscores in func names.
|
||||
* Never name tests `TestIssue1234`; always give the test function a descriptive name, e.g. `TestDisablePathToLower`, and add any issue reference as a Go doc function comment, e.g. `// See issue 1234.`.
|
||||
* If you borrow a test case (e.g. from the issue), that test's author must be added as co-author in the commit.
|
||||
* If you're a security researcher, read @SECURITY.md carefully.
|
||||
* Brevity is good. This applies to code, comments and commit messages. Don't write a novel.
|
||||
* Use `./check.sh ./somepackage/...` when iterating.
|
||||
* Use `./check.sh` when you're done.
|
||||
|
||||
+6
-4
@@ -1,5 +1,3 @@
|
||||
>**Note:** We would appreciate if you hold on with any big refactoring (like renaming deprecated Go packages), mainly because of potential for extra merge work for future coming in in the near future.
|
||||
|
||||
# Contributing to Hugo
|
||||
|
||||
We welcome contributions to Hugo of any kind including documentation, themes,
|
||||
@@ -74,6 +72,7 @@ To make the contribution process as seamless as possible, we ask for the followi
|
||||
* When you’re ready to create a pull request, be sure to:
|
||||
* Sign the [CLA](https://cla-assistant.io/gohugoio/hugo).
|
||||
* Have test cases for the new code. If you have questions about how to do this, please ask in your pull request.
|
||||
* If you borrow a test case (e.g. from the issue), that test's author must be added as [co-author](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) in the commit.
|
||||
* Run `go fmt`.
|
||||
* Add documentation if you are adding new features or changing functionality. The docs site lives in `/docs`.
|
||||
* Squash your commits into a single commit. `git rebase -i`. It’s okay to force update your pull request with `git push -f`.
|
||||
@@ -82,13 +81,16 @@ To make the contribution process as seamless as possible, we ask for the followi
|
||||
|
||||
## AI Assistance Notice
|
||||
|
||||
If a substantial part of your contribution is autogenerated with AI, **this must be disclosed in the pull request**, along with the extent to which AI assistance was used.
|
||||
If a substantial part of your contribution is autogenerated with AI, **this must be disclosed in the pull request**, along with the extent to which AI assistance was used. AI contributions from non-maintainers needs to have a fairly narrow scope (e.g. a bug fix), as we have limited review capacity.
|
||||
|
||||
An example disclosure:
|
||||
|
||||
> This PR was written primarily by Claude Code.
|
||||
|
||||
When using AI assistance, we expect contributors to understand the code that is produced and be able to answer critical questions about it. Also, AI contributions from non-maintainers needs to have a fairly narrow scope (e.g. a bug fix), as we have limited review capacity.
|
||||
Also, When using AI assistance:
|
||||
|
||||
* We expect contributors to manually verify that the state of the pull request is OK (e.g. that the CLI is signed).
|
||||
* We expect contributors to understand the code that is produced and be able to answer critical questions about it
|
||||
|
||||
### Git Commit Message Guidelines
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ A fast and flexible static site generator built with love by [bep][], [spf13][],
|
||||
|
||||
[](https://godoc.org/github.com/gohugoio/hugo)
|
||||
[](https://github.com/gohugoio/hugo/actions?query=workflow%3ATest)
|
||||
[](https://goreportcard.com/report/github.com/gohugoio/hugo)
|
||||
|
||||
[Website][] | [Installation][] | [Documentation][] | [Support][] | [Contributing][] | <a rel="me" href="https://fosstodon.org/@gohugoio">Mastodon</a>
|
||||
|
||||
@@ -105,7 +104,7 @@ Install Hugo from a [prebuilt binary][], package manager, or package repository.
|
||||
To build Hugo from source you must install:
|
||||
|
||||
1. [Git][]
|
||||
1. [Go][] version 1.25.0 or later
|
||||
1. [Go][] version 1.26.0 or later
|
||||
|
||||
### Standard edition
|
||||
|
||||
@@ -139,10 +138,6 @@ To build and install the extended/deploy edition, first install a C compiler suc
|
||||
CGO_ENABLED=1 go install -tags extended,withdeploy github.com/gohugoio/hugo@latest
|
||||
```
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#gohugoio/hugo&Timeline)
|
||||
|
||||
## Documentation
|
||||
|
||||
Hugo's [documentation][] includes installation instructions, a quick start guide, conceptual explanations, reference information, and examples.
|
||||
@@ -195,10 +190,48 @@ Hugo stands on the shoulders of great open source libraries. Run `hugo env --log
|
||||
<summary>See current dependencies</summary>
|
||||
|
||||
```text
|
||||
cel.dev/expr="v0.25.1"
|
||||
cloud.google.com/go/auth/oauth2adapt="v0.2.8"
|
||||
cloud.google.com/go/auth="v0.20.0"
|
||||
cloud.google.com/go/compute/metadata="v0.9.0"
|
||||
cloud.google.com/go/iam="v1.5.3"
|
||||
cloud.google.com/go/monitoring="v1.24.3"
|
||||
cloud.google.com/go/storage="v1.57.2"
|
||||
cloud.google.com/go="v0.123.0"
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore="v1.20.0"
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity="v1.13.1"
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal="v1.11.2"
|
||||
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob="v1.6.3"
|
||||
github.com/Azure/go-autorest/autorest/to="v0.4.1"
|
||||
github.com/AzureAD/microsoft-authentication-library-for-go="v1.6.0"
|
||||
github.com/BurntSushi/locker="v0.0.0-20171006230638-a6e239ea1c69"
|
||||
github.com/JohannesKaufmann/dom="v0.2.0"
|
||||
github.com/JohannesKaufmann/html-to-markdown/v2="v2.5.0"
|
||||
github.com/alecthomas/chroma/v2="v2.21.1"
|
||||
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp="v1.31.0"
|
||||
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric="v0.54.0"
|
||||
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping="v0.54.0"
|
||||
github.com/JohannesKaufmann/dom="v0.3.1"
|
||||
github.com/JohannesKaufmann/html-to-markdown/v2="v2.5.2"
|
||||
github.com/alecthomas/chroma/v2="v2.27.0"
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream="v1.7.8"
|
||||
github.com/aws/aws-sdk-go-v2/config="v1.32.2"
|
||||
github.com/aws/aws-sdk-go-v2/credentials="v1.19.2"
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds="v1.18.14"
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager="v1.20.12"
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources="v1.4.22"
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2="v2.7.22"
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini="v1.8.4"
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a="v1.4.22"
|
||||
github.com/aws/aws-sdk-go-v2/service/cloudfront="v1.61.1"
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding="v1.13.7"
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum="v1.9.13"
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url="v1.13.21"
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared="v1.19.21"
|
||||
github.com/aws/aws-sdk-go-v2/service/s3="v1.97.3"
|
||||
github.com/aws/aws-sdk-go-v2/service/signin="v1.0.2"
|
||||
github.com/aws/aws-sdk-go-v2/service/sso="v1.30.5"
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc="v1.35.10"
|
||||
github.com/aws/aws-sdk-go-v2/service/sts="v1.41.2"
|
||||
github.com/aws/aws-sdk-go-v2="v1.41.6"
|
||||
github.com/aws/smithy-go="v1.25.0"
|
||||
github.com/aymerick/douceur="v0.2.0"
|
||||
github.com/bep/clocks="v0.5.0"
|
||||
github.com/bep/debounce="v1.2.0"
|
||||
@@ -206,105 +239,129 @@ github.com/bep/gitmap="v1.9.0"
|
||||
github.com/bep/goat="v0.5.0"
|
||||
github.com/bep/godartsass/v2="v2.5.0"
|
||||
github.com/bep/golibsass="v1.2.0"
|
||||
github.com/bep/goportabletext="v0.1.0"
|
||||
github.com/bep/helpers="v0.6.0"
|
||||
github.com/bep/imagemeta="v0.12.0"
|
||||
github.com/bep/lazycache="v0.8.0"
|
||||
github.com/bep/golocales="v0.2.0"
|
||||
github.com/bep/goportabletext="v0.2.0"
|
||||
github.com/bep/helpers="v0.12.0"
|
||||
github.com/bep/imagemeta="v0.17.2"
|
||||
github.com/bep/lazycache="v0.8.1"
|
||||
github.com/bep/logg="v0.4.0"
|
||||
github.com/bep/mclib="v1.20400.20402"
|
||||
github.com/bep/overlayfs="v0.10.0"
|
||||
github.com/bep/simplecobra="v0.6.1"
|
||||
github.com/bep/textandbinarywriter="v0.0.0-20251212174530-cd9f0732f60f"
|
||||
github.com/bep/tmc="v0.5.1"
|
||||
github.com/bits-and-blooms/bitset="v1.24.4"
|
||||
github.com/bep/mclib="v1.20401.20400"
|
||||
github.com/bep/overlayfs="v0.11.0"
|
||||
github.com/bep/simplecobra="v0.7.0"
|
||||
github.com/bep/textandbinarywriter="v0.1.0"
|
||||
github.com/bep/tmc="v0.6.0"
|
||||
github.com/bits-and-blooms/bitset="v1.24.5"
|
||||
github.com/cespare/xxhash/v2="v2.3.0"
|
||||
github.com/clbanning/mxj/v2="v2.7.0"
|
||||
github.com/clipperhouse/displaywidth="v0.6.0"
|
||||
github.com/clipperhouse/stringish="v0.1.1"
|
||||
github.com/clipperhouse/uax29/v2="v2.3.0"
|
||||
github.com/clipperhouse/displaywidth="v0.10.0"
|
||||
github.com/clipperhouse/uax29/v2="v2.6.0"
|
||||
github.com/cncf/xds/go="v0.0.0-20251210132809-ee656c7534f5"
|
||||
github.com/cpuguy83/go-md2man/v2="v2.0.6"
|
||||
github.com/disintegration/gift="v1.2.1"
|
||||
github.com/dlclark/regexp2="v1.11.5"
|
||||
github.com/evanw/esbuild="v0.27.2"
|
||||
github.com/dlclark/regexp2/v2="v2.2.1"
|
||||
github.com/dustin/go-humanize="v1.0.1"
|
||||
github.com/envoyproxy/go-control-plane/envoy="v1.36.0"
|
||||
github.com/envoyproxy/protoc-gen-validate="v1.3.0"
|
||||
github.com/evanw/esbuild="v0.28.1"
|
||||
github.com/fatih/color="v1.18.0"
|
||||
github.com/felixge/httpsnoop="v1.0.4"
|
||||
github.com/frankban/quicktest="v1.14.6"
|
||||
github.com/fsnotify/fsnotify="v1.9.0"
|
||||
github.com/getkin/kin-openapi="v0.133.0"
|
||||
github.com/go-openapi/jsonpointer="v0.21.0"
|
||||
github.com/go-openapi/swag="v0.23.0"
|
||||
github.com/getkin/kin-openapi="v0.140.0"
|
||||
github.com/go-jose/go-jose/v4="v4.1.4"
|
||||
github.com/go-logr/logr="v1.4.3"
|
||||
github.com/go-logr/stdr="v1.2.2"
|
||||
github.com/go-openapi/jsonpointer="v0.22.5"
|
||||
github.com/go-openapi/swag/jsonname="v0.25.5"
|
||||
github.com/gobuffalo/flect="v1.0.3"
|
||||
github.com/gobwas/glob="v0.2.3"
|
||||
github.com/goccy/go-yaml="v1.19.1"
|
||||
github.com/goccy/go-yaml="v1.19.2"
|
||||
github.com/gohugoio/gift="v0.2.0"
|
||||
github.com/gohugoio/go-i18n/v2="v2.1.3-0.20251018145728-cfcc22d823c6"
|
||||
github.com/gohugoio/go-radix="v1.2.0"
|
||||
github.com/gohugoio/hashstructure="v0.6.0"
|
||||
github.com/gohugoio/httpcache="v0.8.0"
|
||||
github.com/gohugoio/hugo-goldmark-extensions/extras="v0.5.0"
|
||||
github.com/gohugoio/hugo-goldmark-extensions/passthrough="v0.3.1"
|
||||
github.com/gohugoio/locales="v0.14.0"
|
||||
github.com/gohugoio/localescompressed="v1.0.1"
|
||||
github.com/gohugoio/hugo-goldmark-extensions/extras="v0.7.0"
|
||||
github.com/gohugoio/hugo-goldmark-extensions/passthrough="v0.5.0"
|
||||
github.com/golang-jwt/jwt/v5="v5.3.0"
|
||||
github.com/google/go-cmp="v0.7.0"
|
||||
github.com/google/s2a-go="v0.1.9"
|
||||
github.com/google/uuid="v1.6.0"
|
||||
github.com/google/wire="v0.7.0"
|
||||
github.com/googleapis/enterprise-certificate-proxy="v0.3.14"
|
||||
github.com/googleapis/gax-go/v2="v2.21.0"
|
||||
github.com/gorilla/css="v1.0.1"
|
||||
github.com/gorilla/websocket="v1.5.3"
|
||||
github.com/hairyhenderson/go-codeowners="v0.7.0"
|
||||
github.com/hashicorp/golang-lru/v2="v2.0.7"
|
||||
github.com/jdkato/prose="v1.2.1"
|
||||
github.com/josharian/intern="v1.0.0"
|
||||
github.com/kr/pretty="v0.3.1"
|
||||
github.com/kr/text="v0.2.0"
|
||||
github.com/kylelemons/godebug="v1.1.0"
|
||||
github.com/kyokomi/emoji/v2="v2.2.13"
|
||||
github.com/mailru/easyjson="v0.7.7"
|
||||
github.com/makeworld-the-better-one/dither/v2="v2.4.0"
|
||||
github.com/marekm4/color-extractor="v1.2.1"
|
||||
github.com/mattn/go-colorable="v0.1.13"
|
||||
github.com/mattn/go-isatty="v0.0.20"
|
||||
github.com/mattn/go-colorable="v0.1.14"
|
||||
github.com/mattn/go-isatty="v0.0.22"
|
||||
github.com/mattn/go-runewidth="v0.0.19"
|
||||
github.com/microcosm-cc/bluemonday="v1.0.27"
|
||||
github.com/mitchellh/mapstructure="v1.5.1-0.20231216201459-8508981c8b6c"
|
||||
github.com/mohae/deepcopy="v0.0.0-20170929034955-c48cc78d4826"
|
||||
github.com/muesli/smartcrop="v0.3.0"
|
||||
github.com/niklasfasching/go-org="v1.9.1"
|
||||
github.com/oasdiff/yaml3="v0.0.0-20250309153720-d2182401db90"
|
||||
github.com/oasdiff/yaml="v0.0.0-20250309154309-f31be36b4037"
|
||||
github.com/oasdiff/yaml3="v0.0.13"
|
||||
github.com/oasdiff/yaml="v0.1.0"
|
||||
github.com/olekukonko/cat="v0.0.0-20250911104152-50322a0618f6"
|
||||
github.com/olekukonko/errors="v1.1.0"
|
||||
github.com/olekukonko/ll="v0.1.3"
|
||||
github.com/olekukonko/tablewriter="v1.1.2"
|
||||
github.com/olekukonko/errors="v1.2.0"
|
||||
github.com/olekukonko/ll="v0.1.6"
|
||||
github.com/olekukonko/tablewriter="v1.1.4"
|
||||
github.com/pbnjay/memory="v0.0.0-20210728143218-7b4eea64cf58"
|
||||
github.com/pelletier/go-toml/v2="v2.2.4"
|
||||
github.com/perimeterx/marshmallow="v1.1.5"
|
||||
github.com/pelletier/go-toml/v2="v2.4.3"
|
||||
github.com/pkg/browser="v0.0.0-20240102092130-5ac0b6a4141c"
|
||||
github.com/pkg/errors="v0.9.1"
|
||||
github.com/rogpeppe/go-internal="v1.14.1"
|
||||
github.com/rogpeppe/go-internal="v1.15.0"
|
||||
github.com/russross/blackfriday/v2="v2.1.0"
|
||||
github.com/sass/dart-sass/compiler="1.97.1"
|
||||
github.com/sass/dart-sass/implementation="1.97.1"
|
||||
github.com/sass/dart-sass/protocol="3.2.0"
|
||||
github.com/santhosh-tekuri/jsonschema/v6="v6.0.2"
|
||||
github.com/spf13/afero="v1.15.0"
|
||||
github.com/spf13/cast="v1.10.0"
|
||||
github.com/spf13/cobra="v1.10.2"
|
||||
github.com/spf13/fsync="v0.10.1"
|
||||
github.com/spf13/pflag="v1.0.9"
|
||||
github.com/tdewolff/minify/v2="v2.24.8"
|
||||
github.com/tdewolff/parse/v2="v2.8.5"
|
||||
github.com/tetratelabs/wazero="v1.10.1"
|
||||
github.com/spf13/pflag="v1.0.10"
|
||||
github.com/spiffe/go-spiffe/v2="v2.6.0"
|
||||
github.com/tdewolff/minify/v2="v2.24.13"
|
||||
github.com/tdewolff/parse/v2="v2.8.12"
|
||||
github.com/tetratelabs/wazero="v1.12.0"
|
||||
github.com/webmproject/libwebp="v1.6.0"
|
||||
github.com/woodsbury/decimal128="v1.3.0"
|
||||
github.com/yuin/goldmark-emoji="v1.0.6"
|
||||
github.com/yuin/goldmark="v1.7.13"
|
||||
github.com/yuin/goldmark="v1.8.2"
|
||||
go.opentelemetry.io/auto/sdk="v1.2.1"
|
||||
go.opentelemetry.io/contrib/detectors/gcp="v1.39.0"
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc="v0.67.0"
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp="v0.67.0"
|
||||
go.opentelemetry.io/otel/metric="v1.43.0"
|
||||
go.opentelemetry.io/otel/sdk/metric="v1.43.0"
|
||||
go.opentelemetry.io/otel/sdk="v1.43.0"
|
||||
go.opentelemetry.io/otel/trace="v1.43.0"
|
||||
go.opentelemetry.io/otel="v1.43.0"
|
||||
go.uber.org/automaxprocs="v1.5.3"
|
||||
go.yaml.in/yaml/v3="v3.0.4"
|
||||
golang.org/x/crypto="v0.46.0"
|
||||
golang.org/x/image="v0.34.0"
|
||||
golang.org/x/mod="v0.31.0"
|
||||
golang.org/x/net="v0.48.0"
|
||||
golang.org/x/sync="v0.19.0"
|
||||
golang.org/x/sys="v0.39.0"
|
||||
golang.org/x/text="v0.32.0"
|
||||
golang.org/x/tools="v0.40.0"
|
||||
google.golang.org/protobuf="v1.36.10"
|
||||
gopkg.in/yaml.v3="v3.0.1"
|
||||
gocloud.dev="v0.45.0"
|
||||
golang.org/x/crypto="v0.53.0"
|
||||
golang.org/x/image="v0.43.0"
|
||||
golang.org/x/mod="v0.37.0"
|
||||
golang.org/x/net="v0.56.0"
|
||||
golang.org/x/oauth2="v0.36.0"
|
||||
golang.org/x/sync="v0.21.0"
|
||||
golang.org/x/sys="v0.46.0"
|
||||
golang.org/x/text="v0.38.0"
|
||||
golang.org/x/time="v0.15.0"
|
||||
golang.org/x/tools="v0.47.0"
|
||||
golang.org/x/xerrors="v0.0.0-20240903120638-7835f813f4da"
|
||||
google.golang.org/api="v0.276.0"
|
||||
google.golang.org/genproto/googleapis/api="v0.0.0-20260319201613-d00831a3d3e7"
|
||||
google.golang.org/genproto/googleapis/rpc="v0.0.0-20260401024825-9d38bb4040a9"
|
||||
google.golang.org/genproto="v0.0.0-20260319201613-d00831a3d3e7"
|
||||
google.golang.org/grpc="v1.80.0"
|
||||
google.golang.org/protobuf="v1.36.11"
|
||||
rsc.io/qr="v0.2.0"
|
||||
software.sslmate.com/src/go-pkcs12="v0.2.0"
|
||||
software.sslmate.com/src/go-pkcs12="v0.7.0"
|
||||
```
|
||||
</details>
|
||||
|
||||
Vendored
+4
-13
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
|
||||
"github.com/BurntSushi/locker"
|
||||
"github.com/bep/helpers/maphelpers"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -56,8 +57,7 @@ type Cache struct {
|
||||
}
|
||||
|
||||
type lockTracker struct {
|
||||
seenMu sync.RWMutex
|
||||
seen map[string]struct{}
|
||||
seen *maphelpers.ConcurrentSet[string]
|
||||
|
||||
*locker.Locker
|
||||
}
|
||||
@@ -65,16 +65,7 @@ type lockTracker struct {
|
||||
// Lock tracks the ids in use. We use this information to do garbage collection
|
||||
// after a Hugo build.
|
||||
func (l *lockTracker) Lock(id string) {
|
||||
l.seenMu.RLock()
|
||||
if _, seen := l.seen[id]; !seen {
|
||||
l.seenMu.RUnlock()
|
||||
l.seenMu.Lock()
|
||||
l.seen[id] = struct{}{}
|
||||
l.seenMu.Unlock()
|
||||
} else {
|
||||
l.seenMu.RUnlock()
|
||||
}
|
||||
|
||||
l.seen.AddIfAbsent(id)
|
||||
l.Locker.Lock(id)
|
||||
}
|
||||
|
||||
@@ -92,7 +83,7 @@ func NewCache(fs afero.Fs, cfg FileCacheConfig) *Cache {
|
||||
|
||||
return &Cache{
|
||||
Fs: fs,
|
||||
entryLocker: &lockTracker{Locker: locker.NewLocker(), seen: make(map[string]struct{})},
|
||||
entryLocker: &lockTracker{Locker: locker.NewLocker(), seen: maphelpers.NewConcurrentSet[string]()},
|
||||
cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+54
-14
@@ -17,6 +17,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
@@ -59,6 +60,29 @@ func (c *Cache) Prune(force bool) (int, error) {
|
||||
|
||||
counter := 0
|
||||
|
||||
seen := c.entryLocker.seen
|
||||
seenByLower := make(map[string]string, seen.Len())
|
||||
for id := range seen.All() {
|
||||
seenByLower[strings.ToLower(id)] = id
|
||||
}
|
||||
|
||||
// Names on disk matching a used cache key except for the case, and the used keys
|
||||
// actually walked. See the note about case-insensitive filesystems below.
|
||||
var candidates map[string]string
|
||||
visited := make(map[string]bool, seen.Len())
|
||||
|
||||
remove := func(name string) error {
|
||||
err := c.Fs.Remove(name)
|
||||
if err == nil {
|
||||
counter++
|
||||
return nil
|
||||
}
|
||||
if !herrors.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err := afero.Walk(c.Fs, "", func(name string, info os.FileInfo, err error) error {
|
||||
if info == nil {
|
||||
return nil
|
||||
@@ -93,28 +117,44 @@ func (c *Cache) Prune(force bool) (int, error) {
|
||||
|
||||
shouldRemove := force || c.isExpired(info.ModTime())
|
||||
|
||||
if !shouldRemove && len(c.entryLocker.seen) > 0 {
|
||||
// Remove it if it's not been touched/used in the last build.
|
||||
_, seen := c.entryLocker.seen[name]
|
||||
shouldRemove = !seen
|
||||
if seen.Has(name) {
|
||||
visited[name] = true
|
||||
} else if !shouldRemove && seen.Len() > 0 {
|
||||
if id, found := seenByLower[strings.ToLower(name)]; found {
|
||||
// On case-insensitive filesystems this is the same file as id; e.g. an
|
||||
// entry created before Hugo started lowercasing the content paths in
|
||||
// v0.123 (content/MyBundle => _gen/images/MyBundle). Decided once the
|
||||
// walk is done: if id is walked too, they are distinct files and this
|
||||
// one is stale. See issue 15101.
|
||||
if candidates == nil {
|
||||
candidates = make(map[string]string)
|
||||
}
|
||||
candidates[name] = id
|
||||
} else {
|
||||
// Remove it if it's not been touched/used in the last build.
|
||||
shouldRemove = true
|
||||
}
|
||||
}
|
||||
|
||||
if shouldRemove {
|
||||
err := c.Fs.Remove(name)
|
||||
if err == nil {
|
||||
counter++
|
||||
}
|
||||
|
||||
if err != nil && !herrors.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
return remove(name)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return counter, err
|
||||
}
|
||||
|
||||
return counter, err
|
||||
for name, id := range candidates {
|
||||
if visited[id] {
|
||||
if err := remove(name); err != nil {
|
||||
return counter, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return counter, nil
|
||||
}
|
||||
|
||||
func (c *Cache) pruneRootDirs(force bool) (int, error) {
|
||||
|
||||
+121
-57
@@ -16,20 +16,83 @@ package filecache_test
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"testing/synctest"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/cache/filecache"
|
||||
"github.com/gohugoio/hugo/htesting"
|
||||
"github.com/spf13/afero"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
// A cache entry created before Hugo started lowercasing content paths in v0.123
|
||||
// (e.g. _gen/images/MyBundle) is on a case-insensitive filesystem the same file as
|
||||
// the lowercased cache key used today, and must not be pruned.
|
||||
// See issue 15101.
|
||||
func TestPruneCacheEntryWithOtherCase(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
|
||||
dir := t.TempDir()
|
||||
if isCaseInsensitive, err := htesting.IsCaseInsensitiveFs(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !isCaseInsensitive {
|
||||
t.Skip("skip test on case-sensitive filesystem")
|
||||
}
|
||||
|
||||
fs := afero.NewBasePathFs(afero.NewOsFs(), dir)
|
||||
newCache := func() *filecache.Cache {
|
||||
return filecache.NewCache(fs, filecache.FileCacheConfig{Dir: "cache", MaxAge: -1})
|
||||
}
|
||||
|
||||
c.Assert(newCache().SetBytes("MyBundle/i1", []byte("abc")), qt.IsNil)
|
||||
|
||||
cache := newCache()
|
||||
_, b, err := cache.GetOrCreateBytes("mybundle/i1", func() ([]byte, error) {
|
||||
return []byte("def"), nil
|
||||
})
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(string(b), qt.Equals, "abc")
|
||||
|
||||
count, err := cache.Prune(false)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(count, qt.Equals, 0)
|
||||
c.Assert(cache.GetString("MyBundle/i1"), qt.Equals, "abc")
|
||||
}
|
||||
|
||||
// On a case-sensitive filesystem the entries above are distinct files,
|
||||
// and the one not used in this build should be pruned.
|
||||
func TestPruneCacheEntryWithOtherCaseCaseSensitiveFs(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
|
||||
fs := afero.NewMemMapFs()
|
||||
cache := filecache.NewCache(fs, filecache.FileCacheConfig{Dir: "cache", MaxAge: -1})
|
||||
|
||||
c.Assert(cache.SetBytes("MyBundle/i1", []byte("abc")), qt.IsNil)
|
||||
|
||||
cache = filecache.NewCache(fs, filecache.FileCacheConfig{Dir: "cache", MaxAge: -1})
|
||||
_, b, err := cache.GetOrCreateBytes("mybundle/i1", func() ([]byte, error) {
|
||||
return []byte("def"), nil
|
||||
})
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(string(b), qt.Equals, "def")
|
||||
|
||||
count, err := cache.Prune(false)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(count, qt.Equals, 1)
|
||||
c.Assert(cache.GetString("MyBundle/i1"), qt.Equals, "")
|
||||
c.Assert(cache.GetString("mybundle/i1"), qt.Equals, "def")
|
||||
}
|
||||
|
||||
func TestPrune(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c := qt.New(t)
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
configStr := `
|
||||
configStr := `
|
||||
resourceDir = "myresources"
|
||||
contentDir = "content"
|
||||
dataDir = "data"
|
||||
@@ -50,63 +113,64 @@ maxAge = "200ms"
|
||||
dir = ":resourceDir/_gen"
|
||||
`
|
||||
|
||||
for _, name := range []string{filecache.CacheKeyAssets, filecache.CacheKeyImages} {
|
||||
msg := qt.Commentf("cache: %s", name)
|
||||
fs := afero.NewMemMapFs()
|
||||
p := newPathsSpec(t, fs, configStr)
|
||||
fileCachConfig := p.Cfg.GetConfigSection("caches").(filecache.Configs)
|
||||
caches, err := filecache.NewCaches(fileCachConfig, fs)
|
||||
c.Assert(err, qt.IsNil)
|
||||
caches.SetResourceFs(fs)
|
||||
cache := caches[name]
|
||||
for i := range 10 {
|
||||
id := fmt.Sprintf("i%d", i)
|
||||
cache.GetOrCreateBytes(id, func() ([]byte, error) {
|
||||
for _, name := range []string{filecache.CacheKeyAssets, filecache.CacheKeyImages} {
|
||||
msg := qt.Commentf("cache: %s", name)
|
||||
fs := afero.NewMemMapFs()
|
||||
p := newPathsSpec(t, fs, configStr)
|
||||
fileCachConfig := p.Cfg.GetConfigSection("caches").(filecache.Configs)
|
||||
caches, err := filecache.NewCaches(fileCachConfig, fs)
|
||||
c.Assert(err, qt.IsNil)
|
||||
caches.SetResourceFs(fs)
|
||||
cache := caches[name]
|
||||
for i := range 10 {
|
||||
id := fmt.Sprintf("i%d", i)
|
||||
cache.GetOrCreateBytes(id, func() ([]byte, error) {
|
||||
return []byte("abc"), nil
|
||||
})
|
||||
if i == 4 {
|
||||
// This will expire the first 5
|
||||
time.Sleep(201 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
count, err := caches.Prune()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(count, qt.Equals, 5, msg)
|
||||
|
||||
for i := range 10 {
|
||||
id := fmt.Sprintf("i%d", i)
|
||||
v := cache.GetString(id)
|
||||
if i < 5 {
|
||||
c.Assert(v, qt.Equals, "")
|
||||
} else {
|
||||
c.Assert(v, qt.Equals, "abc")
|
||||
}
|
||||
}
|
||||
|
||||
caches, err = filecache.NewCaches(fileCachConfig, fs)
|
||||
c.Assert(err, qt.IsNil)
|
||||
caches.SetResourceFs(fs)
|
||||
cache = caches[name]
|
||||
// Touch one and then prune.
|
||||
cache.GetOrCreateBytes("i5", func() ([]byte, error) {
|
||||
return []byte("abc"), nil
|
||||
})
|
||||
if i == 4 {
|
||||
// This will expire the first 5
|
||||
time.Sleep(201 * time.Millisecond)
|
||||
|
||||
count, err = caches.Prune()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(count, qt.Equals, 4)
|
||||
|
||||
// Now only the i5 should be left.
|
||||
for i := range 10 {
|
||||
id := fmt.Sprintf("i%d", i)
|
||||
v := cache.GetString(id)
|
||||
if i != 5 {
|
||||
c.Assert(v, qt.Equals, "")
|
||||
} else {
|
||||
c.Assert(v, qt.Equals, "abc")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
count, err := caches.Prune()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(count, qt.Equals, 5, msg)
|
||||
|
||||
for i := range 10 {
|
||||
id := fmt.Sprintf("i%d", i)
|
||||
v := cache.GetString(id)
|
||||
if i < 5 {
|
||||
c.Assert(v, qt.Equals, "")
|
||||
} else {
|
||||
c.Assert(v, qt.Equals, "abc")
|
||||
}
|
||||
}
|
||||
|
||||
caches, err = filecache.NewCaches(fileCachConfig, fs)
|
||||
c.Assert(err, qt.IsNil)
|
||||
caches.SetResourceFs(fs)
|
||||
cache = caches[name]
|
||||
// Touch one and then prune.
|
||||
cache.GetOrCreateBytes("i5", func() ([]byte, error) {
|
||||
return []byte("abc"), nil
|
||||
})
|
||||
|
||||
count, err = caches.Prune()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(count, qt.Equals, 4)
|
||||
|
||||
// Now only the i5 should be left.
|
||||
for i := range 10 {
|
||||
id := fmt.Sprintf("i%d", i)
|
||||
v := cache.GetString(id)
|
||||
if i != 5 {
|
||||
c.Assert(v, qt.Equals, "")
|
||||
} else {
|
||||
c.Assert(v, qt.Equals, "abc")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,13 +38,20 @@ run_gofmt() {
|
||||
|
||||
# Run staticcheck
|
||||
run_staticcheck() {
|
||||
# Check if staticcheck is installed, install if not
|
||||
if ! command -v staticcheck &> /dev/null; then
|
||||
local staticcheck_bin
|
||||
if command -v staticcheck &> /dev/null; then
|
||||
staticcheck_bin=$(command -v staticcheck)
|
||||
else
|
||||
echo "==> Installing staticcheck..."
|
||||
go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
staticcheck_bin="$(go env GOBIN)"
|
||||
if [ -z "$staticcheck_bin" ]; then
|
||||
staticcheck_bin="$(go env GOPATH)/bin"
|
||||
fi
|
||||
staticcheck_bin="$staticcheck_bin/staticcheck"
|
||||
fi
|
||||
echo "==> Running staticcheck..."
|
||||
staticcheck $PACKAGES
|
||||
"$staticcheck_bin" $PACKAGES
|
||||
echo " OK"
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -103,9 +103,7 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T
|
||||
}
|
||||
|
||||
for _, t := range include {
|
||||
for i := range t.NumMethod() {
|
||||
|
||||
m := t.Method(i)
|
||||
for m := range t.Methods() {
|
||||
if excludes[m.Name] || seen[m.Name] {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ func applyLocalFlagsBuild(cmd *cobra.Command, r *rootCommand) {
|
||||
cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
|
||||
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
|
||||
cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
|
||||
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
|
||||
cmd.Flags().BoolP("ignoreCache", "", false, "ignore the configured file caches")
|
||||
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
|
||||
cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
|
||||
_ = cmd.MarkFlagDirname("layoutDir")
|
||||
|
||||
+31
-3
@@ -263,11 +263,39 @@ func (c *convertCommand) convertContents(format metadecoders.Format) error {
|
||||
|
||||
site := c.h.Sites[0]
|
||||
|
||||
var pagesBackedByFile page.Pages
|
||||
for _, p := range site.AllPages() {
|
||||
workingDir := c.h.Sites[0].Deps.Conf.WorkingDir() + string(filepath.Separator)
|
||||
|
||||
isConvertible := func(p page.Page) bool {
|
||||
// Skip pages not backed by a content file.
|
||||
if p.File() == nil {
|
||||
return false
|
||||
}
|
||||
// Skip content adapters.
|
||||
if p.File().IsContentAdapter() {
|
||||
return false
|
||||
}
|
||||
// Skip content files provided by modules, including vendored modules.
|
||||
if !p.File().FileInfo().Meta().IsProject {
|
||||
return false
|
||||
}
|
||||
// Skip content files in project mounts outside the working directory.
|
||||
if !strings.HasPrefix(p.File().Filename(), workingDir) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
seen := make(map[string]bool)
|
||||
var pagesBackedByFile page.Pages
|
||||
for _, p := range c.h.Pages() {
|
||||
if !isConvertible(p) {
|
||||
continue
|
||||
}
|
||||
filename := p.File().Filename()
|
||||
if seen[filename] {
|
||||
continue
|
||||
}
|
||||
seen[filename] = true
|
||||
pagesBackedByFile = append(pagesBackedByFile, p)
|
||||
}
|
||||
|
||||
@@ -278,7 +306,7 @@ func (c *convertCommand) convertContents(format metadecoders.Format) error {
|
||||
}
|
||||
|
||||
site.Log.Println("processing", len(pagesBackedByFile), "content files")
|
||||
for _, p := range site.AllPages() {
|
||||
for _, p := range pagesBackedByFile {
|
||||
if err := c.convertAndSavePage(p, site, format); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+28
-29
@@ -21,12 +21,8 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/chroma/v2"
|
||||
"github.com/alecthomas/chroma/v2/formatters/html"
|
||||
"github.com/alecthomas/chroma/v2/styles"
|
||||
"github.com/bep/simplecobra"
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/gohugoio/hugo/common/hugo"
|
||||
@@ -34,6 +30,7 @@ import (
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
"github.com/gohugoio/hugo/hugolib"
|
||||
"github.com/gohugoio/hugo/markup/highlight"
|
||||
"github.com/gohugoio/hugo/parser"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/cobra/doc"
|
||||
@@ -47,6 +44,10 @@ func newGenCommand() *genCommand {
|
||||
|
||||
// Chroma flags.
|
||||
style string
|
||||
mode string
|
||||
modeSelector bool
|
||||
classDark string
|
||||
classLight string
|
||||
highlightStyle string
|
||||
lineNumbersInlineStyle string
|
||||
lineNumbersTableStyle string
|
||||
@@ -63,43 +64,41 @@ func newGenCommand() *genCommand {
|
||||
See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview of the available styles.`,
|
||||
|
||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||
style = strings.ToLower(style)
|
||||
if !slices.Contains(styles.Names(), style) {
|
||||
return fmt.Errorf("invalid style: %s", style)
|
||||
}
|
||||
builder := styles.Get(style).Builder()
|
||||
if highlightStyle != "" {
|
||||
builder.Add(chroma.LineHighlight, highlightStyle)
|
||||
}
|
||||
if lineNumbersInlineStyle != "" {
|
||||
builder.Add(chroma.LineNumbers, lineNumbersInlineStyle)
|
||||
}
|
||||
if lineNumbersTableStyle != "" {
|
||||
builder.Add(chroma.LineNumbersTable, lineNumbersTableStyle)
|
||||
}
|
||||
style, err := builder.Build()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if omitEmpty {
|
||||
// See https://github.com/alecthomas/chroma/commit/5b2a4c5a26c503c79bc86ba3c4ae5b330028bd3d
|
||||
hugo.Deprecate("--omitEmpty", "Flag is no longer needed, empty classes are now always omitted.", "v0.149.0")
|
||||
}
|
||||
options := []html.Option{
|
||||
html.WithCSSComments(!omitClassComments),
|
||||
css, err := highlight.ChromaStylesCSS(highlight.ChromaStylesOptions{
|
||||
Style: style,
|
||||
Mode: mode,
|
||||
ModeSelector: modeSelector,
|
||||
ClassDark: classDark,
|
||||
ClassLight: classLight,
|
||||
HighlightStyle: highlightStyle,
|
||||
LineNumbersInlineStyle: lineNumbersInlineStyle,
|
||||
LineNumbersTableStyle: lineNumbersTableStyle,
|
||||
OmitClassComments: omitClassComments,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
formatter := html.New(options...)
|
||||
|
||||
w := os.Stdout
|
||||
fmt.Fprintf(w, "/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))
|
||||
formatter.WriteCSS(w, style)
|
||||
fmt.Printf("/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))
|
||||
fmt.Print(css)
|
||||
return nil
|
||||
},
|
||||
withc: func(cmd *cobra.Command, r *rootCommand) {
|
||||
cmd.ValidArgsFunction = cobra.NoFileCompletions
|
||||
cmd.PersistentFlags().StringVar(&style, "style", "friendly", "highlighter style")
|
||||
_ = cmd.RegisterFlagCompletionFunc("style", cobra.NoFileCompletions)
|
||||
cmd.PersistentFlags().StringVar(&mode, "mode", "", `style mode ("light", "dark")`)
|
||||
_ = cmd.RegisterFlagCompletionFunc("mode", cobra.FixedCompletions([]string{"light", "dark"}, cobra.ShellCompDirectiveNoFileComp))
|
||||
cmd.PersistentFlags().BoolVar(&modeSelector, "modeSelector", false, `scope selectors under a top level mode class, e.g. ".dark .chroma"`)
|
||||
_ = cmd.RegisterFlagCompletionFunc("modeSelector", cobra.NoFileCompletions)
|
||||
cmd.PersistentFlags().StringVar(&classDark, "classDark", "dark", `class name used by --modeSelector for dark styles`)
|
||||
_ = cmd.RegisterFlagCompletionFunc("classDark", cobra.NoFileCompletions)
|
||||
cmd.PersistentFlags().StringVar(&classLight, "classLight", "light", `class name used by --modeSelector for light styles`)
|
||||
_ = cmd.RegisterFlagCompletionFunc("classLight", cobra.NoFileCompletions)
|
||||
cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", `foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff"`)
|
||||
_ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions)
|
||||
cmd.PersistentFlags().StringVar(&lineNumbersInlineStyle, "lineNumbersInlineStyle", "", `foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff"`)
|
||||
|
||||
@@ -367,7 +367,7 @@ func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*wa
|
||||
case changes := <-c.r.changesFromBuild:
|
||||
unlock, err := h.LockBuild()
|
||||
if err != nil {
|
||||
c.r.logger.Errorln("Failed to acquire a build lock: %s", err)
|
||||
c.r.logger.Errorf("Failed to acquire a build lock: %s", err)
|
||||
return
|
||||
}
|
||||
c.changeDetector.PrepareNew()
|
||||
@@ -387,7 +387,7 @@ func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*wa
|
||||
case evs := <-watcher.Events:
|
||||
unlock, err := h.LockBuild()
|
||||
if err != nil {
|
||||
c.r.logger.Errorln("Failed to acquire a build lock: %s", err)
|
||||
c.r.logger.Errorf("Failed to acquire a build lock: %s", err)
|
||||
return
|
||||
}
|
||||
c.handleEvents(watcher, staticSyncer, evs, configSet)
|
||||
|
||||
+32
-25
@@ -466,41 +466,48 @@ func (c *importCommand) importFromJekyll(args []string) error {
|
||||
c.r.Println("Now, start Hugo by yourself:")
|
||||
c.r.Println("cd " + args[1])
|
||||
c.r.Println("git init")
|
||||
c.r.Println("git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke")
|
||||
c.r.Println("echo \"theme = 'ananke'\" > hugo.toml")
|
||||
c.r.Println("git submodule add https://github.com/gohugo-ananke/ananke themes/ananke")
|
||||
c.r.Println("echo \"theme: ananke\" >> hugo.yaml")
|
||||
c.r.Println("hugo server")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *importCommand) loadJekyllConfig(fs afero.Fs, jekyllRoot string) map[string]any {
|
||||
path := filepath.Join(jekyllRoot, "_config.yml")
|
||||
for _, candidate := range []struct {
|
||||
filename string
|
||||
format metadecoders.Format
|
||||
}{
|
||||
{"_config.yml", metadecoders.YAML},
|
||||
{"_config.yaml", metadecoders.YAML},
|
||||
{"_config.toml", metadecoders.TOML},
|
||||
} {
|
||||
path := filepath.Join(jekyllRoot, candidate.filename)
|
||||
exists, err := helpers.Exists(path, fs)
|
||||
if err != nil || !exists {
|
||||
continue
|
||||
}
|
||||
|
||||
exists, err := helpers.Exists(path, fs)
|
||||
f, err := fs.Open(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
b, err := io.ReadAll(f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err != nil || !exists {
|
||||
c.r.Println("_config.yaml not found: Is the specified Jekyll root correct?")
|
||||
return nil
|
||||
m, err := metadecoders.Default.UnmarshalToMap(b, candidate.format)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
f, err := fs.Open(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
b, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
m, err := metadecoders.Default.UnmarshalToMap(b, metadecoders.YAML)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return m
|
||||
c.r.Println("no config file (_config.yml, _config.yaml, or _config.toml) found: is the specified Jekyll root correct?")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *importCommand) parseJekyllFilename(filename string) (time.Time, string, error) {
|
||||
|
||||
+2
-2
@@ -549,7 +549,7 @@ of a second, you will be able to save and see your changes nearly instantly.`
|
||||
cmd.Flags().BoolVar(&c.tlsAuto, "tlsAuto", false, "generate and use locally-trusted certificates.")
|
||||
cmd.Flags().BoolVar(&c.pprof, "pprof", false, "enable the pprof server (port 8080)")
|
||||
cmd.Flags().BoolVarP(&c.serverWatch, "watch", "w", true, "watch filesystem for changes and recreate as needed")
|
||||
cmd.Flags().BoolVar(&c.noHTTPCache, "noHTTPCache", false, "prevent HTTP caching")
|
||||
cmd.Flags().BoolVar(&c.noHTTPCache, "noHTTPCache", false, "disable browser caching of pages served by the embedded web server")
|
||||
cmd.Flags().BoolVarP(&c.serverAppend, "appendPort", "", true, "append port to baseURL")
|
||||
cmd.Flags().BoolVar(&c.disableLiveReload, "disableLiveReload", false, "watch without enabling live browser reload on rebuild")
|
||||
cmd.Flags().BoolVarP(&c.navigateToChanged, "navigateToChanged", "N", false, "navigate to changed content file on live browser reload")
|
||||
@@ -1108,7 +1108,7 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error {
|
||||
|
||||
fromPath := ev.Name
|
||||
|
||||
relPath, found := sourceFs.MakePathRelative(fromPath, true)
|
||||
relPath, found := sourceFs.MakePathRelative(fromPath, false)
|
||||
|
||||
if !found {
|
||||
// Not member of this virtual host.
|
||||
|
||||
+41
-21
@@ -18,6 +18,7 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
@@ -105,6 +106,16 @@ func MD5FromStringHexEncoded(f string) string {
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// MD5FromReaderHexEncoded returns the MD5 hash of the given reader.
|
||||
func MD5FromReaderHexEncoded(r io.Reader) string {
|
||||
h := md5.New()
|
||||
_, err := io.Copy(h, r)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// HashString returns a hash from the given elements.
|
||||
// It will panic if the hash cannot be calculated.
|
||||
// Note that this hash should be used primarily for identity, not for change detection as
|
||||
@@ -124,11 +135,38 @@ func HashStringHex(vs ...any) string {
|
||||
var hashOptsPool = sync.Pool{
|
||||
New: func() any {
|
||||
return &hashstructure.HashOptions{
|
||||
Hasher: xxhash.New(),
|
||||
Hasher: xxhash.New(),
|
||||
UnwrapFunc: unwrapForHashing,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// hashstructure only sees exported struct fields, so rewrite known identity types before hashing,
|
||||
// e.g. a Resource or Page nested in an options map hashes by its Key.
|
||||
func unwrapForHashing(v reflect.Value) (reflect.Value, error) {
|
||||
if v.Kind() != reflect.Struct {
|
||||
return v, nil
|
||||
}
|
||||
var in any
|
||||
if v.CanAddr() {
|
||||
// The common case; pointer receiver methods on a struct
|
||||
// reached through a pointer.
|
||||
in = v.Addr().Interface()
|
||||
} else {
|
||||
in = v.Interface()
|
||||
}
|
||||
switch t := in.(type) {
|
||||
case hashstructure.Hashable:
|
||||
// Let hashstructure handle it.
|
||||
return v, nil
|
||||
case keyer:
|
||||
return reflect.ValueOf(t.Key()), nil
|
||||
case identity.IdentityProvider:
|
||||
return reflect.ValueOf(t.GetIdentity()), nil
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func getHashOpts() *hashstructure.HashOptions {
|
||||
return hashOptsPool.Get().(*hashstructure.HashOptions)
|
||||
}
|
||||
@@ -145,15 +183,10 @@ func putHashOpts(opts *hashstructure.HashOptions) {
|
||||
func HashUint64(vs ...any) uint64 {
|
||||
var o any
|
||||
if len(vs) == 1 {
|
||||
o = toHashable(vs[0])
|
||||
o = vs[0]
|
||||
} else {
|
||||
elements := make([]any, len(vs))
|
||||
for i, e := range vs {
|
||||
elements[i] = toHashable(e)
|
||||
}
|
||||
o = elements
|
||||
o = vs
|
||||
}
|
||||
|
||||
hash, err := Hash(o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -176,19 +209,6 @@ type keyer interface {
|
||||
Key() string
|
||||
}
|
||||
|
||||
// For structs, hashstructure.Hash only works on the exported fields,
|
||||
// so rewrite the input slice for known identity types.
|
||||
func toHashable(v any) any {
|
||||
switch t := v.(type) {
|
||||
case keyer:
|
||||
return t.Key()
|
||||
case identity.IdentityProvider:
|
||||
return t.GetIdentity()
|
||||
default:
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
type xxhashReadFrom struct {
|
||||
buff []byte
|
||||
*xxhash.Digest
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2026 The Hugo Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package hexec
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/base64"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//go:embed esmloader.mjs
|
||||
var esmLoaderSource string
|
||||
|
||||
// nodeESMLoaderImportArg returns a "--import=data:..." argument that installs
|
||||
// a Node.js ESM resolver hook making NODE_PATH a fallback for failed bare
|
||||
// imports. See esmloader.mjs for the rationale.
|
||||
var nodeESMLoaderImportArg = sync.OnceValue(func() string {
|
||||
return "--import=data:text/javascript;base64," + base64.StdEncoding.EncodeToString([]byte(esmLoaderSource))
|
||||
})
|
||||
@@ -0,0 +1,61 @@
|
||||
// Node.js ESM resolver hook installed by Hugo.
|
||||
//
|
||||
// Node's ESM resolver does not consult NODE_PATH, unlike CJS require().
|
||||
// That breaks postcss.config.js / babel.config.js / etc. files written in
|
||||
// ESM and loaded from outside the project tree (typically the Hugo module
|
||||
// cache): bare imports like `import x from "postcss-import"` cannot be
|
||||
// resolved by walking up from the file's location.
|
||||
//
|
||||
// This hook makes the ESM resolver fall back to NODE_PATH for bare
|
||||
// specifiers when Node's normal resolution fails. It is a no-op for
|
||||
// relative/absolute paths and URL-scheme specifiers, and it never fires
|
||||
// unless Node would itself have thrown ERR_MODULE_NOT_FOUND or
|
||||
// ERR_ACCESS_DENIED.
|
||||
//
|
||||
// ERR_ACCESS_DENIED is handled because Node's resolver walks up the
|
||||
// directory tree looking for node_modules. Under the permission model that
|
||||
// walk can hit a node_modules outside the allow-list (e.g. Netlify stores
|
||||
// its node_modules cache in the same tree as the Hugo file cache), aborting
|
||||
// resolution even though the package is reachable via NODE_PATH. If the
|
||||
// NODE_PATH fallback also fails we re-throw the original error so the
|
||||
// access-denied resource is still reported.
|
||||
//
|
||||
// Uses the synchronous registerHooks API so it runs on the main thread and
|
||||
// does not require --allow-worker under the Node permission model.
|
||||
|
||||
import { registerHooks, createRequire } from 'node:module';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
const resolvers = [];
|
||||
const np = process.env.NODE_PATH;
|
||||
if (np) {
|
||||
const sep = process.platform === 'win32' ? ';' : ':';
|
||||
for (const p of np.split(sep)) {
|
||||
if (p) resolvers.push(createRequire(p + '/_'));
|
||||
}
|
||||
}
|
||||
|
||||
function isBareSpecifier(s) {
|
||||
if (!s) return false;
|
||||
if (s.startsWith('.') || s.startsWith('/') || s.startsWith('#')) return false;
|
||||
if (/^[a-z][a-z0-9+.-]*:/i.test(s)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
registerHooks({
|
||||
resolve(specifier, context, nextResolve) {
|
||||
try {
|
||||
return nextResolve(specifier, context);
|
||||
} catch (err) {
|
||||
if (err?.code !== 'ERR_MODULE_NOT_FOUND' && err?.code !== 'ERR_ACCESS_DENIED') throw err;
|
||||
if (!isBareSpecifier(specifier)) throw err;
|
||||
for (const r of resolvers) {
|
||||
try {
|
||||
const resolved = r.resolve(specifier);
|
||||
return { url: pathToFileURL(resolved).href, shortCircuit: true, format: null };
|
||||
} catch (_) { /* try next */ }
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -234,6 +234,10 @@ func (e *Exec) newNode(name, scriptPath string, arg ...any) (Runner, error) {
|
||||
for _, pa := range e.nodePermissionArgs(name, scriptPath) {
|
||||
allArgs = append(allArgs, pa)
|
||||
}
|
||||
// Install an ESM resolver hook that makes NODE_PATH a fallback for failed
|
||||
// bare imports, so postcss.config.js / babel.config.js / etc. written in
|
||||
// ESM work when loaded from the Hugo module cache. See esmloader.mjs.
|
||||
allArgs = append(allArgs, nodeESMLoaderImportArg())
|
||||
allArgs = append(allArgs, scriptPath)
|
||||
allArgs = append(allArgs, arg...)
|
||||
// When the script lives outside the working dir (a globally installed
|
||||
|
||||
@@ -45,17 +45,17 @@ body { color: blue }
|
||||
-- layouts/home.html --
|
||||
{{ with resources.Get "css/main1.css" }}
|
||||
{{ with . | css.PostCSS }}
|
||||
CSS1 size: {{ .Content | len }}|{{ .RelPermalink }}|
|
||||
CSS1: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}|
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ with resources.Get "css/main2.css" }}
|
||||
{{ with resources.Get "css/main2.css" }}
|
||||
{{ with . | css.TailwindCSS }}
|
||||
CSS2 size: {{ .Content | len }}|{{ .RelPermalink }}|
|
||||
CSS2: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}|
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ with resources.Get "js/main.js" }}
|
||||
{{ with resources.Get "js/main.js" }}
|
||||
{{ with . | js.Babel }}
|
||||
JS size: {{ .Content | len }}|{{ .RelPermalink }}|
|
||||
JS: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}|
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
`
|
||||
@@ -67,8 +67,8 @@ body { color: blue }
|
||||
))
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"CSS1 size: 233|/css/main1.css|",
|
||||
"CSS2 size: 4557|/css/main2.css|",
|
||||
"JS size: 31|/js/main.js|",
|
||||
"CSS1: /css/main1.css|true|",
|
||||
"CSS2: /css/main2.css|true|",
|
||||
"JS: /js/main.js|true|",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,23 @@ type ImageConfigProvider interface {
|
||||
GetImageConfig() image.Config
|
||||
}
|
||||
|
||||
// ColorPropertiesProvider provides access to CICP color properties (for HDR images).
|
||||
// Images implementing this interface preserve color space information through processing.
|
||||
type ColorPropertiesProvider interface {
|
||||
GetColorPrimaries() int
|
||||
GetTransferCharacteristics() int
|
||||
GetMatrixCoefficients() int
|
||||
}
|
||||
|
||||
// HasColorProperties returns true if the image has non-zero color properties that should be preserved.
|
||||
func HasColorProperties(img image.Image) bool {
|
||||
if cpp, ok := img.(ColorPropertiesProvider); ok {
|
||||
// Consider it as having properties if any value is non-zero.
|
||||
return cpp.GetColorPrimaries() > 0 || cpp.GetTransferCharacteristics() > 0 || cpp.GetMatrixCoefficients() > 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// FrameDurationsToGifDelays converts frame durations in milliseconds to
|
||||
// GIF delays in 100ths of a second.
|
||||
func FrameDurationsToGifDelays(frameDurations []int) []int {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package hiter
|
||||
|
||||
// Common iterator functions.
|
||||
// Some of these are are based on this discsussion: https://github.com/golang/go/issues/61898
|
||||
// Some of these are based on this discsussion: https://github.com/golang/go/issues/61898
|
||||
|
||||
import "iter"
|
||||
|
||||
|
||||
@@ -120,6 +120,14 @@ func (p Params) merge(ps ParamsMergeStrategy, pp Params) {
|
||||
if vvv, ok := vv.(Params); ok {
|
||||
if pv, ok := v.(Params); ok {
|
||||
vvv.merge(ms, pv)
|
||||
} else if vvv.IsZero() {
|
||||
// The existing value is an empty Params (just merge metadata)
|
||||
// and the incoming value is a non-Params type (e.g. a slice).
|
||||
// If the user has set an explicit non-none merge strategy,
|
||||
// honor it by using the incoming value.
|
||||
if s, found := vvv.GetMergeStrategy(); found && s != ParamsMergeStrategyNone {
|
||||
p[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if !noUpdate {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
package hstore
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -69,9 +68,8 @@ func TestScratchAddSlice(t *testing.T) {
|
||||
sl := scratch.Get("intSlice")
|
||||
expected := []int{1, 2, 3}
|
||||
|
||||
if !reflect.DeepEqual(expected, sl) {
|
||||
t.Errorf("Slice difference, go %q expected %q", sl, expected)
|
||||
}
|
||||
c.Assert(sl, qt.DeepEquals, expected)
|
||||
|
||||
_, err = scratch.Add("intSlice", []int{4, 5})
|
||||
|
||||
c.Assert(err, qt.IsNil)
|
||||
@@ -79,9 +77,7 @@ func TestScratchAddSlice(t *testing.T) {
|
||||
sl = scratch.Get("intSlice")
|
||||
expected = []int{1, 2, 3, 4, 5}
|
||||
|
||||
if !reflect.DeepEqual(expected, sl) {
|
||||
t.Errorf("Slice difference, go %q expected %q", sl, expected)
|
||||
}
|
||||
c.Assert(sl, qt.DeepEquals, expected)
|
||||
}
|
||||
|
||||
// https://github.com/gohugoio/hugo/issues/5275
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/bep/helpers/maphelpers"
|
||||
"github.com/gohugoio/hugo/compare"
|
||||
)
|
||||
|
||||
@@ -55,46 +55,17 @@ func EqualAny(a string, b ...string) bool {
|
||||
return slices.Contains(b, a)
|
||||
}
|
||||
|
||||
// regexpCache represents a cache of regexp objects protected by a mutex.
|
||||
type regexpCache struct {
|
||||
mu sync.RWMutex
|
||||
re map[string]*regexp.Regexp
|
||||
}
|
||||
|
||||
func (rc *regexpCache) getOrCompileRegexp(pattern string) (re *regexp.Regexp, err error) {
|
||||
var ok bool
|
||||
|
||||
if re, ok = rc.get(pattern); !ok {
|
||||
re, err = regexp.Compile(pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc.set(pattern, re)
|
||||
}
|
||||
|
||||
return re, nil
|
||||
}
|
||||
|
||||
func (rc *regexpCache) get(key string) (re *regexp.Regexp, ok bool) {
|
||||
rc.mu.RLock()
|
||||
re, ok = rc.re[key]
|
||||
rc.mu.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (rc *regexpCache) set(key string, re *regexp.Regexp) {
|
||||
rc.mu.Lock()
|
||||
rc.re[key] = re
|
||||
rc.mu.Unlock()
|
||||
}
|
||||
|
||||
var reCache = regexpCache{re: make(map[string]*regexp.Regexp)}
|
||||
var reCache = *maphelpers.NewConcurrentMap[string, *regexp.Regexp]()
|
||||
|
||||
// GetOrCompileRegexp retrieves a regexp object from the cache based upon the pattern.
|
||||
// If the pattern is not found in the cache, the pattern is compiled and added to
|
||||
// the cache.
|
||||
func GetOrCompileRegexp(pattern string) (re *regexp.Regexp, err error) {
|
||||
return reCache.getOrCompileRegexp(pattern)
|
||||
return reCache.GetOrCreate(pattern,
|
||||
func() (*regexp.Regexp, error) {
|
||||
return regexp.Compile(pattern)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasAnyPrefix checks if the string s has any of the prefixes given.
|
||||
|
||||
@@ -21,8 +21,9 @@ import (
|
||||
type HasBytesWriter struct {
|
||||
Patterns []*HasBytesPattern
|
||||
|
||||
i int
|
||||
done bool
|
||||
// The tail of the bytes written so far, retained so we can detect a
|
||||
// pattern that straddles the boundary between two Write calls.
|
||||
buff []byte
|
||||
}
|
||||
|
||||
@@ -31,10 +32,13 @@ type HasBytesPattern struct {
|
||||
Pattern []byte
|
||||
}
|
||||
|
||||
func (h *HasBytesWriter) patternLen() int {
|
||||
// maxPatternLen returns the length of the longest pattern.
|
||||
func (h *HasBytesWriter) maxPatternLen() int {
|
||||
l := 0
|
||||
for _, p := range h.Patterns {
|
||||
l += len(p.Pattern)
|
||||
if len(p.Pattern) > l {
|
||||
l = len(p.Pattern)
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
||||
@@ -44,36 +48,55 @@ func (h *HasBytesWriter) Write(p []byte) (n int, err error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
if len(h.buff) == 0 {
|
||||
h.buff = make([]byte, h.patternLen()*2)
|
||||
keep := h.maxPatternLen() - 1
|
||||
|
||||
// Join the tail retained from previous Writes with the head of this chunk
|
||||
// so a pattern straddling the boundary is still detected. Only the
|
||||
// boundary window is copied; the chunk itself is scanned in place below.
|
||||
var boundary []byte
|
||||
if keep > 0 && len(h.buff) > 0 {
|
||||
head := p
|
||||
if len(head) > keep {
|
||||
head = head[:keep]
|
||||
}
|
||||
boundary = make([]byte, 0, len(h.buff)+len(head))
|
||||
boundary = append(boundary, h.buff...)
|
||||
boundary = append(boundary, head...)
|
||||
}
|
||||
|
||||
for i := range p {
|
||||
h.buff[h.i] = p[i]
|
||||
h.i++
|
||||
if h.i == len(h.buff) {
|
||||
// Shift left.
|
||||
copy(h.buff, h.buff[len(h.buff)/2:])
|
||||
h.i = len(h.buff) / 2
|
||||
// Scan each not-yet-matched pattern once per Write instead of once per byte.
|
||||
done := true
|
||||
for _, pp := range h.Patterns {
|
||||
if pp.Match {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, pp := range h.Patterns {
|
||||
if bytes.Contains(h.buff, pp.Pattern) {
|
||||
pp.Match = true
|
||||
done := true
|
||||
for _, ppp := range h.Patterns {
|
||||
if !ppp.Match {
|
||||
done = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if done {
|
||||
h.done = true
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
if bytes.Contains(p, pp.Pattern) || bytes.Contains(boundary, pp.Pattern) {
|
||||
pp.Match = true
|
||||
continue
|
||||
}
|
||||
done = false
|
||||
}
|
||||
|
||||
if done {
|
||||
// All patterns found; no need to look at any more data.
|
||||
h.done = true
|
||||
h.buff = nil
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// Retain the last keep bytes of (previous tail + this chunk) to detect a
|
||||
// pattern straddling into the next Write.
|
||||
switch {
|
||||
case keep <= 0:
|
||||
h.buff = h.buff[:0]
|
||||
case len(p) >= keep:
|
||||
h.buff = append(h.buff[:0], p[len(p)-keep:]...)
|
||||
default:
|
||||
// Chunk shorter than keep: slide the window over the retained tail.
|
||||
if total := len(h.buff) + len(p); total > keep {
|
||||
h.buff = h.buff[total-keep:]
|
||||
}
|
||||
h.buff = append(h.buff, p...)
|
||||
}
|
||||
|
||||
return len(p), nil
|
||||
|
||||
@@ -65,3 +65,61 @@ func TestHasBytesWriter(t *testing.T) {
|
||||
fmt.Fprintf(w, "__foo")
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, true)
|
||||
}
|
||||
|
||||
func TestHasBytesWriterMultiplePatterns(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
neww := func() (*HasBytesWriter, io.Writer) {
|
||||
var b bytes.Buffer
|
||||
h := &HasBytesWriter{
|
||||
Patterns: []*HasBytesPattern{
|
||||
{Pattern: []byte("__hdeferred/")},
|
||||
{Pattern: []byte("__h_pp_l1")},
|
||||
},
|
||||
}
|
||||
return h, io.MultiWriter(&b, h)
|
||||
}
|
||||
|
||||
// Neither pattern present.
|
||||
h, w := neww()
|
||||
fmt.Fprint(w, "the quick brown fox jumps over the lazy dog")
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, false)
|
||||
c.Assert(h.Patterns[1].Match, qt.Equals, false)
|
||||
c.Assert(h.done, qt.Equals, false)
|
||||
|
||||
// Only the second pattern present; the writer must not report a match
|
||||
// for the first, and must not prematurely mark itself done.
|
||||
h, w = neww()
|
||||
fmt.Fprint(w, "prefix __h_pp_l1 suffix")
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, false)
|
||||
c.Assert(h.Patterns[1].Match, qt.Equals, true)
|
||||
c.Assert(h.done, qt.Equals, false)
|
||||
|
||||
// Both patterns present across multiple writes; done once all match.
|
||||
h, w = neww()
|
||||
fmt.Fprint(w, "aaa __hdef")
|
||||
fmt.Fprint(w, "erred/xyz bbb __h_p")
|
||||
fmt.Fprint(w, "p_l1 ccc")
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, true)
|
||||
c.Assert(h.Patterns[1].Match, qt.Equals, true)
|
||||
c.Assert(h.done, qt.Equals, true)
|
||||
}
|
||||
|
||||
func BenchmarkHasBytesWriter(b *testing.B) {
|
||||
// A large chunk of output containing neither pattern is the common case
|
||||
// (a normal rendered page): the writer must scan all of it.
|
||||
content := []byte(strings.Repeat("<div class=\"nav\"><a href=\"/foo/bar\">baz</a></div>\n", 4000))
|
||||
|
||||
b.ResetTimer()
|
||||
for range b.N {
|
||||
h := &HasBytesWriter{
|
||||
Patterns: []*HasBytesPattern{
|
||||
{Pattern: []byte("__hdeferred/")},
|
||||
{Pattern: []byte("__h_pp_l1")},
|
||||
},
|
||||
}
|
||||
if _, err := h.Write(content); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -33,6 +33,7 @@ import (
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/common/version"
|
||||
"github.com/gohugoio/hugo/hugofs/files"
|
||||
"github.com/gohugoio/hugo/internal/warpc"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
@@ -61,6 +62,11 @@ type BuildInfo struct {
|
||||
GoVersion string
|
||||
}
|
||||
|
||||
// GetBuildDate returns the build date if set by -ldflags="-X github.com/gohugoio/hugo/common/hugo.buildDate="
|
||||
func GetBuildDate() string {
|
||||
return buildDate
|
||||
}
|
||||
|
||||
// GetBuildInfo returns the build info for the current binary.
|
||||
func GetBuildInfo() *BuildInfo {
|
||||
bi := getBuildInfo()
|
||||
@@ -206,7 +212,10 @@ func GetDependencyList() []string {
|
||||
|
||||
// GetDependencyListNonGo returns a list of non-Go dependencies.
|
||||
func GetDependencyListNonGo() []string {
|
||||
deps := []string{formatDep("github.com/webmproject/libwebp", "v1.6.0")} // via WASM. TODO(bep) get versions from the plugin setup.
|
||||
var deps []string
|
||||
for _, dep := range warpc.GetWASMDeps() {
|
||||
deps = append(deps, formatDep(dep[0], dep[1]))
|
||||
}
|
||||
|
||||
if IsExtended {
|
||||
deps = append(
|
||||
@@ -220,7 +229,8 @@ func GetDependencyListNonGo() []string {
|
||||
if IsDartSassGeV2() {
|
||||
dartSassPath = "github.com/sass/dart-sass"
|
||||
}
|
||||
deps = append(deps,
|
||||
deps = append(
|
||||
deps,
|
||||
formatDep(dartSassPath+"/protocol", dartSass.ProtocolVersion),
|
||||
formatDep(dartSassPath+"/compiler", dartSass.CompilerVersion),
|
||||
formatDep(dartSassPath+"/implementation", dartSass.ImplementationVersion),
|
||||
|
||||
@@ -35,8 +35,8 @@ func TestDeprecationLogLevelFromVersion(t *testing.T) {
|
||||
c.Assert(deprecationLogLevelFromVersion(ver.String()), qt.Equals, logg.LevelError)
|
||||
|
||||
// Added just to find the threshold for where we can remove deprecated items.
|
||||
// Subtract 5 from the minor version of the first ERRORed version => 0.136.0.
|
||||
c.Assert(deprecationLogLevelFromVersion("0.141.0"), qt.Equals, logg.LevelError)
|
||||
// Subtract 5 from the minor version of the first ERRORed version => 0.145.0.
|
||||
c.Assert(deprecationLogLevelFromVersion("0.150.0"), qt.Equals, logg.LevelError)
|
||||
}
|
||||
|
||||
func TestMarkupScope(t *testing.T) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import "github.com/gohugoio/hugo/common/version"
|
||||
// This should be the only one.
|
||||
var CurrentVersion = version.Version{
|
||||
Major: 0,
|
||||
Minor: 162,
|
||||
Minor: 165,
|
||||
PatchLevel: 0,
|
||||
Suffix: "-DEV",
|
||||
Suffix: "",
|
||||
}
|
||||
|
||||
+28
-26
@@ -20,6 +20,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"testing/synctest"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/htesting"
|
||||
@@ -28,18 +29,16 @@ import (
|
||||
)
|
||||
|
||||
func TestPara(t *testing.T) {
|
||||
if runtime.NumCPU() < 4 {
|
||||
t.Skipf("skip para test, CPU count is %d", runtime.NumCPU())
|
||||
}
|
||||
|
||||
// TODO(bep)
|
||||
if htesting.IsCI() {
|
||||
t.Skip("skip para test when running on CI")
|
||||
}
|
||||
|
||||
c := qt.New(t)
|
||||
|
||||
c.Run("Order", func(c *qt.C) {
|
||||
if runtime.NumCPU() < 4 {
|
||||
c.Skipf("skip Order subtest, CPU count is %d", runtime.NumCPU())
|
||||
}
|
||||
if htesting.IsCI() {
|
||||
c.Skip("skip Order subtest when running on CI")
|
||||
}
|
||||
|
||||
n := 500
|
||||
ints := make([]int, n)
|
||||
for i := range n {
|
||||
@@ -68,28 +67,31 @@ func TestPara(t *testing.T) {
|
||||
})
|
||||
|
||||
c.Run("Time", func(c *qt.C) {
|
||||
const n = 100
|
||||
synctest.Test(c.TB.(*testing.T), func(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
const n = 100
|
||||
|
||||
p := New(5)
|
||||
r, _ := p.Start(context.Background())
|
||||
p := New(5)
|
||||
r, _ := p.Start(context.Background())
|
||||
|
||||
start := time.Now()
|
||||
start := time.Now()
|
||||
|
||||
var counter int64
|
||||
var counter int64
|
||||
|
||||
for range n {
|
||||
r.Run(func() error {
|
||||
atomic.AddInt64(&counter, 1)
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
for range n {
|
||||
r.Run(func() error {
|
||||
atomic.AddInt64(&counter, 1)
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
c.Assert(r.Wait(), qt.IsNil)
|
||||
c.Assert(counter, qt.Equals, int64(n))
|
||||
c.Assert(r.Wait(), qt.IsNil)
|
||||
c.Assert(counter, qt.Equals, int64(n))
|
||||
|
||||
since := time.Since(start)
|
||||
limit := n / 2 * time.Millisecond
|
||||
c.Assert(since < limit, qt.Equals, true, qt.Commentf("%s >= %s", since, limit))
|
||||
since := time.Since(start)
|
||||
limit := n / 2 * time.Millisecond
|
||||
c.Assert(since < limit, qt.Equals, true, qt.Commentf("%s >= %s", since, limit))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -134,11 +134,6 @@ func (l LowHigh[S]) Value(source S) S {
|
||||
// This is only used for debugging purposes.
|
||||
var InvocationCounter atomic.Int64
|
||||
|
||||
// NewTrue returns a pointer to b.
|
||||
func NewBool(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
// WeightProvider provides a weight.
|
||||
type WeightProvider interface {
|
||||
Weight() int
|
||||
|
||||
@@ -458,36 +458,6 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy privacy values.
|
||||
if c.Privacy.Twitter.Disable {
|
||||
hugo.DeprecateWithLogger("project config key privacy.twitter.disable", "Use privacy.x.disable instead.", "v0.141.0", logger.Logger())
|
||||
c.Privacy.X.Disable = c.Privacy.Twitter.Disable
|
||||
}
|
||||
if c.Privacy.Twitter.EnableDNT {
|
||||
hugo.DeprecateWithLogger("project config key privacy.twitter.enableDNT", "Use privacy.x.enableDNT instead.", "v0.141.0", logger.Logger())
|
||||
c.Privacy.X.EnableDNT = c.Privacy.Twitter.EnableDNT
|
||||
}
|
||||
if c.Privacy.Twitter.Simple {
|
||||
hugo.DeprecateWithLogger("project config key privacy.twitter.simple", "Use privacy.x.simple instead.", "v0.141.0", logger.Logger())
|
||||
c.Privacy.X.Simple = c.Privacy.Twitter.Simple
|
||||
}
|
||||
|
||||
// Legacy services values.
|
||||
if c.Services.Twitter.DisableInlineCSS {
|
||||
hugo.DeprecateWithLogger("project config key services.twitter.disableInlineCSS", "Use services.x.disableInlineCSS instead.", "v0.141.0", logger.Logger())
|
||||
c.Services.X.DisableInlineCSS = c.Services.Twitter.DisableInlineCSS
|
||||
}
|
||||
|
||||
// Legacy permalink tokens
|
||||
for _, pc := range c.Permalinks {
|
||||
if strings.Contains(pc.Pattern, ":filename") {
|
||||
hugo.DeprecateWithLogger("the \":filename\" permalink token", "Use \":contentbasename\" instead.", "0.144.0", logger.Logger())
|
||||
}
|
||||
if strings.Contains(pc.Pattern, ":slugorfilename") {
|
||||
hugo.DeprecateWithLogger("the \":slugorfilename\" permalink token", "Use \":slugorcontentbasename\" instead.", "0.144.0", logger.Logger())
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy render hook values.
|
||||
alternativeDetails := fmt.Sprintf(
|
||||
"Set to %q if previous value was false, or set to %q if previous value was true.",
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/gohugoio/hugo/common/hugo"
|
||||
"github.com/gohugoio/hugo/config/allconfig"
|
||||
"github.com/gohugoio/hugo/hugolib"
|
||||
gc "github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
|
||||
"github.com/gohugoio/hugo/media"
|
||||
)
|
||||
|
||||
@@ -26,11 +25,13 @@ weight = 2
|
||||
[[module.mounts]]
|
||||
source = 'content/en'
|
||||
target = 'content'
|
||||
lang = 'en'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'en'
|
||||
[[module.mounts]]
|
||||
source = 'content/sv'
|
||||
target = 'content'
|
||||
lang = 'sv'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'sv'
|
||||
-- content/en/p1.md --
|
||||
---
|
||||
title: "p1"
|
||||
@@ -360,25 +361,46 @@ weight = 3
|
||||
|
||||
// Issue 13535
|
||||
// We changed enablement of the embedded link and image render hooks from
|
||||
// booleans to enums in v0.148.0.
|
||||
// booleans to enums in v0.148.0. This should throw error with v0.163.0 and later.
|
||||
func TestLegacyEmbeddedRenderHookEnablement(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
[markup.goldmark.renderHooks.image]
|
||||
#KEY_VALUE
|
||||
#KEY_VALUE_IMAGE
|
||||
|
||||
[markup.goldmark.renderHooks.link]
|
||||
#KEY_VALUE
|
||||
#KEY_VALUE_LINK
|
||||
`
|
||||
f := strings.ReplaceAll(files, "#KEY_VALUE", "enableDefault = false")
|
||||
b := hugolib.Test(t, f)
|
||||
c := b.H.Configs.Base.Markup.Goldmark.RenderHooks
|
||||
b.Assert(c.Link.UseEmbedded, qt.Equals, gc.RenderHookUseEmbeddedNever)
|
||||
b.Assert(c.Image.UseEmbedded, qt.Equals, gc.RenderHookUseEmbeddedNever)
|
||||
|
||||
f = strings.ReplaceAll(files, "#KEY_VALUE", "enableDefault = true")
|
||||
b = hugolib.Test(t, f)
|
||||
c = b.H.Configs.Base.Markup.Goldmark.RenderHooks
|
||||
b.Assert(c.Link.UseEmbedded, qt.Equals, gc.RenderHookUseEmbeddedFallback)
|
||||
b.Assert(c.Image.UseEmbedded, qt.Equals, gc.RenderHookUseEmbeddedFallback)
|
||||
replacer := strings.NewReplacer(
|
||||
"#KEY_VALUE_IMAGE", "enableDefault = false",
|
||||
"#KEY_VALUE_LINK", "",
|
||||
)
|
||||
f := replacer.Replace(files)
|
||||
b, _ := hugolib.TestE(t, f)
|
||||
b.AssertLogContains("ERROR deprecated")
|
||||
|
||||
replacer = strings.NewReplacer(
|
||||
"#KEY_VALUE_IMAGE", "enableDefault = true",
|
||||
"#KEY_VALUE_LINK", "",
|
||||
)
|
||||
f = replacer.Replace(files)
|
||||
b, _ = hugolib.TestE(t, f)
|
||||
b.AssertLogContains("ERROR deprecated")
|
||||
|
||||
replacer = strings.NewReplacer(
|
||||
"#KEY_VALUE_IMAGE", "",
|
||||
"#KEY_VALUE_LINK", "enableDefault = false",
|
||||
)
|
||||
f = replacer.Replace(files)
|
||||
b, _ = hugolib.TestE(t, f)
|
||||
b.AssertLogContains("ERROR deprecated")
|
||||
|
||||
replacer = strings.NewReplacer(
|
||||
"#KEY_VALUE_IMAGE", "",
|
||||
"#KEY_VALUE_LINK", "enableDefault = true",
|
||||
)
|
||||
f = replacer.Replace(files)
|
||||
b, _ = hugolib.TestE(t, f)
|
||||
b.AssertLogContains("ERROR deprecated")
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/gohugoio/hugo/cache/httpcache"
|
||||
"github.com/gohugoio/hugo/common/hmaps"
|
||||
"github.com/gohugoio/hugo/common/hstrings"
|
||||
"github.com/gohugoio/hugo/common/hugo"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/common/types"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
@@ -87,8 +88,18 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||
"imaging": {
|
||||
key: "imaging",
|
||||
decode: func(d decodeWeight, p decodeConfig) error {
|
||||
m := p.p.GetStringMap(d.key)
|
||||
if _, found := m["quality"]; found {
|
||||
hugo.DeprecateWithLogger("project config key imaging.quality", "Set the quality per format instead with imaging.jpeg.quality, imaging.webp.quality and/or imaging.avif.quality.", "v0.163.0", p.logger.Logger())
|
||||
}
|
||||
if _, found := m["compression"]; found {
|
||||
hugo.DeprecateWithLogger("project config key imaging.compression", "Set the compression type per format instead with imaging.webp.compression and/or imaging.avif.compression.", "v0.163.0", p.logger.Logger())
|
||||
}
|
||||
if _, found := m["hint"]; found {
|
||||
hugo.DeprecateWithLogger("project config key imaging.hint", "Set the hint per format instead with imaging.webp.hint and/or imaging.avif.hint.", "v0.163.0", p.logger.Logger())
|
||||
}
|
||||
var err error
|
||||
p.c.Imaging, err = images.DecodeConfig(p.p.GetStringMap(d.key))
|
||||
p.c.Imaging, err = images.DecodeConfig(m)
|
||||
return err
|
||||
},
|
||||
},
|
||||
|
||||
@@ -67,6 +67,15 @@ func (c ConfigLanguage) BaseURLLiveReload() urls.BaseURL {
|
||||
return c.config.C.BaseURLLiveReload
|
||||
}
|
||||
|
||||
// AllBaseURLs returns the BaseURL for each enabled language, ordered as Languages().
|
||||
func (c ConfigLanguage) AllBaseURLs() []urls.BaseURL {
|
||||
bs := make([]urls.BaseURL, len(c.m.configLangs))
|
||||
for i, p := range c.m.configLangs {
|
||||
bs[i] = p.BaseURL()
|
||||
}
|
||||
return bs
|
||||
}
|
||||
|
||||
func (c ConfigLanguage) Environment() string {
|
||||
return c.config.Environment
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/gohugoio/hugo/docshelper"
|
||||
)
|
||||
|
||||
// This is is just some helpers used to create some JSON used in the Hugo docs.
|
||||
// This is just a helper used to create some JSON used in the Hugo docs.
|
||||
func init() {
|
||||
docsProvider := func() docshelper.DocProvider {
|
||||
cfg := config.New()
|
||||
|
||||
@@ -19,19 +19,23 @@ defaultContentLanguage = 'en'
|
||||
[[module.mounts]]
|
||||
source = 'content/en'
|
||||
target = 'content/en'
|
||||
lang = 'en'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'en'
|
||||
[[module.mounts]]
|
||||
source = 'content/nn'
|
||||
target = 'content/nn'
|
||||
lang = 'nn'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'nn'
|
||||
[[module.mounts]]
|
||||
source = 'content/no'
|
||||
target = 'content/no'
|
||||
lang = 'no'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'no'
|
||||
[[module.mounts]]
|
||||
source = 'content/sv'
|
||||
target = 'content/sv'
|
||||
lang = 'sv'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'sv'
|
||||
[[module.mounts]]
|
||||
source = 'layouts'
|
||||
target = 'layouts'
|
||||
|
||||
@@ -88,7 +88,7 @@ var defaultBuild = BuildConfig{
|
||||
|
||||
CacheBusters: []CacheBuster{
|
||||
{
|
||||
Source: `(postcss|tailwind)\.config\.js`,
|
||||
Source: `(postcss|tailwind)\.config\.(js|mjs|cjs)`,
|
||||
Target: cssTargetCachebusterRe,
|
||||
},
|
||||
},
|
||||
|
||||
+13
-1
@@ -173,9 +173,11 @@ func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provid
|
||||
}
|
||||
|
||||
var keyPath []string
|
||||
var unwrapKey string
|
||||
if !DefaultConfigNamesSet[name] {
|
||||
// Can be params.jp, menus.en etc.
|
||||
name, lang := paths.FileAndExtNoDelimiter(name)
|
||||
unwrapKey = name
|
||||
|
||||
keyPath = []string{name}
|
||||
|
||||
@@ -190,13 +192,23 @@ func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provid
|
||||
}
|
||||
}
|
||||
|
||||
// TOML/YAML can't represent a headless top-level array, so allow a
|
||||
// file to wrap its content under a single top-level key matching
|
||||
// the basename (e.g. cascade.yaml with `cascade: [...]`).
|
||||
var itemValue any = item
|
||||
if unwrapKey != "" && len(item) == 1 {
|
||||
if inner, ok := item[unwrapKey]; ok {
|
||||
itemValue = inner
|
||||
}
|
||||
}
|
||||
|
||||
root := item
|
||||
if len(keyPath) > 0 {
|
||||
root = make(map[string]any)
|
||||
m := root
|
||||
for i, key := range keyPath {
|
||||
if i >= len(keyPath)-1 {
|
||||
m[key] = item
|
||||
m[key] = itemValue
|
||||
} else {
|
||||
nm := make(map[string]any)
|
||||
m[key] = nm
|
||||
|
||||
@@ -30,7 +30,6 @@ type Config struct {
|
||||
Disqus Disqus
|
||||
GoogleAnalytics GoogleAnalytics
|
||||
Instagram Instagram
|
||||
Twitter Twitter `json:"-"` // deprecated in favor of X in v0.141.0
|
||||
Vimeo Vimeo
|
||||
YouTube YouTube
|
||||
X X
|
||||
@@ -59,19 +58,6 @@ type Instagram struct {
|
||||
Simple bool
|
||||
}
|
||||
|
||||
// Twitter holds the privacy configuration settings related to the Twitter shortcode.
|
||||
// Deprecated in favor of X in v0.141.0.
|
||||
type Twitter struct {
|
||||
Service `mapstructure:",squash"`
|
||||
|
||||
// When set to true, the Tweet and its embedded page on your site are not used
|
||||
// for purposes that include personalized suggestions and personalized ads.
|
||||
EnableDNT bool
|
||||
|
||||
// If simple mode is enabled, a static and no-JS version of the Tweet will be built.
|
||||
Simple bool
|
||||
}
|
||||
|
||||
// Vimeo holds the privacy configuration settings related to the Vimeo shortcode.
|
||||
type Vimeo struct {
|
||||
Service `mapstructure:",squash"`
|
||||
|
||||
@@ -18,8 +18,11 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
@@ -36,12 +39,11 @@ const securityConfigKey = "security"
|
||||
var DefaultConfig = Config{
|
||||
Exec: Exec{
|
||||
Allow: MustNewWhitelist(
|
||||
"^(dart-)?sass(-embedded)?$", // sass, dart-sass, dart-sass-embedded.
|
||||
"^go$", // for Go Modules
|
||||
"^git$", // For Git info
|
||||
"^node$", // Used as the runtime for Node tools.
|
||||
"^(dart-)?sass$", // sass, dart-sass
|
||||
"^go$", // for Go Modules
|
||||
"^git$", // For Git info
|
||||
"^node$", // Used as the runtime for Node tools.
|
||||
"^postcss$",
|
||||
"^tailwindcss$",
|
||||
),
|
||||
// These have been tested to work with Hugo's external programs
|
||||
// on Windows, Linux and MacOS.
|
||||
@@ -57,7 +59,8 @@ var DefaultConfig = Config{
|
||||
// foil the obvious SSRF bypass. Public IP literals are collateral
|
||||
// blocks; users who need them can override security.http.urls.
|
||||
URLs: MustNewWhitelist(
|
||||
`(?i)^https?://[a-z]`,
|
||||
`(?i)^https?://[a-z0-9]`,
|
||||
`! ^https?://\d+\.`,
|
||||
`! (?i)localhost`,
|
||||
`! (?i)^https?://[^/?#]*@`,
|
||||
),
|
||||
@@ -73,6 +76,11 @@ var DefaultConfig = Config{
|
||||
AllowChildProcess: []string{"tailwindcss"}, // detect-libc spawns getconf on some Linux setups.
|
||||
},
|
||||
},
|
||||
// Content under /content is treated as untrusted. text/html bodies are
|
||||
// emitted verbatim and are an XSS sink, so they are denied by default.
|
||||
// Everything else is allowed because Whitelist treats a deny-only list as
|
||||
// "allow anything not denied".
|
||||
AllowContent: MustNewWhitelist("! ^text/html$"),
|
||||
}
|
||||
|
||||
// Config is the top level security config.
|
||||
@@ -91,6 +99,12 @@ type Config struct {
|
||||
// Node holds Node.js security settings.
|
||||
Node Node `json:"node"`
|
||||
|
||||
// AllowContent restricts which content media types may be used for
|
||||
// pages under /content. Matched against the full MIME type (e.g.
|
||||
// "text/html"). text/html is denied by default because Hugo emits the
|
||||
// body verbatim.
|
||||
AllowContent Whitelist `json:"allowContent"`
|
||||
|
||||
// Allow inline shortcodes
|
||||
EnableInlineShortcodes bool `json:"enableInlineShortcodes"`
|
||||
}
|
||||
@@ -177,17 +191,102 @@ func (c Config) CheckAllowedGetEnv(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) CheckAllowedHTTPURL(url string) error {
|
||||
if !c.HTTP.URLs.Accept(url) {
|
||||
func (c Config) CheckAllowedHTTPURL(u string) error {
|
||||
deny := func(name string) error {
|
||||
return &AccessDeniedError{
|
||||
name: url,
|
||||
name: name,
|
||||
path: "security.http.urls",
|
||||
policies: c.ToTOML(),
|
||||
}
|
||||
}
|
||||
if !c.HTTP.URLs.Accept(u) {
|
||||
return deny(u)
|
||||
}
|
||||
// A host can be written as an integer/hex/octal IPv4 literal
|
||||
// (e.g. http://2130706433/ == http://127.0.0.1/) that has no dot and
|
||||
// thus slips past IP-literal deny rules. Re-check the canonical form so
|
||||
// the policy treats every encoding of the same address alike.
|
||||
if canon, ok := canonicalIPv4URL(u); ok && !c.HTTP.URLs.Accept(canon) {
|
||||
return deny(u)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// canonicalIPv4URL rewrites an integer/hex/octal IPv4 host in rawURL to its
|
||||
// canonical dotted-decimal form (inet_aton semantics), returning ok=false when
|
||||
// the host is a normal name or already dotted-decimal.
|
||||
func canonicalIPv4URL(rawURL string) (string, bool) {
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
host := u.Hostname()
|
||||
ip, ok := parseInetAtonIPv4(host)
|
||||
if !ok || ip.String() == host {
|
||||
return "", false
|
||||
}
|
||||
if port := u.Port(); port != "" {
|
||||
u.Host = ip.String() + ":" + port
|
||||
} else {
|
||||
u.Host = ip.String()
|
||||
}
|
||||
return u.String(), true
|
||||
}
|
||||
|
||||
// parseInetAtonIPv4 parses the inet_aton IPv4 forms (1–4 dot-separated parts,
|
||||
// each decimal, octal "0..." or hex "0x..."), e.g. "2130706433", "0x7f.0.0.1".
|
||||
func parseInetAtonIPv4(host string) (netip.Addr, bool) {
|
||||
if host == "" {
|
||||
return netip.Addr{}, false
|
||||
}
|
||||
parts := strings.Split(host, ".")
|
||||
if len(parts) > 4 {
|
||||
return netip.Addr{}, false
|
||||
}
|
||||
vals := make([]uint64, len(parts))
|
||||
for i, p := range parts {
|
||||
v, ok := parseCInt(p)
|
||||
if !ok {
|
||||
return netip.Addr{}, false
|
||||
}
|
||||
vals[i] = v
|
||||
}
|
||||
maxLast := []uint64{0xffffffff, 0xffffff, 0xffff, 0xff}[len(parts)-1]
|
||||
var n uint64
|
||||
for i, v := range vals {
|
||||
if i == len(parts)-1 {
|
||||
if v > maxLast {
|
||||
return netip.Addr{}, false
|
||||
}
|
||||
n |= v
|
||||
} else {
|
||||
if v > 0xff {
|
||||
return netip.Addr{}, false
|
||||
}
|
||||
n |= v << (8 * (3 - i))
|
||||
}
|
||||
}
|
||||
return netip.AddrFrom4([4]byte{byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)}), true
|
||||
}
|
||||
|
||||
func parseCInt(s string) (uint64, bool) {
|
||||
base := 10
|
||||
switch {
|
||||
case len(s) >= 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'):
|
||||
base, s = 16, s[2:]
|
||||
case len(s) >= 2 && s[0] == '0':
|
||||
base, s = 8, s[1:]
|
||||
}
|
||||
if s == "" {
|
||||
return 0, false
|
||||
}
|
||||
v, err := strconv.ParseUint(s, base, 64)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
return v, true
|
||||
}
|
||||
|
||||
func (c Config) CheckAllowedHTTPMethod(method string) error {
|
||||
if !c.HTTP.Methods.Accept(method) {
|
||||
return &AccessDeniedError{
|
||||
@@ -199,6 +298,17 @@ func (c Config) CheckAllowedHTTPMethod(method string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) CheckAllowedContent(mediaType string) error {
|
||||
if !c.AllowContent.Accept(mediaType) {
|
||||
return &AccessDeniedError{
|
||||
name: mediaType,
|
||||
path: "security.allowContent",
|
||||
policies: c.ToTOML(),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToSecurityMap converts c to a map with 'security' as the root key.
|
||||
func (c Config) ToSecurityMap() map[string]any {
|
||||
// Take it to JSON and back to get proper casing etc.
|
||||
|
||||
@@ -135,7 +135,7 @@ func TestToTOML(t *testing.T) {
|
||||
got := DefaultConfig.ToTOML()
|
||||
|
||||
c.Assert(got, qt.Equals,
|
||||
"[security]\n enableInlineShortcodes = false\n\n [security.exec]\n allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^node$', '^postcss$', '^tailwindcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE|PROGRAMDATA)$']\n\n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['(?i)^https?://[a-z]', '! (?i)localhost', '! (?i)^https?://[^/?#]*@']\n\n [security.node]\n [security.node.permissions]\n allowAddons = ['tailwindcss']\n allowChildProcess = ['tailwindcss']\n allowRead = ['.']\n allowWorker = ['tailwindcss']\n allowWrite = []\n disable = false",
|
||||
"[security]\n allowContent = ['! ^text/html$']\n enableInlineShortcodes = false\n\n [security.exec]\n allow = ['^(dart-)?sass$', '^go$', '^git$', '^node$', '^postcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE|PROGRAMDATA)$']\n\n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['(?i)^https?://[a-z0-9]', '! ^https?://\\d+\\.', '! (?i)localhost', '! (?i)^https?://[^/?#]*@']\n\n [security.node]\n [security.node.permissions]\n allowAddons = ['tailwindcss']\n allowChildProcess = ['tailwindcss']\n allowRead = ['.']\n allowWorker = ['tailwindcss']\n allowWrite = []\n disable = false",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -273,6 +273,108 @@ func TestCheckAllowedHTTPURLAtInPathIssue14825(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckAllowedHTTPURLDigitHostnameIssue14837(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
|
||||
pc, err := DecodeConfig(config.New())
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
for _, u := range []string{
|
||||
"https://1password.com/",
|
||||
"https://37signals.com/foo",
|
||||
} {
|
||||
c.Assert(pc.CheckAllowedHTTPURL(u), qt.IsNil, qt.Commentf(u))
|
||||
}
|
||||
|
||||
for _, u := range []string{
|
||||
"http://127.0.0.1/",
|
||||
"http://10.0.0.1/",
|
||||
"http://192.168.1.1/",
|
||||
"http://0.0.0.0/",
|
||||
} {
|
||||
err := pc.CheckAllowedHTTPURL(u)
|
||||
c.Assert(err, qt.IsNotNil, qt.Commentf(u))
|
||||
}
|
||||
}
|
||||
|
||||
// Integer/hex/octal IPv4 encodings must be denied just like their dotted-decimal
|
||||
// literals; digit-leading hostnames must still be allowed. See issue 14856.
|
||||
func TestCheckAllowedHTTPURLIntegerIPEncodings(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
|
||||
pc, err := DecodeConfig(config.New())
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
for _, u := range []string{
|
||||
"http://2130706433/", // 127.0.0.1 decimal
|
||||
"http://2130706433:9777/x", // 127.0.0.1 decimal, port
|
||||
"http://2852039166/", // 169.254.169.254 (cloud metadata)
|
||||
"http://0x7f000001/", // 127.0.0.1 hex
|
||||
"http://017700000001/", // 127.0.0.1 octal
|
||||
"http://0x7f.0.0.1/", // 127.0.0.1 dotted hex
|
||||
"http://0177.0.0.1/", // 127.0.0.1 dotted octal
|
||||
"http://127.1/", // 127.0.0.1 short form
|
||||
"http://0/", // 0.0.0.0
|
||||
"http://0xa9fea9fe/", // 169.254.169.254 hex
|
||||
} {
|
||||
err := pc.CheckAllowedHTTPURL(u)
|
||||
c.Assert(err, qt.IsNotNil, qt.Commentf(u))
|
||||
}
|
||||
|
||||
for _, u := range []string{
|
||||
"https://1password.com/",
|
||||
"https://37signals.com/foo",
|
||||
"https://3com.com/",
|
||||
"https://0x.tools/",
|
||||
} {
|
||||
c.Assert(pc.CheckAllowedHTTPURL(u), qt.IsNil, qt.Commentf(u))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckAllowedContent(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
|
||||
c.Run("text/html denied by default", func(c *qt.C) {
|
||||
c.Parallel()
|
||||
pc, err := DecodeConfig(config.New())
|
||||
c.Assert(err, qt.IsNil)
|
||||
err = pc.CheckAllowedContent("text/html")
|
||||
c.Assert(err, qt.IsNotNil)
|
||||
c.Assert(err, qt.ErrorMatches, `(?s).*"text/html" is not whitelisted in policy "security\.allowContent".*`)
|
||||
})
|
||||
|
||||
c.Run("Other content types allowed by default", func(c *qt.C) {
|
||||
c.Parallel()
|
||||
pc, err := DecodeConfig(config.New())
|
||||
c.Assert(err, qt.IsNil)
|
||||
for _, mt := range []string{
|
||||
"text/markdown",
|
||||
"text/asciidoc",
|
||||
"text/x-org",
|
||||
"text/rst",
|
||||
"text/pandoc",
|
||||
} {
|
||||
c.Assert(pc.CheckAllowedContent(mt), qt.IsNil, qt.Commentf(mt))
|
||||
}
|
||||
})
|
||||
|
||||
c.Run("User can opt in to HTML", func(c *qt.C) {
|
||||
c.Parallel()
|
||||
tomlConfig := `
|
||||
[security]
|
||||
allowContent = ['.*']
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
c.Assert(err, qt.IsNil)
|
||||
pc, err := DecodeConfig(cfg)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(pc.CheckAllowedContent("text/html"), qt.IsNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDecodeConfigNodePermissions(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ type Config struct {
|
||||
Disqus Disqus
|
||||
GoogleAnalytics GoogleAnalytics
|
||||
Instagram Instagram `json:"-"` // the embedded instagram shortcode no longer uses this
|
||||
Twitter Twitter `json:"-"` // deprecated in favor of X in v0.141.0
|
||||
X X
|
||||
RSS RSS
|
||||
}
|
||||
@@ -61,15 +60,6 @@ type Instagram struct {
|
||||
AccessToken string // this is no longer used by the embedded instagram shortcode
|
||||
}
|
||||
|
||||
// Twitter holds the functional configuration settings related to the Twitter shortcodes.
|
||||
// Deprecated in favor of X in v0.141.0.
|
||||
type Twitter struct {
|
||||
// The Simple variant of Twitter is decorated with a basic set of inline styles.
|
||||
// This means that if you want to provide your own CSS, you want
|
||||
// to disable the inline CSS provided by Hugo.
|
||||
DisableInlineCSS bool
|
||||
}
|
||||
|
||||
// X holds the functional configuration settings related to the X shortcodes.
|
||||
type X struct {
|
||||
// The Simple variant of X is decorated with a basic set of inline styles.
|
||||
|
||||
@@ -68,6 +68,9 @@ func GetTestDeps(fs afero.Fs, cfg config.Provider, beforeInit ...func(*deps.Deps
|
||||
warpc.Options{
|
||||
PoolSize: 1,
|
||||
},
|
||||
warpc.Options{
|
||||
PoolSize: 1,
|
||||
},
|
||||
),
|
||||
}
|
||||
for _, f := range beforeInit {
|
||||
|
||||
+37
-6
@@ -74,7 +74,6 @@ func TestNewContentFromFile(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
for i, cas := range cases {
|
||||
|
||||
c.Run(cas.name, func(c *qt.C) {
|
||||
c.Parallel()
|
||||
|
||||
@@ -109,7 +108,6 @@ func TestNewContentFromFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +157,37 @@ site RegularPages: {{ len site.RegularPages }}
|
||||
cContains(c, readFileFromFs(t, fs.Source, filepath.Join("content", "mypage.md")), `draft: true`)
|
||||
}
|
||||
|
||||
// See issue 15078.
|
||||
func TestNewContentWithBuildCascade(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mm := afero.NewMemMapFs()
|
||||
c := qt.New(t)
|
||||
|
||||
c.Assert(initFs(mm), qt.IsNil)
|
||||
c.Assert(mm.MkdirAll(filepath.Join("content", "posts", "drafts"), 0o755), qt.IsNil)
|
||||
c.Assert(afero.WriteFile(mm, filepath.Join("content", "posts", "drafts", "_index.md"), []byte(`---
|
||||
title: Drafts
|
||||
build:
|
||||
render: never
|
||||
cascade:
|
||||
draft: true
|
||||
build:
|
||||
render: link
|
||||
draft: true
|
||||
---
|
||||
`), 0o755), qt.IsNil)
|
||||
|
||||
cfg, fs := newTestCfg(c, mm)
|
||||
conf := testconfig.GetTestConfigs(fs.Source, cfg)
|
||||
h, err := hugolib.NewHugoSites(deps.DepsCfg{Configs: conf, Fs: fs})
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
const target = "posts/drafts/trip-to-puebla/index.md"
|
||||
c.Assert(create.NewContent(h, "", target, false), qt.IsNil)
|
||||
c.Assert(readFileFromFs(c, fs.Source, filepath.Join("content", target)), qt.Contains, `title: "Trip to Puebla"`)
|
||||
}
|
||||
|
||||
func initFs(fs afero.Fs) error {
|
||||
perm := os.FileMode(0o755)
|
||||
var err error
|
||||
@@ -308,10 +337,10 @@ theme = "mytheme"
|
||||
[languages]
|
||||
[languages.en]
|
||||
weight = 1
|
||||
languageName = "English"
|
||||
label = "English"
|
||||
[languages.nn]
|
||||
weight = 2
|
||||
languageName = "Nynorsk"
|
||||
label = "Nynorsk"
|
||||
|
||||
[module]
|
||||
[[module.mounts]]
|
||||
@@ -320,11 +349,13 @@ languageName = "Nynorsk"
|
||||
[[module.mounts]]
|
||||
source = 'content'
|
||||
target = 'content'
|
||||
lang = 'en'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'en'
|
||||
[[module.mounts]]
|
||||
source = 'content_nn'
|
||||
target = 'content'
|
||||
lang = 'nn'
|
||||
[module.mounts.sites.matrix]
|
||||
languages = 'nn'
|
||||
`
|
||||
if mm == nil {
|
||||
mm = afero.NewMemMapFs()
|
||||
|
||||
Vendored
+18
@@ -435,10 +435,28 @@ type DepsCfg struct {
|
||||
// Build triggered by the IntegrationTest framework.
|
||||
IsIntegrationTest bool
|
||||
|
||||
// TestCfg holds configuration used only in tests.
|
||||
// It is a programming error to set this when IsIntegrationTest is not set,
|
||||
// and doing so will panic.
|
||||
TestCfg TestConfig
|
||||
|
||||
// ChangesFromBuild for changes passed back to the server/watch process.
|
||||
ChangesFromBuild chan []identity.Identity
|
||||
}
|
||||
|
||||
// TestConfig holds configuration used only in tests.
|
||||
// See DepsCfg.TestCfg.
|
||||
type TestConfig struct {
|
||||
// WarpcMemory, if set, overrides the memory limit in MiB for the WASM based
|
||||
// image processors (WebP and AVIF). Used to provoke memory allocation failures.
|
||||
WarpcMemory int
|
||||
}
|
||||
|
||||
// IsZero reports whether c holds no test configuration.
|
||||
func (c TestConfig) IsZero() bool {
|
||||
return c == TestConfig{}
|
||||
}
|
||||
|
||||
// BuildState are state used during a build.
|
||||
type BuildState struct {
|
||||
counter uint64
|
||||
|
||||
+8
-5
@@ -77,7 +77,7 @@
|
||||
"unmarshaling",
|
||||
"unmarshals",
|
||||
// ------------------------------------------------------------------------
|
||||
// cspell: ignore hugo terminology",
|
||||
// cspell: ignore hugo terminology
|
||||
// ------------------------------------------------------------------------
|
||||
"alignx",
|
||||
"aligny",
|
||||
@@ -102,8 +102,10 @@
|
||||
"unpublishdate",
|
||||
"zgotmplz",
|
||||
// ------------------------------------------------------------------------
|
||||
// cspell: ignore foreign language words",
|
||||
// cspell: ignore foreign language words
|
||||
// ------------------------------------------------------------------------
|
||||
"Bokmål",
|
||||
"Norsk",
|
||||
"bezpieczeństwo",
|
||||
"blatt",
|
||||
"buch",
|
||||
@@ -130,7 +132,7 @@
|
||||
"referenz",
|
||||
"régime",
|
||||
// ------------------------------------------------------------------------
|
||||
// cspell: ignore names",
|
||||
// cspell: ignore names
|
||||
// ------------------------------------------------------------------------
|
||||
"Atishay",
|
||||
"Cosette",
|
||||
@@ -149,8 +151,9 @@
|
||||
"Vitter",
|
||||
"WASI",
|
||||
// ------------------------------------------------------------------------
|
||||
// cspell: ignore operating systems and software packages",
|
||||
// cspell: ignore operating systems and software packages
|
||||
// ------------------------------------------------------------------------
|
||||
"ananke",
|
||||
"asciidoctor",
|
||||
"brotli",
|
||||
"cifs",
|
||||
@@ -173,7 +176,7 @@
|
||||
"rclone",
|
||||
"xubuntu",
|
||||
// ------------------------------------------------------------------------
|
||||
// cspell: ignore miscellaneous",
|
||||
// cspell: ignore miscellaneous
|
||||
// ------------------------------------------------------------------------
|
||||
"achristie",
|
||||
"ccpa",
|
||||
|
||||
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
name: Lint
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
markdownlint:
|
||||
name: Lint Markdown
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Run Markdown linter
|
||||
uses: DavidAnson/markdownlint-cli2-action@ded1f9488f68a970bc66ea5619e13e9b52e601cd # v23.2.0
|
||||
with:
|
||||
globs: # set to null to override default of *.{md,markdown}
|
||||
|
||||
spellcheck:
|
||||
name: Check spelling
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Check spelling with cspell
|
||||
uses: streetsidesoftware/cspell-action@de2a73e963e7443969755b648a1008f77033c5b2 # v8.4.0
|
||||
with:
|
||||
incremental_files_only: true
|
||||
strict: true
|
||||
# cspell uses the .cspell.json configuration file
|
||||
- name: Check spelling with codespell
|
||||
uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2
|
||||
with:
|
||||
check_filenames: true
|
||||
check_hidden: true
|
||||
# codespell uses the .codespellrc file
|
||||
|
||||
template-formatting:
|
||||
name: Check template formatting
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
|
||||
with:
|
||||
go-version: "1.26"
|
||||
check-latest: true
|
||||
cache: true
|
||||
cache-dependency-path: |
|
||||
**/go.sum
|
||||
**/go.mod
|
||||
- name: Install gotmplfmt
|
||||
run: go install github.com/gohugoio/gotmplfmt@623175f49b3d07a11da381ff85228d0d03101880 # v0.4.1
|
||||
- name: Check template formatting
|
||||
run: "diff <(gotmplfmt -d layouts) <(printf '')"
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
name: Lint markdown
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
|
||||
- name: Run Markdown linter
|
||||
uses: DavidAnson/markdownlint-cli2-action@30a0e04f1870d58f8d717450cc6134995f993c63 # v21.0.0
|
||||
with:
|
||||
globs: # set to null to override default of *.{md,markdown}
|
||||
continue-on-error: false
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
name: "Check spelling"
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
branches-ignore:
|
||||
- "dependabot/**"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
spellcheck:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
|
||||
- uses: streetsidesoftware/cspell-action@3294df585d3d639e30f3bc019cb11940b9866e95 # v8.0.0
|
||||
with:
|
||||
incremental_files_only: true
|
||||
strict: true
|
||||
# cspell uses the .cspell.json configuration file
|
||||
- uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2
|
||||
with:
|
||||
check_filenames: true
|
||||
check_hidden: true
|
||||
# codespell uses the .codespellrc file
|
||||
@@ -1,18 +1,3 @@
|
||||
# Ignore all SVG icons.
|
||||
**/icons.html
|
||||
|
||||
# These are whitespace sensitive.
|
||||
layouts/_markup/render-code*
|
||||
layouts/_markup/render-table*
|
||||
layouts/_shortcodes/glossary-term.html
|
||||
layouts/_shortcodes/glossary.html
|
||||
layouts/_shortcodes/highlighting-styles.html
|
||||
layouts/_shortcodes/list-pages-in-section.html
|
||||
layouts/_shortcodes/quick-reference.html
|
||||
|
||||
# No root node.
|
||||
layouts/_partials/layouts/head/head.html
|
||||
|
||||
# Auto generated.
|
||||
assets/css/components/chroma*.css
|
||||
assets/jsconfig.json
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
"prettier-plugin-go-template",
|
||||
"@awmottaz/prettier-plugin-void-html"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"options": {
|
||||
"parser": "go-template",
|
||||
"goTemplateBracketSpacing": true,
|
||||
"bracketSameLine": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.js", "*.ts"],
|
||||
"options": {
|
||||
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"DavidAnson.vscode-markdownlint",
|
||||
"EditorConfig.EditorConfig",
|
||||
"streetsidesoftware.code-spell-checker"
|
||||
]
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: {{ replace .File.ContentBaseName "-" " " }}
|
||||
params:
|
||||
reference:
|
||||
reference:
|
||||
---
|
||||
|
||||
<!--
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* pre */
|
||||
@apply prose-pre:text-gray-800 prose-pre:border-1 prose-pre:border-gray-100 prose-pre:bg-light dark:prose-pre:bg-dark dark:prose-pre:ring-1 dark:prose-pre:ring-slate-300/10;
|
||||
/* code */
|
||||
@apply prose-code:px-0.5 prose-code:text-gray-500 prose-code:dark:text-gray-300 border-none;
|
||||
@apply prose-code:px-0.5 prose-code:text-gray-600 prose-code:dark:text-gray-300 border-none;
|
||||
@apply prose-code:before:hidden prose-code:after:hidden prose-code:font-mono;
|
||||
@apply prose-table:prose-th:prose-code:text-white;
|
||||
/* tables */
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
/* Opt in to native cross-document view transitions on navigation. */
|
||||
@view-transition {
|
||||
navigation: auto;
|
||||
}
|
||||
|
||||
/* Global slight fade */
|
||||
::view-transition-old(root),
|
||||
::view-transition-new(root) {
|
||||
animation-duration: 200ms;
|
||||
}
|
||||
|
||||
::view-transition-old(qr),
|
||||
::view-transition-new(qr) {
|
||||
animation-duration: 800ms;
|
||||
animation-delay: 250ms;
|
||||
}
|
||||
|
||||
.view-transition-qr {
|
||||
view-transition-name: qr;
|
||||
}
|
||||
|
||||
/* Turbo styles */
|
||||
.turbo-progress-bar {
|
||||
visibility: hidden;
|
||||
/*
|
||||
* Persistent chrome (header/footer) is named so it gets its own snapshot
|
||||
* instead of being part of the root crossfade. Holding it static prevents
|
||||
* the flicker that the sticky header otherwise shows on every navigation.
|
||||
*/
|
||||
::view-transition-group(site-header),
|
||||
::view-transition-group(site-footer),
|
||||
::view-transition-old(site-header),
|
||||
::view-transition-new(site-header),
|
||||
::view-transition-old(site-footer),
|
||||
::view-transition-new(site-footer) {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
var debug = 0 ? console.log.bind(console, '[explorer]') : function () {};
|
||||
|
||||
// This is currently not used, but kept in case I change my mind.
|
||||
export const explorer = (Alpine) => ({
|
||||
uiState: {
|
||||
containerScrollTop: -1,
|
||||
lastActiveRef: '',
|
||||
},
|
||||
treeState: {
|
||||
// The href of the current page.
|
||||
currentNode: '',
|
||||
// The state of each node in the tree.
|
||||
nodes: {},
|
||||
|
||||
// We currently only list the sections, not regular pages, in the side bar.
|
||||
// This strikes me as the right balance. The pages gets listed on the section pages.
|
||||
// This array is sorted by length, so we can find the longest prefix of the current page
|
||||
// without having to iterate over all the keys.
|
||||
nodeRefsByLength: [],
|
||||
},
|
||||
async init() {
|
||||
let keys = Reflect.ownKeys(this.$refs);
|
||||
for (let key of keys) {
|
||||
let n = {
|
||||
open: false,
|
||||
active: false,
|
||||
};
|
||||
this.treeState.nodes[key] = n;
|
||||
this.treeState.nodeRefsByLength.push(key);
|
||||
}
|
||||
|
||||
this.treeState.nodeRefsByLength.sort((a, b) => b.length - a.length);
|
||||
|
||||
this.setCurrentActive();
|
||||
},
|
||||
|
||||
longestPrefix(ref) {
|
||||
let longestPrefix = '';
|
||||
for (let key of this.treeState.nodeRefsByLength) {
|
||||
if (ref.startsWith(key)) {
|
||||
longestPrefix = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return longestPrefix;
|
||||
},
|
||||
|
||||
setCurrentActive() {
|
||||
let ref = this.longestPrefix(window.location.pathname);
|
||||
let activeChanged = this.uiState.lastActiveRef !== ref;
|
||||
debug('setCurrentActive', this.uiState.lastActiveRef, window.location.pathname, '=>', ref, activeChanged);
|
||||
this.uiState.lastActiveRef = ref;
|
||||
if (this.uiState.containerScrollTop === -1 && activeChanged) {
|
||||
// Navigation outside of the explorer menu.
|
||||
let el = document.querySelector(`[x-ref="${ref}"]`);
|
||||
if (el) {
|
||||
this.$nextTick(() => {
|
||||
debug('scrolling to', ref);
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
});
|
||||
}
|
||||
}
|
||||
this.treeState.currentNode = ref;
|
||||
for (let key in this.treeState.nodes) {
|
||||
let n = this.treeState.nodes[key];
|
||||
n.active = false;
|
||||
n.open = ref == key || ref.startsWith(key);
|
||||
if (n.open) {
|
||||
debug('open', key);
|
||||
}
|
||||
}
|
||||
|
||||
let n = this.treeState.nodes[this.longestPrefix(ref)];
|
||||
if (n) {
|
||||
n.active = true;
|
||||
}
|
||||
},
|
||||
|
||||
getScrollingContainer() {
|
||||
return document.getElementById('leftsidebar');
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
debug('onLoad', this.uiState.containerScrollTop);
|
||||
if (this.uiState.containerScrollTop >= 0) {
|
||||
debug('onLoad: scrolling to', this.uiState.containerScrollTop);
|
||||
this.getScrollingContainer().scrollTo(0, this.uiState.containerScrollTop);
|
||||
}
|
||||
this.uiState.containerScrollTop = -1;
|
||||
},
|
||||
|
||||
onBeforeRender() {
|
||||
debug('onBeforeRender', this.uiState.containerScrollTop);
|
||||
this.setCurrentActive();
|
||||
},
|
||||
|
||||
toggleNode(ref) {
|
||||
this.uiState.containerScrollTop = this.getScrollingContainer().scrollTop;
|
||||
this.uiState.lastActiveRef = '';
|
||||
debug('toggleNode', ref, this.uiState.containerScrollTop);
|
||||
|
||||
let node = this.treeState.nodes[ref];
|
||||
if (!node) {
|
||||
debug('node not found', ref);
|
||||
return;
|
||||
}
|
||||
let wasOpen = node.open;
|
||||
},
|
||||
|
||||
isCurrent(ref) {
|
||||
let n = this.treeState.nodes[ref];
|
||||
return n && n.active;
|
||||
},
|
||||
|
||||
isOpen(ref) {
|
||||
let node = this.treeState.nodes[ref];
|
||||
if (!node) return false;
|
||||
if (node.open) {
|
||||
debug('isOpen', ref);
|
||||
}
|
||||
return node.open;
|
||||
},
|
||||
});
|
||||
@@ -10,7 +10,7 @@ const groupByLvl0 = (array) => {
|
||||
}, {});
|
||||
};
|
||||
|
||||
const applyHelperFuncs = (array) => {
|
||||
const adjustHits = (array, isServer) => {
|
||||
if (!array) return [];
|
||||
return array.map((item) => {
|
||||
item.getHeadingHTML = function () {
|
||||
@@ -30,6 +30,11 @@ const applyHelperFuncs = (array) => {
|
||||
|
||||
return `${lvl2.value} <span class="text-gray-500"> > </span> ${lvl3.value}`;
|
||||
};
|
||||
|
||||
if (isServer) {
|
||||
// Trim https://gohugo.io from the url to make it work locally.
|
||||
item.url = item.url.replace('https://gohugo.io', '');
|
||||
}
|
||||
return item;
|
||||
});
|
||||
};
|
||||
@@ -99,7 +104,7 @@ export const search = (Alpine, cfg) => ({
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
this.result = groupByLvl0(applyHelperFuncs(data.results[0].hits));
|
||||
this.result = groupByLvl0(adjustHits(data.results[0].hits, cfg.params.isServer));
|
||||
this.cache.put(this.query, this.result);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
export function bridgeTurboAndAlpine(Alpine) {
|
||||
document.addEventListener('turbo:before-render', (event) => {
|
||||
event.detail.newBody.querySelectorAll('[data-alpine-generated]').forEach((el) => {
|
||||
if (el.hasAttribute('data-alpine-generated')) {
|
||||
el.removeAttribute('data-alpine-generated');
|
||||
el.remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('turbo:render', () => {
|
||||
if (document.documentElement.hasAttribute('data-turbo-preview')) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelectorAll('[data-alpine-ignored]').forEach((el) => {
|
||||
el.removeAttribute('x-ignore');
|
||||
el.removeAttribute('data-alpine-ignored');
|
||||
});
|
||||
|
||||
document.body.querySelectorAll('[x-data]').forEach((el) => {
|
||||
if (el.hasAttribute('data-turbo-permanent')) {
|
||||
return;
|
||||
}
|
||||
Alpine.initTree(el);
|
||||
});
|
||||
|
||||
Alpine.startObservingMutations();
|
||||
});
|
||||
|
||||
// Cleanup Alpine state on navigation.
|
||||
document.addEventListener('turbo:before-cache', () => {
|
||||
// This will be restarted in turbo:render.
|
||||
Alpine.stopObservingMutations();
|
||||
|
||||
document.body.querySelectorAll('[data-turbo-permanent]').forEach((el) => {
|
||||
if (!el.hasAttribute('x-ignore')) {
|
||||
el.setAttribute('x-ignore', true);
|
||||
el.setAttribute('data-alpine-ignored', true);
|
||||
}
|
||||
});
|
||||
|
||||
document.body.querySelectorAll('[x-for],[x-if],[x-teleport]').forEach((el) => {
|
||||
if (el.hasAttribute('x-for') && el._x_lookup) {
|
||||
Object.values(el._x_lookup).forEach((el) => el.setAttribute('data-alpine-generated', true));
|
||||
}
|
||||
|
||||
if (el.hasAttribute('x-if') && el._x_currentIfEl) {
|
||||
el._x_currentIfEl.setAttribute('data-alpine-generated', true);
|
||||
}
|
||||
|
||||
if (el.hasAttribute('x-teleport') && el._x_teleport) {
|
||||
el._x_teleport.setAttribute('data-alpine-generated', true);
|
||||
}
|
||||
});
|
||||
|
||||
document.body.querySelectorAll('[x-data]').forEach((el) => {
|
||||
if (!el.hasAttribute('data-turbo-permanent')) {
|
||||
Alpine.destroyTree(el);
|
||||
// Turbo leaks DOM elements via their data-turbo-permanent handling.
|
||||
// That needs to be fixed upstream, but until then.
|
||||
let clone = el.cloneNode(true);
|
||||
el.replaceWith(clone);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -5,7 +5,7 @@ export const scrollToActive = (when) => {
|
||||
}
|
||||
els.forEach((el) => {
|
||||
// Find scrolling container.
|
||||
let container = el.closest('[data-turbo-preserve-scroll-container]');
|
||||
let container = el.closest('[data-preserve-scroll-container]');
|
||||
if (container) {
|
||||
// Avoid scrolling if el is already in view.
|
||||
if (el.offsetTop >= container.scrollTop && el.offsetTop <= container.scrollTop + container.clientHeight) {
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from './bridgeTurboAndAlpine';
|
||||
export * from './helpers';
|
||||
export * from './lrucache';
|
||||
|
||||
+12
-36
@@ -1,10 +1,10 @@
|
||||
import Alpine from 'alpinejs';
|
||||
import { registerMagics } from './alpinejs/magics/index';
|
||||
import { navbar, search, toc } from './alpinejs/data/index';
|
||||
import { navStore, initColorScheme } from './alpinejs/stores/index';
|
||||
import { bridgeTurboAndAlpine } from './helpers/index';
|
||||
import { navStore } from './alpinejs/stores/index';
|
||||
import persist from '@alpinejs/persist';
|
||||
import focus from '@alpinejs/focus';
|
||||
import * as params from '@params';
|
||||
|
||||
var debug = 0 ? console.log.bind(console, '[index]') : function () {};
|
||||
|
||||
@@ -28,6 +28,7 @@ var debug = 0 ? console.log.bind(console, '[index]') : function () {};
|
||||
index: 'hugodocs',
|
||||
app_id: 'D1BPLZHGYQ',
|
||||
api_key: '6df94e1e5d55d258c56f60d974d10314',
|
||||
params: params,
|
||||
};
|
||||
|
||||
Alpine.data('navbar', () => navbar(Alpine));
|
||||
@@ -43,39 +44,14 @@ var debug = 0 ? console.log.bind(console, '[index]') : function () {};
|
||||
// Start AlpineJS.
|
||||
Alpine.start();
|
||||
|
||||
// Start the Turbo-Alpine bridge.
|
||||
bridgeTurboAndAlpine(Alpine);
|
||||
|
||||
{
|
||||
let containerScrollTops = {};
|
||||
|
||||
// To preserve scroll position in scrolling elements on navigation add data-turbo-preserve-scroll-container="somename" to the scrolling container.
|
||||
addEventListener('turbo:click', () => {
|
||||
document.querySelectorAll('[data-turbo-preserve-scroll-container]').forEach((el2) => {
|
||||
containerScrollTops[el2.dataset.turboPreserveScrollContainer] = el2.scrollTop;
|
||||
});
|
||||
// On cross-document navigation the browser snapshots the current page for
|
||||
// the view transition. An open overlay (e.g. the search modal) would
|
||||
// otherwise linger in that outgoing snapshot while the page crossfades.
|
||||
// `pageswap` runs right before the snapshot is taken, so hide such
|
||||
// elements here to make them disappear instantly on navigation.
|
||||
window.addEventListener('pageswap', () => {
|
||||
document.querySelectorAll('[data-hide-on-navigate]').forEach((el) => {
|
||||
el.classList.add('hidden');
|
||||
});
|
||||
|
||||
addEventListener('turbo:render', () => {
|
||||
document.querySelectorAll('[data-turbo-preserve-scroll-container]').forEach((ele) => {
|
||||
const containerScrollTop = containerScrollTops[ele.dataset.turboPreserveScrollContainer];
|
||||
if (containerScrollTop) {
|
||||
ele.scrollTop = containerScrollTop;
|
||||
} else {
|
||||
let els = ele.querySelectorAll('.scroll-active');
|
||||
if (els.length) {
|
||||
els.forEach((el) => {
|
||||
// Avoid scrolling if el is already in view.
|
||||
if (el.offsetTop >= ele.scrollTop && el.offsetTop <= ele.scrollTop + ele.clientHeight) {
|
||||
return;
|
||||
}
|
||||
ele.scrollTop = el.offsetTop - ele.offsetTop;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
containerScrollTops = {};
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import * as Turbo from '@hotwired/turbo';
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": [
|
||||
"*"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
`locale`
|
||||
: (`string`) The language tag as described in [RFC 5646][]. This is the primary value used by the [`language.Translate`][] function to select a translation table, and for localization of dates, currencies, numbers, and percentages, falling back to the [language key][] in both cases.
|
||||
|
||||
Hugo also uses this value to populate:
|
||||
|
||||
- The `lang` attribute of the `html` element in the [embedded alias template][]
|
||||
- The `language` element in the [embedded RSS template][]
|
||||
- The `locale` property in the [embedded Open Graph template][]
|
||||
|
||||
Access this value from a template using the [`Language.Locale`][] method on a `Site` or `Page` object.
|
||||
|
||||
[RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646#section-2.1
|
||||
[`Language.Locale`]: /methods/site/language/#locale
|
||||
[`language.Translate`]: /functions/lang/translate/
|
||||
[embedded Open Graph template]: <{{% eturl opengraph %}}>
|
||||
[embedded RSS template]: <{{% eturl rss %}}>
|
||||
[embedded alias template]: <{{% eturl alias %}}>
|
||||
[language key]: /configuration/languages/#language-keys
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
A _page matcher_ filters pages by logical path, page kind, environment, or site. Specify filtering criteria using any combination of the following keywords.
|
||||
|
||||
`environment`
|
||||
: (`string`) A [glob pattern](g) matching the build [environment](g). For example: `{staging,production}`.
|
||||
|
||||
`kind`
|
||||
: (`string`) A [glob pattern](g) matching the [page kind](g). For example: `{taxonomy,term}`.
|
||||
|
||||
`lang`
|
||||
: {{< deprecated-in 0.153.0 />}}
|
||||
: Use the [`sites`](#sites) setting instead.
|
||||
|
||||
`path`
|
||||
: (`string`) A [glob pattern](g) matching the page's [logical path](g). For example: `{/books,/books/**}`.
|
||||
|
||||
`sites`
|
||||
: {{< new-in 0.153.0 />}}
|
||||
: (`map`) A [sites matrix](g) matching any combination of [content dimensions](g) including language, version, and role.
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
When the `images` front matter parameter is set, Hugo processes each value. For internal paths, it searches page resources then global resources, using the resource permalink if found or converting the path to an absolute URL if not. External URLs are used as-is.
|
||||
|
||||
When `images` is not set, Hugo searches page resources for a name matching `*feature*`, falling back to `*cover*` or `*thumbnail*` if none is found. If still no image is found, Hugo uses the first entry in the site configuration's `params.images` array, if present, and processes it as described above.
|
||||
@@ -2,7 +2,7 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
> [!note]
|
||||
> The [page collections quick reference guide] describes methods and functions to filter, sort, and group page collections.
|
||||
> [!NOTE]
|
||||
> The [page collections quick reference guide][] describes methods and functions to filter, sort, and group page collections.
|
||||
|
||||
[page collections quick reference guide]: /quick-reference/page-collections/
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
The documentation for Go's [fmt] package describes the structure and content of the format string.
|
||||
The documentation for Go's [`fmt`][] package describes the structure and content of the format string.
|
||||
|
||||
[fmt]: https://pkg.go.dev/fmt
|
||||
[`fmt`]: https://pkg.go.dev/fmt
|
||||
|
||||
@@ -10,5 +10,5 @@ By default, Hugo uses the `html/template` package when rendering HTML files.
|
||||
|
||||
To generate HTML output that is safe against code injection, the `html/template` package escapes strings in certain contexts.
|
||||
|
||||
[`text/template`]: https://pkg.go.dev/text/template
|
||||
[`html/template`]: https://pkg.go.dev/html/template
|
||||
[`text/template`]: https://pkg.go.dev/text/template
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
Apply the filter using the [`images.Filter`] function:
|
||||
|
||||
[`images.Filter`]: /functions/images/filter/
|
||||
Apply the filter using the [`images.Filter`][] function:
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/original.jpg" }}
|
||||
@@ -14,9 +12,7 @@ Apply the filter using the [`images.Filter`] function:
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
You can also apply the filter using the [`Filter`] method on a `Resource` object:
|
||||
|
||||
[`Filter`]: /methods/resource/filter/
|
||||
You can also apply the filter using the [`Filter`][] method on a `Resource` object:
|
||||
|
||||
```go-html-template
|
||||
{{ with resources.Get "images/original.jpg" }}
|
||||
@@ -25,3 +21,6 @@ You can also apply the filter using the [`Filter`] method on a `Resource` object
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
[`Filter`]: /methods/resource/filter/
|
||||
[`images.Filter`]: /functions/images/filter/
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
params
|
||||
`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
|
||||
@@ -17,17 +17,17 @@ params
|
||||
|
||||
Note that this is meant for small data sets, e.g., configuration settings. For larger data sets, please put/mount the files into `assets` and import them directly.
|
||||
|
||||
minify
|
||||
: (`bool`) Whether to minify the generated CSS code. Default is `false`.
|
||||
`minify`
|
||||
: (`bool`) Whether to minify the generated JS code. Default is `false`.
|
||||
|
||||
loaders
|
||||
`loaders`
|
||||
: {{< new-in 0.140.0 />}}
|
||||
: (`map`) Configuring a loader for a given file type lets you load that file type with an `import` statement or a `require` call. For example, configuring the `.png` file extension to use the data URL loader means importing a `.png` file gives you a data URL containing the contents of that image. Loaders available are `none`, `base64`, `binary`, `copy`, `css`, `dataurl`, `default`, `empty`, `file`, `global-css`, `js`, `json`, `jsx`, `local-css`, `text`, `ts`, `tsx`. See <https://esbuild.github.io/api/#loader>.
|
||||
|
||||
inject
|
||||
`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
|
||||
`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
|
||||
@@ -54,39 +54,39 @@ shims
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
```
|
||||
|
||||
target
|
||||
`target`
|
||||
: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020`, `es2021`, `es2022`, `es2023`, `es2024`, or `esnext`. Default is `esnext`.
|
||||
|
||||
platform
|
||||
`platform`
|
||||
: {{< new-in 0.140.0 />}}
|
||||
: (`string`) One of `browser`, `node`, `neutral`. Default is `browser`. See <https://esbuild.github.io/api/#platform>.
|
||||
|
||||
externals
|
||||
`externals`
|
||||
: (`slice`) External dependencies. Use this to trim dependencies you know will never be executed. See <https://esbuild.github.io/api/#external>.
|
||||
|
||||
defines
|
||||
`defines`
|
||||
: (`map`) This option allows you to define a set of string replacements to be performed when building. It must be a map where each key will be replaced by its value.
|
||||
|
||||
```go-html-template
|
||||
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
|
||||
```
|
||||
|
||||
drop
|
||||
`drop`
|
||||
: {{< new-in 0.144.0 />}}
|
||||
: (`string`) Edit your source code before building to drop certain constructs: One of `debugger` or `console`.
|
||||
: See <https://esbuild.github.io/api/#drop>
|
||||
|
||||
sourceMap
|
||||
`sourceMap`
|
||||
: (`string`) The type of source map to generate. One of `external`, `inline`, `linked`, or `none`. Default is `none`. Linked and external source maps will be written to the target with the output file name + ".map". When `linked` a `sourceMappingURL` will also be written to the output file.
|
||||
|
||||
sourcesContent
|
||||
`sourcesContent`
|
||||
: {{< new-in 0.140.0 />}}
|
||||
: (`bool`) Whether to include the content of the source files in the source map. Default is `true`.
|
||||
|
||||
JSX
|
||||
`JSX`
|
||||
: (`string`) How to handle/transform JSX syntax. One of: `transform`, `preserve`, `automatic`. Default is `transform`. Notably, the `automatic` transform was introduced in React 17+ and will cause the necessary JSX helper functions to be imported automatically. See <https://esbuild.github.io/api/#jsx>.
|
||||
|
||||
JSXImportSource
|
||||
`JSXImportSource`
|
||||
: (`string`) Which library to use to automatically import its JSX helper functions from. This only works if `JSX` is set to `automatic`. The specified library needs to be installed through npm and expose certain exports. See <https://esbuild.github.io/api/#jsx-import-source>.
|
||||
|
||||
The combination of `JSX` and `JSXImportSource` is helpful if you want to use a non-React JSX library like Preact, e.g.:
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
> [!note]
|
||||
> Localization of dates, currencies, numbers, and percentages is performed by the [gohugoio/locales] package. The language tag of the current site must match one of the listed locales.
|
||||
> [!NOTE]
|
||||
> Localization of dates, currencies, numbers, and percentages is performed by the [`bep/golocales`][] package. Hugo determines the locale using the [`locale`][] configuration setting, falling back to the language key itself. The resolved value must be a locale supported by the package.
|
||||
|
||||
[gohugoio/locales]: https://github.com/gohugoio/locales
|
||||
[`bep/golocales`]: https://github.com/bep/golocales
|
||||
[`locale`]: /configuration/all/#locale
|
||||
|
||||
@@ -14,7 +14,7 @@ The table below shows the values these functions return for various file formats
|
||||
|
||||
|Format|IsImageResource|IsImageResourceProcessable|IsImageResourceWithMeta|
|
||||
|:-----|:--------------|:-------------------------|:----------------------|
|
||||
|AVIF |true |**false** |true |
|
||||
|AVIF |true |true |true |
|
||||
|BMP |true |true |true |
|
||||
|GIF |true |true |true |
|
||||
|HEIC |true |**false** |true |
|
||||
@@ -44,6 +44,6 @@ This contrived example demonstrates how to iterate through resources and use the
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
[`reflect.IsImageResource`]: /functions/reflect/isimageresource/
|
||||
[`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/
|
||||
[`reflect.IsImageResourceWithMeta`]: /functions/reflect/isimageresourcewithmeta/
|
||||
[`reflect.IsImageResource`]: /functions/reflect/isimageresource/
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes.
|
||||
When specifying the regular expression, use a raw [string literal][] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes.
|
||||
|
||||
Go's regular expression package implements the [RE2 syntax]. The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats]. Note that the RE2 `\C` escape sequence is not supported.
|
||||
Go's regular expression package implements the [RE2 syntax][]. The RE2 syntax is a subset of that accepted by [PCRE][], roughly speaking, and with various [caveats][]. Note that the RE2 `\C` escape sequence is not supported.
|
||||
|
||||
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
|
||||
[PCRE]: https://www.pcre.org/
|
||||
[RE2 syntax]: https://github.com/google/re2/wiki/Syntax/
|
||||
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
|
||||
[string literal]: https://go.dev/ref/spec#String_literals
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
The [`anchorize`] and [`urlize`] functions are similar:
|
||||
|
||||
[`anchorize`]: /functions/urls/anchorize/
|
||||
[`urlize`]: /functions/urls/urlize/
|
||||
The [`anchorize`][] and [`urlize`][] functions are similar:
|
||||
|
||||
- Use the `anchorize` function to generate an HTML `id` attribute value
|
||||
- Use the `urlize` function to sanitize a string for usage in a URL
|
||||
@@ -33,3 +30,6 @@ For example:
|
||||
{{ $s | anchorize }} → hugö
|
||||
{{ $s | urlize }} → hug%C3%B6
|
||||
```
|
||||
|
||||
[`anchorize`]: /functions/urls/anchorize/
|
||||
[`urlize`]: /functions/urls/urlize/
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
> [!NOTE]
|
||||
> Do not commit the contents of the [`publishDir`][] directory to your repository. Hugo recreates this directory when you build your project.
|
||||
|
||||
[`publishDir`]: /configuration/all/#publishdir
|
||||
@@ -2,13 +2,15 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
> [!note] Hugo Modules are Go Modules
|
||||
> You need [Go] version 1.18 or later and [Git] to use Hugo Modules. For older sites hosted on Netlify, please ensure the `GO_VERSION` environment variable is set to `1.18` or higher.
|
||||
> [!NOTE] Hugo modules are Go modules
|
||||
> You need [Go][] version 1.18 or later and [Git][] to use Hugo modules. For older sites hosted on Netlify, please ensure the `GO_VERSION` environment variable is set to `1.18` or higher.
|
||||
>
|
||||
> Go Modules resources:
|
||||
> Go module resources:
|
||||
>
|
||||
> - [go.dev/wiki/Modules](https://go.dev/wiki/Modules)
|
||||
> - [blog.golang.org/using-go-modules](https://go.dev/blog/using-go-modules)
|
||||
> - [go.dev/wiki/Modules][]
|
||||
> - [blog.golang.org/using-go-modules][]
|
||||
|
||||
[Git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
|
||||
[Go]: https://go.dev/doc/install
|
||||
[blog.golang.org/using-go-modules]: https://go.dev/blog/using-go-modules
|
||||
[go.dev/wiki/Modules]: https://go.dev/wiki/Modules
|
||||
|
||||
@@ -4,15 +4,20 @@ _comment: Do not remove front matter.
|
||||
|
||||
## Editions
|
||||
|
||||
Hugo offers a standard edition with core features, plus extended and extended/deploy editions with more. Use the standard edition unless you need the features below.
|
||||
Hugo is available in several editions. Use the standard edition unless you need additional features.
|
||||
|
||||
<!-- TODO Remove the transpiler row somewhere around v0.166.0 -->
|
||||
Feature|standard|deploy (1)|extended|extended/deploy
|
||||
:--|:-:|:-:|:-:|:-:
|
||||
Core features|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:
|
||||
Direct cloud deployment (2)|:x:|:heavy_check_mark:|:x:|:heavy_check_mark:
|
||||
LibSass support (3)|:x:|:x:|:heavy_check_mark:|:heavy_check_mark:
|
||||
|
||||
Feature|extended edition|extended/deploy edition
|
||||
:--|:-:|:-:
|
||||
[Transpile Sass to CSS] via embedded LibSass. Note that embedded LibSass was deprecated in v0.153.0 and will be removed in a future release. Use the [Dart Sass] transpiler instead, which is compatible with any edition.|:heavy_check_mark:|:heavy_check_mark:
|
||||
Deploy your site directly to a Google Cloud Storage bucket, an AWS S3 bucket, or an Azure Storage container. See [details].|:x:|:heavy_check_mark:
|
||||
(1) {{< new-in v0.159.2 />}}
|
||||
|
||||
[dart sass]: /functions/css/sass/#dart-sass
|
||||
[transpile sass to css]: /functions/css/sass/
|
||||
(2) Deploy your site directly to a Google Cloud Storage bucket, an AWS S3 bucket, or an Azure Storage container. See [details][].
|
||||
|
||||
(3) [Transpile Sass to CSS][] via embedded LibSass. Note that embedded LibSass was deprecated in v0.153.0 and will be removed in a future release. Use the [Dart Sass][] transpiler instead, which is compatible with any edition.
|
||||
|
||||
[Dart Sass]: /functions/css/sass/#dart-sass
|
||||
[Transpile Sass to CSS]: /functions/css/sass/
|
||||
[details]: /host-and-deploy/deploy-with-hugo-deploy/
|
||||
|
||||
@@ -4,20 +4,20 @@ _comment: Do not remove front matter.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Although not required in all cases, [Git], [Go], and [Dart Sass] are commonly used when working with Hugo.
|
||||
Although not required in all cases, [Git][], [Go][], and [Dart Sass][] are commonly used when working with Hugo.
|
||||
|
||||
Git is required to:
|
||||
|
||||
- Build Hugo from source
|
||||
- Use the [Hugo Modules] feature
|
||||
- Use [Hugo modules][]
|
||||
- Install a theme as a Git submodule
|
||||
- Access [commit information] from a local Git repository
|
||||
- Access [commit information][] from a local Git repository
|
||||
- Host your site on [CI/CD](g) platforms such as [Cloudflare][], [GitHub Pages][], [GitLab Pages][], [Netlify][], [Render][], or [Vercel][]
|
||||
|
||||
Go is required to:
|
||||
|
||||
- Build Hugo from source
|
||||
- Use the Hugo Modules feature
|
||||
- Use Hugo modules
|
||||
|
||||
Dart Sass is required to transpile Sass to CSS when using the latest features of the Sass language.
|
||||
|
||||
@@ -28,16 +28,16 @@ Please refer to the relevant documentation for installation instructions:
|
||||
- [Dart Sass][dart sass install]
|
||||
|
||||
[Cloudflare]: /host-and-deploy/host-on-cloudflare/
|
||||
[commit information]: /methods/page/GitInfo
|
||||
[dart sass install]: /functions/css/sass/#dart-sass
|
||||
[dart sass]: https://sass-lang.com/dart-sass
|
||||
[git install]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
|
||||
[git]: https://git-scm.com/
|
||||
[Dart Sass]: https://sass-lang.com/dart-sass
|
||||
[GitHub Pages]: /host-and-deploy/host-on-github-pages/
|
||||
[GitLab Pages]: /host-and-deploy/host-on-gitlab-pages/
|
||||
[go install]: https://go.dev/doc/install
|
||||
[go]: https://go.dev/
|
||||
[hugo modules]: /hugo-modules/
|
||||
[Git]: https://git-scm.com/
|
||||
[Go]: https://go.dev/
|
||||
[Hugo modules]: /hugo-modules/
|
||||
[Netlify]: /host-and-deploy/host-on-netlify/
|
||||
[Render]: /host-and-deploy/host-on-render/
|
||||
[Vercel]: /host-and-deploy/host-on-vercel/
|
||||
[commit information]: /methods/page/GitInfo/
|
||||
[dart sass install]: /functions/css/sass/#dart-sass
|
||||
[git install]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
|
||||
[go install]: https://go.dev/doc/install
|
||||
|
||||
@@ -4,7 +4,7 @@ _comment: Do not remove front matter.
|
||||
|
||||
## Prebuilt binaries
|
||||
|
||||
Prebuilt binaries are available for a variety of operating systems and architectures. Visit the [latest release] page, and scroll down to the Assets section.
|
||||
Prebuilt binaries are available for a variety of operating systems and architectures. Visit the [latest release][] page, and scroll down to the Assets section.
|
||||
|
||||
1. Download the archive for the desired edition, operating system, and architecture
|
||||
1. Extract the archive
|
||||
|
||||
@@ -4,28 +4,40 @@ _comment: Do not remove front matter.
|
||||
|
||||
## Build from source
|
||||
|
||||
To build the extended or extended/deploy edition from source you must:
|
||||
To build Hugo from source you must install:
|
||||
|
||||
1. Install [Git]
|
||||
1. Install [Go] version 1.25.0 or later
|
||||
1. Install a C compiler, either [GCC] or [Clang]
|
||||
1. Update your `PATH` environment variable as described in the [Go documentation]
|
||||
1. [Git][]
|
||||
1. [Go][] version {{% current-go-version %}} or later
|
||||
|
||||
> The install directory is controlled by the `GOPATH` and `GOBIN` environment variables. If `GOBIN` is set, binaries are installed to that directory. If `GOPATH` is set, binaries are installed to the bin subdirectory of the first directory in the `GOPATH` list. Otherwise, binaries are installed to the bin subdirectory of the default `GOPATH` (`$HOME/go` or `%USERPROFILE%\go`).
|
||||
### Standard edition
|
||||
|
||||
To build the standard edition:
|
||||
To build and install the standard edition:
|
||||
|
||||
```sh
|
||||
go install github.com/gohugoio/hugo@latest
|
||||
CGO_ENABLED=0 go install github.com/gohugoio/hugo@latest
|
||||
```
|
||||
|
||||
To build the extended edition:
|
||||
### Deploy edition
|
||||
|
||||
{{< new-in v0.159.2 />}}
|
||||
|
||||
To build and install the deploy edition:
|
||||
|
||||
```sh
|
||||
CGO_ENABLED=0 go install -tags withdeploy github.com/gohugoio/hugo@latest
|
||||
```
|
||||
|
||||
### Extended edition
|
||||
|
||||
To build and install the extended edition, first install a C compiler such as [GCC][] or [Clang][] and then run the following command:
|
||||
|
||||
```sh
|
||||
CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@latest
|
||||
```
|
||||
|
||||
To build the extended/deploy edition:
|
||||
### Extended/deploy edition
|
||||
|
||||
To build and install the extended/deploy edition, first install a C compiler such as [GCC][] or [Clang][] and then run the following command:
|
||||
|
||||
```sh
|
||||
CGO_ENABLED=1 go install -tags extended,withdeploy github.com/gohugoio/hugo@latest
|
||||
@@ -34,5 +46,4 @@ CGO_ENABLED=1 go install -tags extended,withdeploy github.com/gohugoio/hugo@late
|
||||
[Clang]: https://clang.llvm.org/
|
||||
[GCC]: https://gcc.gnu.org/
|
||||
[Git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
|
||||
[Go documentation]: https://go.dev/doc/code#Command
|
||||
[Go]: https://go.dev/doc/install
|
||||
|
||||
@@ -4,7 +4,7 @@ _comment: Do not remove front matter.
|
||||
|
||||
### Homebrew
|
||||
|
||||
[Homebrew] is a free and open-source package manager for macOS and Linux. To install the extended/deploy edition of Hugo:
|
||||
[Homebrew][] is a free and open-source package manager for macOS and Linux. To install the extended/deploy edition of Hugo:
|
||||
|
||||
```sh
|
||||
brew install hugo
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
In this project configuration we enable rendering of [emoji shortcodes], and add emoji shortcodes before (pre) and after (post) each menu entry:
|
||||
In this project configuration we enable rendering of [emoji shortcodes][], and add emoji shortcodes before (pre) and after (post) each menu entry:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
enableEmoji = true
|
||||
|
||||
@@ -6,26 +6,26 @@ _comment: Do not remove front matter.
|
||||
This description list intentionally excludes the `pageRef` and `url` properties. Add those properties manually after using the include shortcode to include this list.
|
||||
-->
|
||||
|
||||
identifier
|
||||
`identifier`
|
||||
: (`string`) Required when two or more menu entries have the same `name`, or when localizing the `name` using translation tables. Must start with a letter, followed by letters, digits, or underscores.
|
||||
|
||||
name
|
||||
`name`
|
||||
: (`string`) The text to display when rendering the menu entry.
|
||||
|
||||
params
|
||||
`params`
|
||||
: (`map`) User-defined properties for the menu entry.
|
||||
|
||||
parent
|
||||
`parent`
|
||||
: (`string`) The `identifier` of the parent menu entry. If `identifier` is not defined, use `name`. Required for child entries in a nested menu.
|
||||
|
||||
post
|
||||
`post`
|
||||
: (`string`) The HTML to append when rendering the menu entry.
|
||||
|
||||
pre
|
||||
`pre`
|
||||
: (`string`) The HTML to prepend when rendering the menu entry.
|
||||
|
||||
title
|
||||
`title`
|
||||
: (`string`) The HTML `title` attribute of the rendered menu entry.
|
||||
|
||||
weight
|
||||
`weight`
|
||||
: (`int`) A non-zero integer indicating the entry's position relative the root of the menu, or to its parent for a child entry. Lighter entries float to the top, while heavier entries sink to the bottom.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
`Type`
|
||||
: (`string`) Returns the media type.
|
||||
|
||||
`MainType`
|
||||
: (`string`) Returns the main type of the media type.
|
||||
|
||||
`SubType`
|
||||
: (`string`) Returns the subtype of the media type.
|
||||
|
||||
`Suffixes`
|
||||
: (`slice`) Returns a slice of possible file suffixes for the media type.
|
||||
|
||||
`FirstSuffix.Suffix`
|
||||
: (`string`) Returns the first of the possible file suffixes for the media type.
|
||||
@@ -6,21 +6,16 @@ Hugo determines the _next_ and _previous_ page by sorting the site's collection
|
||||
|
||||
Field|Precedence|Sort direction
|
||||
:--|:--|:--
|
||||
[`weight`]|1|descending
|
||||
[`date`]|2|descending
|
||||
[`linkTitle`]|3|descending
|
||||
[`path`]|4|descending
|
||||
|
||||
[`date`]: /methods/page/date/
|
||||
[`weight`]: /methods/page/weight/
|
||||
[`linkTitle`]: /methods/page/linktitle/
|
||||
[`path`]: /methods/page/path/
|
||||
[`weight`][]|1|descending
|
||||
[`date`][]|2|descending
|
||||
[`linkTitle`][]|3|descending
|
||||
[`path`][]|4|descending
|
||||
|
||||
The sorted page collection used to determine the _next_ and _previous_ page is independent of other page collections, which may lead to unexpected behavior.
|
||||
|
||||
For example, with this content structure:
|
||||
|
||||
```text
|
||||
```tree
|
||||
content/
|
||||
├── pages/
|
||||
│ ├── _index.md
|
||||
@@ -53,8 +48,12 @@ When you visit page-2:
|
||||
- The `Prev` method points to page-3
|
||||
- The `Next` method points to page-1
|
||||
|
||||
To reverse the meaning of _next_ and _previous_ you can change the sort direction in your [project configuration], or use the [`Next`] and [`Prev`] methods on a `Pages` object for more flexibility.
|
||||
To reverse the meaning of _next_ and _previous_ you can change the sort direction in your [project configuration][], or use the [`Next`][] and [`Prev`][] methods on a `Pages` object for more flexibility.
|
||||
|
||||
[`Next`]: /methods/pages/next/
|
||||
[`Prev`]: /methods/pages/prev/
|
||||
[`date`]: /methods/page/date/
|
||||
[`linkTitle`]: /methods/page/linktitle/
|
||||
[`path`]: /methods/page/path/
|
||||
[`weight`]: /methods/page/weight/
|
||||
[project configuration]: /configuration/page/
|
||||
[`Next`]: /methods/pages/prev
|
||||
[`Prev`]: /methods/pages/prev
|
||||
|
||||
@@ -6,21 +6,16 @@ Hugo determines the _next_ and _previous_ page by sorting the current section's
|
||||
|
||||
Field|Precedence|Sort direction
|
||||
:--|:--|:--
|
||||
[`weight`]|1|descending
|
||||
[`date`]|2|descending
|
||||
[`linkTitle`]|3|descending
|
||||
[`path`]|4|descending
|
||||
|
||||
[`date`]: /methods/page/date/
|
||||
[`weight`]: /methods/page/weight/
|
||||
[`linkTitle`]: /methods/page/linktitle/
|
||||
[`path`]: /methods/page/path/
|
||||
[`weight`][]|1|descending
|
||||
[`date`][]|2|descending
|
||||
[`linkTitle`][]|3|descending
|
||||
[`path`][]|4|descending
|
||||
|
||||
The sorted page collection used to determine the _next_ and _previous_ page is independent of other page collections, which may lead to unexpected behavior.
|
||||
|
||||
For example, with this content structure:
|
||||
|
||||
```text
|
||||
```tree
|
||||
content/
|
||||
├── pages/
|
||||
│ ├── _index.md
|
||||
@@ -53,11 +48,7 @@ When you visit page-2:
|
||||
- The `PrevInSection` method points to page-3
|
||||
- The `NextInSection` method points to page-1
|
||||
|
||||
To reverse the meaning of _next_ and _previous_ you can change the sort direction in your [project configuration], or use the [`Next`] and [`Prev`] methods on a `Pages` object for more flexibility.
|
||||
|
||||
[project configuration]: /configuration/page/
|
||||
[`Next`]: /methods/pages/prev
|
||||
[`Prev`]: /methods/pages/prev
|
||||
To reverse the meaning of _next_ and _previous_ you can change the sort direction in your [project configuration][], or use the [`Next`][] and [`Prev`][] methods on a `Pages` object for more flexibility.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -75,4 +66,12 @@ Code defensively by checking for page existence:
|
||||
|
||||
## Alternative
|
||||
|
||||
Use the [`Next`] and [`Prev`] methods on a `Pages` object for more flexibility.
|
||||
Use the [`Next`][] and [`Prev`][] methods on a `Pages` object for more flexibility.
|
||||
|
||||
[`Next`]: /methods/pages/next/
|
||||
[`Prev`]: /methods/pages/prev/
|
||||
[`date`]: /methods/page/date/
|
||||
[`linkTitle`]: /methods/page/linktitle/
|
||||
[`path`]: /methods/page/path/
|
||||
[`weight`]: /methods/page/weight/
|
||||
[project configuration]: /configuration/page/
|
||||
|
||||
@@ -6,21 +6,16 @@ Hugo determines the _next_ and _previous_ page by sorting the page collection ac
|
||||
|
||||
Field|Precedence|Sort direction
|
||||
:--|:--|:--
|
||||
[`weight`]|1|descending
|
||||
[`date`]|2|descending
|
||||
[`linkTitle`]|3|descending
|
||||
[`path`]|4|descending
|
||||
|
||||
[`date`]: /methods/page/date/
|
||||
[`weight`]: /methods/page/weight/
|
||||
[`linkTitle`]: /methods/page/linktitle/
|
||||
[`path`]: /methods/page/path/
|
||||
[`weight`][]|1|descending
|
||||
[`date`][]|2|descending
|
||||
[`linkTitle`][]|3|descending
|
||||
[`path`][]|4|descending
|
||||
|
||||
The sorted page collection used to determine the _next_ and _previous_ page is independent of other page collections, which may lead to unexpected behavior.
|
||||
|
||||
For example, with this content structure:
|
||||
|
||||
```text
|
||||
```tree
|
||||
content/
|
||||
├── pages/
|
||||
│ ├── _index.md
|
||||
@@ -55,7 +50,7 @@ When you visit page-2:
|
||||
- The `Prev` method points to page-3
|
||||
- The `Next` method points to page-1
|
||||
|
||||
To reverse the meaning of _next_ and _previous_ you can chain the [`Reverse`] method to the page collection definition:
|
||||
To reverse the meaning of _next_ and _previous_ you can chain the [`Reverse`][] method to the page collection definition:
|
||||
|
||||
```go-html-template {file="layouts/page.html"}
|
||||
{{ $pages := .CurrentSection.Pages.ByWeight.Reverse }}
|
||||
@@ -70,3 +65,7 @@ To reverse the meaning of _next_ and _previous_ you can chain the [`Reverse`] me
|
||||
```
|
||||
|
||||
[`Reverse`]: /methods/pages/reverse/
|
||||
[`date`]: /methods/page/date/
|
||||
[`linkTitle`]: /methods/page/linktitle/
|
||||
[`path`]: /methods/page/path/
|
||||
[`weight`]: /methods/page/weight/
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
> [!note]
|
||||
> [!NOTE]
|
||||
> Use this method with [global resources](g), [page resources](g), or [remote resources](g).
|
||||
|
||||
@@ -7,26 +7,26 @@ _comment: Do not remove front matter.
|
||||
The processing specification is a space-delimited, case-insensitive list containing one or more of the following options in any sequence:
|
||||
|
||||
action
|
||||
: Specify one of `crop`, `fill`, `fit`, or `resize`. This is applicable to the [`Process`][] method and the [`images.Process`][] filter. If you specify an action, you must also provide dimensions.
|
||||
: Specify one of `crop`, `fill`, `fit`, or `resize`. This is applicable to the [`Process`][] method and the [`images.Process`][] filter. If you specify an action, you must also provide [`dimensions`](#dimensions).
|
||||
|
||||
anchor
|
||||
: The focal point used when cropping or filling an image. Valid options include `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. The `Smart` option utilizes the [`muesli/smartcrop`][] package to identify the most interesting area of the image. This defaults to the [`anchor`][] parameter in your project configuration.
|
||||
: The focal point used when cropping or filling an image. Valid options include `TopLeft`, `Top`, `TopRight`, `Left`, `Center`, `Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. The `Smart` option utilizes the [`muesli/smartcrop`][] package to identify the most interesting area of the image. This defaults to the `anchor` setting in your [imaging configuration][].
|
||||
|
||||
background color
|
||||
: The background color used when converting transparent images to formats that do not support transparency, such as PNG to JPEG. This color also fills the empty space created when rotating an image by a non-orthogonal angle if the space is not transparent and a background color is not specified in the processing specification. The value must be an RGB [hexadecimal color][]. This defaults to the [`bgColor`][] parameter in your project configuration.
|
||||
: The background color used when converting transparent images to formats that do not support transparency, such as PNG to JPEG. This color also fills the empty space created when rotating an image by a non-orthogonal angle if the space is not transparent and a background color is not specified in the processing specification. The value must be an RGB [hexadecimal color][]. This defaults to the `bgColor` setting in your [imaging configuration][].
|
||||
|
||||
compression
|
||||
: {{< new-in 0.153.5 />}}
|
||||
: The encoding strategy used for the image. Options are `lossy` or `lossless`. Note that `lossless` is only supported by the WebP format. This defaults to the [`compression`][] parameter in your project configuration.
|
||||
: The encoding strategy, applicable to AVIF and WebP images. Options are `lossy` or `lossless`. This defaults to the format-specific `compression` setting in your [imaging configuration][].
|
||||
|
||||
dimensions
|
||||
: The dimensions of the resulting image, in pixels. The format is `WIDTHxHEIGHT` where `WIDTH` and `HEIGHT` are whole numbers. When resizing an image, you may specify only the width (such as `600x`) or only the height (such as `x400`) for proportional scaling. Specifying both width and height when resizing an image may result in non-proportional scaling. When cropping, fitting, or filling, you must provide both width and height such as `600x400`.
|
||||
|
||||
format
|
||||
: The format of the resulting image. Valid options include `bmp`, `gif`, `jpeg`, `png`, `tiff`, or `webp`. This defaults to the format of the source image.
|
||||
: The format of the resulting image. Valid options include `avif`, `bmp`, `gif`, `jpeg`, `png`, `tiff`, or `webp`. This defaults to the format of the source image.
|
||||
|
||||
hint
|
||||
: The encoding preset used when processing WebP images, equivalent to the `-preset` flag for the [`cwebp`][] CLI. Valid options include `drawing`, `icon`, `photo`, `picture`, or `text`. This defaults to the [`hint`][] parameter in your project configuration.
|
||||
: The content hint, applicable to AVIF and WebP images. Valid options include `drawing`, `icon`, `photo`, `picture`, or `text`. This defaults to the format-specific `hint` setting in your [imaging configuration][].
|
||||
|
||||
Value|Example
|
||||
:--|:--
|
||||
@@ -37,10 +37,10 @@ hint
|
||||
`text`|Image that is primarily text
|
||||
|
||||
quality
|
||||
: The visual fidelity of the image, applicable to JPEG and WebP formats when using `lossy` compression. The format is `qQUALITY` where `QUALITY` is a whole number between `1` and `100`, inclusive. Lower numbers prioritize smaller file size, while higher numbers prioritize visual clarity. This defaults to the [`quality`][] parameter in your project configuration.
|
||||
: The visual fidelity, applicable to JPEG images and to AVIF and WebP images when using `lossy` compression. The format is `qQUALITY` where `QUALITY` is a whole number between `1` and `100`, inclusive. Lower numbers prioritize smaller file size, while higher numbers prioritize visual clarity. This defaults to the format-specific `quality` setting in your [imaging configuration][].
|
||||
|
||||
resampling filter
|
||||
: The algorithm used to calculate new pixels when resizing, fitting, or filling an image. Common options include `box`, `lanczos`, `catmullRom`, `mitchellNetravali`, `linear`, or `nearestNeighbor`. This defaults to the [`resampleFilter`][] parameter in your project configuration.
|
||||
: The algorithm used to calculate new pixels when resizing, fitting, or filling an image. Common options include `box`, `lanczos`, `catmullRom`, `mitchellNetravali`, `linear`, or `nearestNeighbor`. This defaults to the `resampleFilter` setting in your [imaging configuration][].
|
||||
|
||||
Filter|Description
|
||||
:--|:--
|
||||
@@ -56,18 +56,12 @@ resampling filter
|
||||
rotation
|
||||
: The number of whole degrees to rotate an image counter-clockwise. The format is `rDEGREES` where `DEGREES` is a whole number. Hugo performs rotation before any other transformations, so your [target dimensions](#dimensions) and any [anchor](#anchor) should refer to the image orientation after rotation. Use `r90`, `r180`, or `r270` for orthogonal rotations, or arbitrary angles such as `r45`. To rotate clockwise, use a negative number such as `r-45`. To automatically rotate an image based on its Exif orientation tag, use the [`images.AutoOrient`][] filter instead of manual rotation.
|
||||
|
||||
Rotating by non-orthogonal values increases the image extents to fit the rotated corners. For formats supporting alpha channels such as PNG or WebP, this resulting empty space is transparent by default. If the target format does not support transparency such as JPEG, or if you explicitly specify a [background color](#background-color) in the processing specification, the space is filled. If a color is required but not specified in the processing string, it defaults to the [`bgColor`][] parameter in your project configuration.
|
||||
Rotating by non-orthogonal values increases the image extents to fit the rotated corners. For formats supporting alpha channels such as AVIF, PNG, or WebP, this resulting empty space is transparent by default. If the target format does not support transparency such as JPEG, or if you explicitly specify a [background color](#background-color) in the processing specification, the space is filled. If a color is required but not specified in the processing string, it defaults to the `bgColor` setting in your [imaging configuration][].
|
||||
|
||||
[`anchor`]: /configuration/imaging/#anchor
|
||||
[`bgcolor`]: /configuration/imaging/#bgcolor
|
||||
[`compression`]: /configuration/imaging/#compression
|
||||
[`cwebp`]: https://developers.google.com/speed/webp/docs/cwebp
|
||||
[`muesli/smartcrop`]: https://github.com/muesli/smartcrop
|
||||
[`hint`]: /configuration/imaging/#hint
|
||||
[`Process`]: /methods/resource/process/
|
||||
[`images.AutoOrient`]: /functions/images/autoorient/
|
||||
[`images.Process`]: /functions/images/process/
|
||||
[`Process`]: /methods/resource/process
|
||||
[`quality`]: /configuration/imaging/#quality
|
||||
[`resampleFilter`]: /configuration/imaging/#resamplefilter
|
||||
[`muesli/smartcrop`]: https://github.com/muesli/smartcrop
|
||||
[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color
|
||||
[imaging configuration]: /configuration/imaging/
|
||||
[source documentation]: https://github.com/disintegration/imaging#image-resizing
|
||||
|
||||
@@ -16,7 +16,7 @@ author = 'authors'
|
||||
|
||||
And this content structure:
|
||||
|
||||
```text
|
||||
```tree
|
||||
content/
|
||||
├── books/
|
||||
│ ├── and-then-there-were-none.md --> genres: suspense
|
||||
@@ -26,13 +26,13 @@ content/
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
To capture the "genres" `Taxonomy` object from within any template, use the [`Taxonomies`] method on a `Site` object.
|
||||
To capture the "genres" `Taxonomy` object from within any template, use the [`Taxonomies`][] method on a `Site` object.
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomyObject := .Site.Taxonomies.genres }}
|
||||
```
|
||||
|
||||
To capture the "genres" `Taxonomy` object when rendering its page with a _taxonomy_ template, use the [`Terms`] method on the page's [`Data`] object:
|
||||
To capture the "genres" `Taxonomy` object when rendering its page with a _taxonomy_ template, use the [`Terms`][] method on the page's [`Data`][] object:
|
||||
|
||||
```go-html-template {file="layouts/taxonomy.html"}
|
||||
{{ $taxonomyObject := .Data.Terms }}
|
||||
@@ -44,7 +44,7 @@ To inspect the data structure:
|
||||
<pre>{{ debug.Dump $taxonomyObject }}</pre>
|
||||
```
|
||||
|
||||
Although the [`Alphabetical`] and [`ByCount`] methods provide a better data structure for ranging through the taxonomy, you can render the weighted pages by term directly from the `Taxonomy` object:
|
||||
Although the [`Alphabetical`][] and [`ByCount`][] methods provide a better data structure for ranging through the taxonomy, you can render the weighted pages by term directly from the `Taxonomy` object:
|
||||
|
||||
```go-html-template
|
||||
{{ range $term, $weightedPages := $taxonomyObject }}
|
||||
@@ -61,7 +61,6 @@ In the example above, the first anchor element is a link to the term page.
|
||||
|
||||
[`Alphabetical`]: /methods/taxonomy/alphabetical/
|
||||
[`ByCount`]: /methods/taxonomy/bycount/
|
||||
|
||||
[`data`]: /methods/page/data/
|
||||
[`terms`]: /methods/page/data/#in-a-taxonomy-template
|
||||
[`taxonomies`]: /methods/site/taxonomies/
|
||||
[`Data`]: /methods/page/data/
|
||||
[`Taxonomies`]: /methods/site/taxonomies/
|
||||
[`Terms`]: /methods/page/data/#in-a-taxonomy-template
|
||||
|
||||
@@ -6,19 +6,19 @@ An ordered taxonomy is a slice, where each element is an object that contains th
|
||||
|
||||
Each element of the slice provides these methods:
|
||||
|
||||
Count
|
||||
`Count`
|
||||
: (`int`) Returns the number of pages to which the term is assigned.
|
||||
|
||||
Page
|
||||
`Page`
|
||||
: (`page.Page`) Returns the term's `Page` object, useful for linking to the term page.
|
||||
|
||||
Pages
|
||||
: (`page.Pages`) Returns a `Pages` object containing the `Page` objects to which the term is assigned, sorted by [taxonomic weight](g). To sort or group, use any of the [methods] available to the `Pages` object. For example, sort by the last modification date.
|
||||
`Pages`
|
||||
: (`page.Pages`) Returns a `Pages` object containing the `Page` objects to which the term is assigned, sorted by [taxonomic weight](g). To sort or group, use any of the [methods][] available to the `Pages` object. For example, sort by the last modification date.
|
||||
|
||||
Term
|
||||
`Term`
|
||||
: (`string`) Returns the term name.
|
||||
|
||||
WeightedPages
|
||||
`WeightedPages`
|
||||
: (`page.WeightedPages`) Returns a slice of weighted pages to which the term is assigned, sorted by taxonomic weight. The `Pages` method above is more flexible, allowing you to sort and group.
|
||||
|
||||
[methods]: /methods/pages/
|
||||
|
||||
@@ -45,27 +45,26 @@ _comment: Do not remove front matter.
|
||||
|
||||
`:filename`
|
||||
: {{< deprecated-in v0.144.0 />}}
|
||||
: Use `:contentbasename` instead.
|
||||
: Use the [`:contentbasename`](#contentbasename) token instead.
|
||||
|
||||
`:slugorfilename`
|
||||
: {{< deprecated-in v0.144.0 />}}
|
||||
: Use `:slugorcontentbasename` instead.
|
||||
: Use the [`:slugorcontentbasename`](#slugorcontentbasename) token instead.
|
||||
|
||||
`:contentbasename`
|
||||
: {{< new-in 0.144.0 />}}
|
||||
: The [content base name].
|
||||
|
||||
[content base name]: /methods/page/file/#contentbasename
|
||||
: The [content base name][].
|
||||
|
||||
`:slugorcontentbasename`
|
||||
: {{< new-in 0.144.0 />}}
|
||||
: The `slug` as defined in front matter, else the [content base name].
|
||||
: The `slug` as defined in front matter, else the [content base name][].
|
||||
|
||||
For time-related values, you can also use the layout string components defined in Go's [time package]. For example:
|
||||
|
||||
[time package]: https://pkg.go.dev/time#pkg-constants
|
||||
For time-related values, you can also use the layout string components defined in Go's [time package][]. For example:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
permalinks:
|
||||
posts: /:06/:1/:2/:title/
|
||||
{{< /code-toggle >}}
|
||||
|
||||
[content base name]: /methods/page/file/#contentbasename
|
||||
[time package]: https://pkg.go.dev/time#pkg-constants
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
path
|
||||
`path`
|
||||
: (`string`) The path to the target page. Paths without a leading slash (`/`) are resolved first relative to the current page, and then relative to the rest of the site.
|
||||
|
||||
lang
|
||||
`lang`
|
||||
: (`string`) The language of the target page. Default is the current language. Optional.
|
||||
|
||||
outputFormat
|
||||
`outputFormat`
|
||||
: (`string`) The output format of the target page. Default is the current output format. Optional.
|
||||
|
||||
@@ -20,7 +20,7 @@ The primary use case for `PageInner` is to resolve links and [page resources](g)
|
||||
|
||||
Then call the shortcode in your Markdown:
|
||||
|
||||
```text {file="content/posts/post-1.md"}
|
||||
```md {file="content/posts/post-1.md"}
|
||||
{{%/* include "/posts/post-2" */%}}
|
||||
```
|
||||
|
||||
@@ -31,15 +31,15 @@ Any render hook triggered while rendering `/posts/post-2` will get:
|
||||
|
||||
`PageInner` falls back to the value of `Page` if not relevant, and always returns a value.
|
||||
|
||||
> [!note]
|
||||
> The `PageInner` method is only relevant for shortcodes that invoke the [`RenderShortcodes`] method, and you must call the shortcode using [Markdown notation].
|
||||
> [!NOTE]
|
||||
> The `PageInner` method is only relevant for shortcodes that invoke the [`RenderShortcodes`][] method, and you must call the shortcode using [Markdown notation][].
|
||||
|
||||
As a practical example, Hugo's embedded link and image render hooks use the `PageInner` method to resolve markdown link and image destinations. See the source code for each:
|
||||
|
||||
- [Embedded link render hook]
|
||||
- [Embedded image render hook]
|
||||
- [Embedded link render hook][]
|
||||
- [Embedded image render hook][]
|
||||
|
||||
[`RenderShortcodes`]: /methods/page/rendershortcodes/
|
||||
[Markdown notation]: /content-management/shortcodes/#notation
|
||||
[Embedded link render hook]: <{{% eturl render-link %}}>
|
||||
[Embedded image render hook]: <{{% eturl render-image %}}>
|
||||
[Embedded link render hook]: <{{% eturl render-link %}}>
|
||||
[Markdown notation]: /content-management/shortcodes/#notation
|
||||
[`RenderShortcodes`]: /methods/page/rendershortcodes/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user