Commit graph

307 commits

Author SHA1 Message Date
Joe Mooring c9f7ebf004 tpl/tplimpl: Resolve fragments in link render hook
Fixes #12084
2024-02-21 09:11:34 +01:00
Bjørn Erik Pedersen 5dbc29dc6c Handle rebuilds when resources passed to transform.Unmarshal etc. changes
Fixes #12065
2024-02-19 14:50:23 +01:00
Joe Mooring d0788b96ae tpl/tplimpl: Update embedded instagram, twitter, and vimeo shortcodes
- Replace data.GetJSON calls with resources.GetRemote
- Remove usage of Facebook’s oEmbed Read feature

Fixes #11971
2024-02-02 08:01:45 +01:00
Bjørn Erik Pedersen 5b7cb258ec Create default link and image render hooks
Fixes #11933
2024-01-30 20:12:19 +01:00
Bjørn Erik Pedersen a795acbcd8 all: Run gofumpt -l -w . 2024-01-28 23:14:09 +01:00
Bjørn Erik Pedersen 2a0329423c
testing: Rename integration_test.go to PACKAGE_integration_test.go
Primary motivation making them easier to find in the code editor.
2024-01-28 11:41:59 +01:00
Bjørn Erik Pedersen 7285e74090
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.

Closes #11455
Closes #11549

This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.

The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.

A list of the notable new features:

* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.

New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.

This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):

Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.

Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).

Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2024-01-27 16:28:14 +01:00
Daniel Terhorst-North 87bf2b9688 tpl/tplimpl: Fix incorrect lastBuildDate
Fixes #11600

Co-authored-by: Joe Mooring <joe@mooring.com>
2024-01-25 19:46:52 +01:00
Daniel Terhorst-North f281ef8a4a tpl: fix incorrect lastBuildDate
Set the `<lastBuildDate>` field to be the most recent Lastmod date
of all the posts in the current selection.

Fixes #11600
2024-01-25 19:46:52 +01:00
Joe Mooring e40b9fbbcf tpl/math: Add math.Rand template function
Closes #11833
2023-12-29 19:37:27 +01:00
Bjørn Erik Pedersen 9f978d387f
Pull in the latest code from Go's template packages (#11771)
Fixes #10707
Fixes #11507
2023-12-04 12:07:54 +01:00
Razon Yang 14d85ec136
tpl: Allow using page resources on the images page parameter for opengraph, schema and twitter_cards templates
The page images selection order as follows:

1. Page's images parameter, image resources are supported.
2. Page's image resources that naming in *feature*, *cover* or *thumbnail* pattern.
3. If no page images specified, then the first one of site's images will be used as the fallback, supports site resources.
2023-12-04 12:05:41 +01:00
Joe Mooring b4c5df42ff tpl/transform: Add transform.XMLEscape template function
Fixes #3268
2023-11-27 10:52:33 +01:00
Joe Mooring 8d32ca223d tpl/tplimpl: Remove superfluous type attr on script elements
Closes #6379
2023-11-27 10:45:53 +01:00
Joe Mooring cb98e9061b tpl/tplimpl: Fix deprecation logic in embedded templates
Closes #11658
2023-11-01 17:42:45 +01:00
Joe Mooring 23fcfb7f74
tpl/tplimpl: Fix deprecation logic in RSS template
Closes #11639
2023-10-31 08:34:30 +01:00
Joe Mooring 2eca1b3cc1 hugolib: Deprecate .Site.DisqusShortname
Use .Site.Config.Services.Disqus.Shortname instead.
2023-10-18 17:35:54 +02:00
Lars Lehtonen 625162674d
tpl/tplimpl: Fix dropped error 2023-10-18 17:33:00 +02:00
Joe Mooring a692278bc6 hugolib: Deprecate .Site.GoogleAnalytics
Use .Site.Config.Services.GoogleAnalytics.ID instead.
2023-10-17 20:06:42 +02:00
Joe Mooring d4016dd5cd tpl/tplimpl: Deprecate .Site.Author usage in RSS template 2023-10-17 20:04:49 +02:00
Joe Mooring 4910312ee7 tpl/tplimpl: Deprecate .Site.Social usage with internal templates 2023-10-17 20:04:24 +02:00
Oleksandr Redko 274852bcf2 all: Format files with gofmt 2023-10-05 14:45:55 +02:00
Carl Johnson c32094ace1 google_analytics_async.html: Add deprecation warning 2023-09-23 18:57:19 +02:00
Oleksandr Redko e3308a0bbc tpl/tplimpl: Fix typo in global variable name 2023-06-26 15:12:21 +02:00
Bjørn Erik Pedersen ee359df172 Fix upstream Go templates bug with reversed key/value assignment
The template packages are based on go1.20.5 with the patch in befec5ddbbfbd81ec84e74e15a38044d67f8785b  added.

This also includes a security fix that now disallows Go template actions in JS literals (inside backticks).

This will throw an error saying "... appears in a JS template literal".

If you're really sure this isn't a security risk in your case, you can revert to the old behaviour:

```toml
[security]
[security.gotemplates]
allowActionJSTmpl = true
```

See https://github.com/golang/go/issues/59234

