summaryrefslogtreecommitdiffstats
path: root/hugolib/page_test.go
Commit message (Collapse)AuthorAge
* Deprecate kind, lang, and path from front matterBjørn Erik Pedersen2025-02-10
| | | | | | | | These were added to the page meta object when we implemented "pages from data", but were not meant to be used in front matter. That is not supported, so we might as well add validation. Fixes #12484
* Add site.Store and hugo.Store and Shortcode.StoreBjørn Erik Pedersen2024-11-13
| | | | Closes #13021
* Alias Page.Scratch to Page.Store (note)Bjørn Erik Pedersen2024-11-06
| | | | Fixes #13016
* Don't count HTML markup in auto summariesBjørn Erik Pedersen2024-09-10
| | | | | | This commit also fixes a bug where a `</picture>` end tag was wrongly used to detect a end paragraph. This should be very rare, though. Closes #12837
* Fix stray end p tag in Obsidian callout titlesBjørn Erik Pedersen2024-09-05
| | | | | | Also remove test references to deprecated funcs now in ERROR. Closes #12828
* Add Page.Contents with scope supportBjørn Erik Pedersen2024-08-29
| | | | | | | | | | | Note that this also adds a new `.ContentWithoutSummary` method, and to do that we had to unify the different summary types: Both `auto` and `manual` now returns HTML. Before this commit, `auto` would return plain text. This could be considered to be a slightly breaking change, but for the better: Now you can treat the `.Summary` the same without thinking about where it comes from, and if you want plain text, pipe it into `{{ .Summary | plainify }}`. Fixes #8680 Fixes #12761 Fixes #12778 Fixes #716
* Consolidate all hashing to the common/hashing packageBjørn Erik Pedersen2024-07-31
| | | | And remove now unsued hashing funcs.
* hugolib: Fix regression for blank summariescuregit2024-04-05
| | | | | | | Fix regression in content summarization so that we can use empty summary by using the manual summary divider. Since v0.123, there has been the regression that causes Hugo to use automatic summary generation when the manual summary results in an empty string, even if there is a `<!--more-->` summary divider.
* Fix translationKey handling for term pagesBjørn Erik Pedersen2024-03-15
| | | | Fixes #12261
* tpl/tplimpl: Modify figure shortcode to look for page resourceJoe Mooring2024-03-14
| | | | | Closes #12244 Closes #12245
* hugolib: Deprecate .Site.MultiLingual in favor of hugo.IsMultiLingualJoe Mooring2024-03-10
| | | | Closes #12224
* Make HTML behave exactly like other content formats (note)Bjørn Erik Pedersen2024-02-07
| | | | Fixes #11999
* Preserve file/dir name case when loading dataBjørn Erik Pedersen2024-02-03
| | | | Fixes #11979
* testing: Simplify some integration testsBjørn Erik Pedersen2024-01-28
|
* all: Rework page store, add a dynacache, improve partial rebuilds, and some ↵develop2024Bjørn Erik Pedersen2024-01-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* tpl/collections: Make delimit return a stringBjørn Erik Pedersen2023-10-28
| | | | | Closes #10876 Closes #11502
* markdown: Pass emoji codes to yuin/goldmark-emojiJoe Mooring2023-10-24
| | | | | | | | | | | | Removes emoji code conversion from the page and shortcode parsers. Emoji codes in markdown are now passed to Goldmark, where the goldmark-emoji extension converts them to decimal numeric character references. This disables emoji rendering for the alternate content formats: html, asciidoc, org, pandoc, and rst. Fixes #7332 Fixes #11587 Closes #11598
* Fix .RawContent for empty content pages (#11407)Bjørn Erik Pedersen2023-08-30
| | | Fixes #11406
* Add Page.RenderShortcodesBjørn Erik Pedersen2023-08-03
| | | | | | | | | | | A layouts/shortcodes/include.html shortcode may look like this: ```html {{ $p := site.GetPage (.Get 0) }} {{ $p.RenderShortcodes }} ``` Fixes #7297
* Return error when .Render is invoked without argBjørn Erik Pedersen2023-07-13
| | | | Fixes #11243
* Bump github.com/bep/clock v0.3.0 to renamed github.com/bep/clocks v0.5.0Anthony Fok2023-07-04
|
* Replace the old log setup, with structured logging etc.Bjørn Erik Pedersen2023-06-18
| | | | Fixes #11124
* Create a struct with all of Hugo's config optionsBjørn Erik Pedersen2023-05-16
| | | | | | | | | | | | 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
* Add page fragments support to RelatedBjørn Erik Pedersen2023-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main topic of this commit is that you can now index fragments (content heading identifiers) when calling `.Related`. You can do this by: * Configure one or more indices with type `fragments` * The name of those index configurations maps to an (optional) front matter slice with fragment references. This allows you to link page<->fragment and page<->page. * This also will index all the fragments (heading identifiers) of the pages. It's also possible to use type `fragments` indices in shortcode, e.g.: ``` {{ $related := site.RegularPages.Related .Page }} ``` But, and this is important, you need to include the shortcode using the `{{<` delimiter. Not doing so will create infinite loops and timeouts. This commit also: * Adds two new methods to Page: Fragments (can also be used to build ToC) and HeadingsFiltered (this is only used in Related Content with index type `fragments` and `enableFilter` set to true. * Consolidates all `.Related*` methods into one, which takes either a `Page` or an options map as its only argument. * Add `context.Context` to all of the content related Page API. Turns out it wasn't strictly needed for this particular feature, but it will soon become usefil, e.g. in #9339. Closes #10711 Updates #9339 Updates #10725
* Only invoke a given cached partial onceBjørn Erik Pedersen2023-01-25
| | | | | | | | | | | | | | | | | | | | | | Note that this is backed by a LRU cache (which we soon shall see more usage of), so if you're a heavy user of cached partials it may be evicted and refreshed if needed. But in most cases every partial is only invoked once. This commit also adds a timeout (the global `timeout` config option) to make infinite recursion in partials easier to reason about. ``` name old time/op new time/op delta IncludeCached-10 8.92ms ± 0% 8.48ms ± 1% -4.87% (p=0.016 n=4+5) name old alloc/op new alloc/op delta IncludeCached-10 6.65MB ± 0% 5.17MB ± 0% -22.32% (p=0.002 n=6+6) name old allocs/op new allocs/op delta IncludeCached-10 117k ± 0% 71k ± 0% -39.44% (p=0.002 n=6+6) ``` Closes #4086 Updates #9588
* Remove Blackfriday markdown engineBjørn Erik Pedersen2022-05-29
| | | | | | | It has been deprecated for a long time, its v1 version is not maintained anymore, and there are many known issues. Goldmark should be a mature replacement by now. Closes #9934
* Fix Plainify edge casesBjørn Erik Pedersen2022-05-25
| | | | | | | | | | | | | | | This commit replaces the main part of `helpers.StripHTML` with Go's implementation in its html/template package. It's a little slower, but correctness is more important: ```bash BenchmarkStripHTMLOld-10 680316 1764 ns/op 728 B/op 4 allocs/op BenchmarkStripHTMLNew-10 384520 3099 ns/op 2089 B/op 10 allocs/op ``` Fixes #9199 Fixes #9909 Closes #9410
* Use configured timeZone for the clockBjørn Erik Pedersen2022-05-08
| | | | | | And some other related adjustments. Updates #8787
* Add `clock` cli flagsatotake2022-05-08
| | | | Close #8787
* deps: Update github.com/yuin/goldmark v1.4.11 => v1.4.12Joe Mooring2022-04-27
| | | | | | Fixes #9054 Fixes #9756 Fixes #9757
* Rework the Destination filesystem to make --renderStaticToDisk workBjørn Erik Pedersen2022-04-08
| | | | See #9626
* all: gofmt -w -r 'interface{} -> any' .Bjørn Erik Pedersen2022-03-17
| | | | Updates #9687
* Add lang attribute to internal alias templateJoe Mooring2022-03-09
| | | | Closes #9586
* Rename Codeowners() to CodeOwners()Bjørn Erik Pedersen2022-02-27
|
* Add Markdown diagrams and render hooks for code blocksBjørn Erik Pedersen2022-02-24
| | | | | | | | | | | | | | | | You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`). We also used this new hook to add support for diagrams in Hugo: * Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams. * Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information. Updates #7765 Closes #9538 Fixes #9553 Fixes #8520 Fixes #6702 Fixes #9558
* Add support for CODEOWNERSMarshall Cottrell2022-02-23
| | | | Fixes #9474
* Add page.StoreBjørn Erik Pedersen2022-02-23
| | | | Fixes #9546
* deps: Update github.com/alecthomas/chroma v0.9.4 => v0.10.0Bjørn Erik Pedersen2022-02-15
|
* Make the RenderString content provider fix more generalBjørn Erik Pedersen2022-01-27
| | | | Updates #9383
* Fix .RenderString issue in .TranslationsPaul Gottschling2022-01-27
| | | | Fixes #9383
* Fix missing page data for alternative formatsPaul Gottschling2022-01-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a template calls the .Translations function and a Hugo environment is using multiple output formats, a template that calls methods like .Summary and .Len on each translation will unexpectedly show empty return values for these methods. This is because each pageOutput's ContentProvider is assigned to a page.NopPage in newPageOutput. When *HugoSites.render assigns pageContentOutputs to pageOutputs in *pageState.shiftToOutputFormat, it reuses pageContentOutputs from other pageOutputs, leaving some pageContentOutputs as NopPages. While this approach conserves resources, sometimes it means that a template will unexpectedly call a method on a pageContentOutput that is actually a NopPage. In the case of ContentProvider methods called on translations for alternative output formats, the methods were called on NopPages. This change introduces LazyContentProvider, which performs late initialization when one of its methods is called. This way, we can reuse content in "normal" cases but ensure that ContentProvider methods work as expected when a pageOutput is not assigned a pageContentOutput during the initial pre-render phase. Fixes #8919
* Remove mmarkBjørn Erik Pedersen2022-01-04
| | | | Closes #9350
* hugolib: Make an RST test optionalBjørn Erik Pedersen2022-01-01
| | | | If no RST installed.
* Add some basic security policies with sensible defaultsBjørn Erik Pedersen2021-12-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This ommmit contains some security hardening measures for the Hugo build runtime. There are some rarely used features in Hugo that would be good to have disabled by default. One example would be the "external helpers". For `asciidoctor` and some others we use Go's `os/exec` package to start a new process. These are a predefined set of binary names, all loaded from `PATH` and with a predefined set of arguments. Still, if you don't use `asciidoctor` in your project, you might as well have it turned off. You can configure your own in the new `security` configuration section, but the defaults are configured to create a minimal amount of site breakage. And if that do happen, you will get clear instructions in the loa about what to do. The default configuration is listed below. Note that almost all of these options are regular expression _whitelists_ (a string or a slice); the value `none` will block all. ```toml [security] enableInlineShortcodes = false [security.exec] allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$'] osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$'] [security.funcs] getenv = ['^HUGO_'] [security.http] methods = ['(?i)GET|POST'] urls = ['.*'] ```
* markup: Add tabindex="0" to default <pre> wrapperrhymes2021-07-15
| | | | | | Currently the generated `<pre>` element isn't fully accessible as it can't be focused by keyboard users. To make this fully accessible, the attribute `tabindex="0"` should be added to the `<pre>` tag. Closes #7194
* Misc config loading fixesBjørn Erik Pedersen2021-06-14
| | | | | | | | | | | | | | | | The main motivation behind this is simplicity and correctnes, but the new small config library is also faster: ``` BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op ``` Fixes #8633 Fixes #8618 Fixes #8630 Updates #8591 Closes #6680 Closes #5192
* build(deps): bump github.com/yuin/goldmark from 1.3.2 to 1.3.5Joe Mooring2021-04-16
| | | | | | Updated test per <https://github.com/yuin/goldmark/pull/205>. Fixes #8377
* Remove extraneous space from figure shortcodeJoe Mooring2021-04-15
| | | | Fixes #8401
* Add Dart Sass supportBjørn Erik Pedersen2020-12-30
| | | | | | | But note that the Dart Sass Embedded Protocol is still in beta (beta 5), a main release scheduled for Q1 2021. Fixes #7380 Fixes #8102
* all: Format code with gofumptBjørn Erik Pedersen2020-12-03
| | | | See https://github.com/mvdan/gofumpt