Fixes #11112
2023-06-15 23:04:33 +02:00
Joe Mooring ff77a927f9 tpl/tplimpl: Use .Language.LanguageCode in built-in templates 2023-05-30 20:10:16 +02:00
InLaw 2db7ec622f
tpl/tplimpl: Add img loading attribute to figure shortcode (#10927) 2023-05-21 12:28:45 -07:00
Bjørn Erik Pedersen 241b21b0fd Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
2023-05-16 18:01:29 +02:00
Oleksandr Redko 36ce3a4a9d Correct typos in Go comments 2023-03-02 16:32:32 +01:00
Bjørn Erik Pedersen eef23a7f27 Fix "page" not defined
Fixes #10774
2023-03-02 10:39:44 +01:00
Joe Mooring 66f94b4945 tpl/tplimpl: Remove the Google News internal template
This was deprecated, with a warning message, on 21 Nov 2021.

Reference #9190
2023-03-01 18:11:44 +01:00
Bjørn Erik Pedersen ce524d0b5e Add a page template func
Fixes #9339
2023-02-25 19:53:18 +01:00
Bjørn Erik Pedersen ecf3cd514f tocss: Simplify the hugo:vars type handling
Instead of maintaing a list of all CSS units and functions this commit:

* Uses 3 regexps to detect typed CSS values (e.g. `24px`) + properly handle numeric Go types.
* These regexps may have some false positives -- e.g. strings that needs to be quoted.
* For that rare case, you can mark the string with e.g. `"32xxx" | css.Quoted`
* For the opposite case:  `"32" | css.Unquoted`

Updates #10632
2023-02-22 13:26:10 +01:00
Joe Mooring 4989da653d Revert "tpl/tplimpl: Use https in sitemap templates"
This reverts commit 3fd0b78498.
2022-12-22 08:53:58 +01:00
Bjørn Erik Pedersen ad2059878a Also consider wrapped errors when checking for file IsNotExist errors
Fixes #10534
2022-12-14 13:51:06 +01:00
Joe Mooring 3fd0b78498 tpl/tplimpl: Use https in sitemap templates
Closes #10515
2022-12-11 18:53:30 +01:00
Razon Yang b82b547acb
tpl/embedded: Make Open Graph's series optional 2022-12-06 10:48:34 +01:00
Joe Mooring 0b976d2b40 tpl/tplimpl: Allow alternate comment syntax
Allow alternate comment syntax before block definitions:

{{/* foo */}}
{{- /* foo */}}
{{- /* foo */ -}}

Fixes #10495
2022-12-04 09:25:51 +01:00
Bjørn Erik Pedersen 9c24b86e4b Cache when not found in LookupLayout
Very visible when using the pprof mutex profiler.

```bash
name         old time/op    new time/op    delta
Baseline-10    58.4ms ± 1%    51.6ms ± 0%  -11.56%  (p=0.029 n=4+4)

name         old alloc/op   new alloc/op   delta
Baseline-10    64.3MB ± 0%    64.2MB ± 0%     ~     (p=0.114 n=4+4)

name         old allocs/op  new allocs/op  delta
Baseline-10      649k ± 0%      649k ± 0%     ~     (p=0.229 n=4+4)
```
2022-07-13 15:49:00 +02:00
Bjørn Erik Pedersen 6f7bf3f2d7 Fix indentation in highlight shortcode
This commit adds a new `.InnerDeindent` method to the shortcode context, which is `.Inner` with any
indendation removed. This is then used in the built-in `highlight` shortcode to prevent the extra
whitespace getting hightlighted.

Fixes #4717
2022-05-31 09:05:54 +02:00
Bjørn Erik Pedersen fc9f315d86 Improve SASS errors
Fixes #9897
2022-05-15 20:25:25 +02:00
Bjørn Erik Pedersen 4b189d8fd9 postcss: Fix import error handling
Note that we will now fail if `inlineImports` is enabled and we cannot resolve an import.

You can work around this by either:

* Use url imports or imports with media queries.
* Set `skipInlineImportsNotFound=true` in the options

Also get the argument order in the different NewFileError* funcs in line.

Fixes #9895
2022-05-15 20:25:25 +02:00
Bjørn Erik Pedersen 5c96bda70a
errors: Misc improvements
* Redo the server error template
* Always add the content file context if relevant
* Remove some now superflous error string matching
* Move the server error template to _server/error.html
* Add file context (with position) to codeblock render blocks
* Improve JS build errors

Fixes #9892
Fixes #9891
Fixes #9893
2022-05-14 13:40:56 +02:00
Bjørn Erik Pedersen 51f08b0b6a Revise the use of htime.Since/htime.Now
We cannot (also, it doesn't add any value)  use that when the `clock` is set,

* To measure time (before that global is set)
* To compare file timestamps re cache eviction

Fixes #9868
2022-05-09 14:18:40 +02:00
satotake e77ca3c105 Add clock cli flag
Close #8787
2022-05-08 16:56:26 +02:00
Bjørn Erik Pedersen f2946da9e8 Improve error messages, esp. when the server is running
* Add file context to minifier errors when publishing
* Misc fixes (see issues)
* Allow custom server error template in layouts/server/error.html

To get to this, this commit also cleans up and simplifies the code surrounding errors and files. This also removes the usage of `github.com/pkg/errors`, mostly because of https://github.com/pkg/errors/issues/223 -- but also because most of this is now built-in to Go.

Fixes #9852
Fixes #9857
Fixes #9863
2022-05-06 19:43:22 +02:00
Bjørn Erik Pedersen b80853de90
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
2022-03-17 22:03:27 +01:00
Bjørn Erik Pedersen 3476b53343
tpl: Pull in Go 1.18 patch that fixes the "no space in {{ continue }} and {{ break }}" bug 2022-03-16 13:14:23 +01:00
Bjørn Erik Pedersen 42cc5f88b6
tpl: Adjustments and an integration test for Go 1.18
Updates #9677
2022-03-16 10:36:46 +01:00
Joe Mooring f98e570b17 Add lang attribute to internal alias template
Closes #9586
2022-03-09 19:06:59 +01:00