You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2002 lines
54 KiB

12 years ago
Rework external asciidoctor integration This commit solves the relative path problem with asciidoctor tooling. An include will resolve relatively, so you can refer easily to files in the same folder. Also `asciidoctor-diagram` and PlantUML rendering works now, because the created temporary files will be placed in the correct folder. This patch covers just the Ruby version of asciidoctor. The old AsciiDoc CLI EOLs in Jan 2020, so this variant is removed from code. The configuration is completely rewritten and now available in `config.toml` under the key `[markup.asciidocext]`: ```toml [markup.asciidocext] extensions = ["asciidoctor-html5s", "asciidoctor-diagram"] workingFolderCurrent = true trace = true [markup.asciidocext.attributes] my-base-url = "https://example.com/" my-attribute-name = "my value" ``` - backends, safe-modes, and extensions are now whitelisted to the popular (ruby) extensions and valid values. - the default for extensions is to not enable any, because they're all external dependencies so the build would break if the user didn't install them beforehand. - the default backend is html5 because html5s is an external gem dependency. - the default safe-mode is safe, explanations of the modes: https://asciidoctor.org/man/asciidoctor/ - the config is namespaced under asciidocext_config and the parser looks at asciidocext to allow a future native Go asciidoc. - `uglyUrls=true` option and `--source` flag are supported - `--destination` flag is required Follow the updated documentation under `docs/content/en/content-management/formats.md`. This patch would be a breaking change, because you need to correct all your absolute include pathes to relative paths, so using relative paths must be configured explicitly by setting `workingFolderCurrent = true`.
5 years ago
Shortcode rewrite, take 2 This commit contains a restructuring and partial rewrite of the shortcode handling. Prior to this commit rendering of the page content was mingled with handling of the shortcodes. This led to several oddities. The new flow is: 1. Shortcodes are extracted from page and replaced with placeholders. 2. Shortcodes are processed and rendered 3. Page is processed 4. The placeholders are replaced with the rendered shortcodes The handling of summaries is also made simpler by this. This commit also introduces some other chenges: 1. distinction between shortcodes that need further processing and those who do not: * `{{< >}}`: Typically raw HTML. Will not be processed. * `{{% %}}`: Will be processed by the page's markup engine (Markdown or (infuture) Asciidoctor) The above also involves a new shortcode-parser, with lexical scanning inspired by Rob Pike's talk called "Lexical Scanning in Go", which should be easier to understand, give better error messages and perform better. 2. If you want to exclude a shortcode from being processed (for documentation etc.), the inner part of the shorcode must be commented out, i.e. `{{%/* movie 47238zzb */%}}`. See the updated shortcode section in the documentation for further examples. The new parser supports nested shortcodes. This isn't new, but has two related design choices worth mentioning: * The shortcodes will be rendered individually, so If both `{{< >}}` and `{{% %}}` are used in the nested hierarchy, one will be passed through the page's markdown processor, the other not. * To avoid potential costly overhead of always looking far ahead for a possible closing tag, this implementation looks at the template itself, and is branded as a container with inner content if it contains a reference to `.Inner` Fixes #565 Fixes #480 Fixes #461 And probably some others.
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
Rework external asciidoctor integration This commit solves the relative path problem with asciidoctor tooling. An include will resolve relatively, so you can refer easily to files in the same folder. Also `asciidoctor-diagram` and PlantUML rendering works now, because the created temporary files will be placed in the correct folder. This patch covers just the Ruby version of asciidoctor. The old AsciiDoc CLI EOLs in Jan 2020, so this variant is removed from code. The configuration is completely rewritten and now available in `config.toml` under the key `[markup.asciidocext]`: ```toml [markup.asciidocext] extensions = ["asciidoctor-html5s", "asciidoctor-diagram"] workingFolderCurrent = true trace = true [markup.asciidocext.attributes] my-base-url = "https://example.com/" my-attribute-name = "my value" ``` - backends, safe-modes, and extensions are now whitelisted to the popular (ruby) extensions and valid values. - the default for extensions is to not enable any, because they're all external dependencies so the build would break if the user didn't install them beforehand. - the default backend is html5 because html5s is an external gem dependency. - the default safe-mode is safe, explanations of the modes: https://asciidoctor.org/man/asciidoctor/ - the config is namespaced under asciidocext_config and the parser looks at asciidocext to allow a future native Go asciidoc. - `uglyUrls=true` option and `--source` flag are supported - `--destination` flag is required Follow the updated documentation under `docs/content/en/content-management/formats.md`. This patch would be a breaking change, because you need to correct all your absolute include pathes to relative paths, so using relative paths must be configured explicitly by setting `workingFolderCurrent = true`.
5 years ago
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
2 years ago
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
2 years ago
Introduce a tree map for all content This commit introduces a new data structure to store pages and their resources. This data structure is backed by radix trees. This simplies tree operations, makes all pages a bundle, and paves the way for #6310. It also solves a set of annoying issues (see list below). Not a motivation behind this, but this commit also makes Hugo in general a little bit faster and more memory effective (see benchmarks). Especially for partial rebuilds on content edits, but also when taxonomies is in use. ``` name old time/op new time/op delta SiteNew/Bundle_with_image/Edit-16 1.32ms ± 8% 1.00ms ± 9% -24.42% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file/Edit-16 1.28ms ± 0% 0.94ms ± 0% -26.26% (p=0.029 n=4+4) SiteNew/Tags_and_categories/Edit-16 33.9ms ± 2% 21.8ms ± 1% -35.67% (p=0.029 n=4+4) SiteNew/Canonify_URLs/Edit-16 40.6ms ± 1% 37.7ms ± 3% -7.20% (p=0.029 n=4+4) SiteNew/Deep_content_tree/Edit-16 56.7ms ± 0% 51.7ms ± 1% -8.82% (p=0.029 n=4+4) SiteNew/Many_HTML_templates/Edit-16 19.9ms ± 2% 18.3ms ± 3% -7.64% (p=0.029 n=4+4) SiteNew/Page_collections/Edit-16 37.9ms ± 4% 34.0ms ± 2% -10.28% (p=0.029 n=4+4) SiteNew/Bundle_with_image-16 10.7ms ± 0% 10.6ms ± 0% -1.15% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 10.8ms ± 0% 10.7ms ± 0% -1.05% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 43.2ms ± 1% 39.6ms ± 1% -8.35% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 47.6ms ± 1% 47.3ms ± 0% ~ (p=0.057 n=4+4) SiteNew/Deep_content_tree-16 73.0ms ± 1% 74.2ms ± 1% ~ (p=0.114 n=4+4) SiteNew/Many_HTML_templates-16 37.9ms ± 0% 38.1ms ± 1% ~ (p=0.114 n=4+4) SiteNew/Page_collections-16 53.6ms ± 1% 54.7ms ± 1% +2.09% (p=0.029 n=4+4) name old alloc/op new alloc/op delta SiteNew/Bundle_with_image/Edit-16 486kB ± 0% 430kB ± 0% -11.47% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file/Edit-16 265kB ± 0% 209kB ± 0% -21.06% (p=0.029 n=4+4) SiteNew/Tags_and_categories/Edit-16 13.6MB ± 0% 8.8MB ± 0% -34.93% (p=0.029 n=4+4) SiteNew/Canonify_URLs/Edit-16 66.5MB ± 0% 63.9MB ± 0% -3.95% (p=0.029 n=4+4) SiteNew/Deep_content_tree/Edit-16 28.8MB ± 0% 25.8MB ± 0% -10.55% (p=0.029 n=4+4) SiteNew/Many_HTML_templates/Edit-16 6.16MB ± 0% 5.56MB ± 0% -9.86% (p=0.029 n=4+4) SiteNew/Page_collections/Edit-16 16.9MB ± 0% 16.0MB ± 0% -5.19% (p=0.029 n=4+4) SiteNew/Bundle_with_image-16 2.28MB ± 0% 2.29MB ± 0% +0.35% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 2.07MB ± 0% 2.07MB ± 0% ~ (p=0.114 n=4+4) SiteNew/Tags_and_categories-16 14.3MB ± 0% 13.2MB ± 0% -7.30% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 69.1MB ± 0% 69.0MB ± 0% ~ (p=0.343 n=4+4) SiteNew/Deep_content_tree-16 31.3MB ± 0% 31.8MB ± 0% +1.49% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 10.8MB ± 0% 10.9MB ± 0% +1.11% (p=0.029 n=4+4) SiteNew/Page_collections-16 21.4MB ± 0% 21.6MB ± 0% +1.15% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Bundle_with_image/Edit-16 4.74k ± 0% 3.86k ± 0% -18.57% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file/Edit-16 4.73k ± 0% 3.85k ± 0% -18.58% (p=0.029 n=4+4) SiteNew/Tags_and_categories/Edit-16 301k ± 0% 198k ± 0% -34.14% (p=0.029 n=4+4) SiteNew/Canonify_URLs/Edit-16 389k ± 0% 373k ± 0% -4.07% (p=0.029 n=4+4) SiteNew/Deep_content_tree/Edit-16 338k ± 0% 262k ± 0% -22.63% (p=0.029 n=4+4) SiteNew/Many_HTML_templates/Edit-16 102k ± 0% 88k ± 0% -13.81% (p=0.029 n=4+4) SiteNew/Page_collections/Edit-16 176k ± 0% 152k ± 0% -13.32% (p=0.029 n=4+4) SiteNew/Bundle_with_image-16 26.8k ± 0% 26.8k ± 0% +0.05% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 26.8k ± 0% 26.8k ± 0% +0.05% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 273k ± 0% 245k ± 0% -10.36% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 396k ± 0% 398k ± 0% +0.39% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 317k ± 0% 325k ± 0% +2.53% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 146k ± 0% 147k ± 0% +0.98% (p=0.029 n=4+4) SiteNew/Page_collections-16 210k ± 0% 215k ± 0% +2.44% (p=0.029 n=4+4) ``` Fixes #6312 Fixes #6087 Fixes #6738 Fixes #6412 Fixes #6743 Fixes #6875 Fixes #6034 Fixes #6902 Fixes #6173 Fixes #6590
6 years ago
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
2 years ago
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
2 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
12 years ago
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
2 years ago
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
2 years ago
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
2 years ago
12 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
hugolib: Extract date and slug from filename This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
7 years ago
12 years ago
12 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
  1. // Copyright 2019 The Hugo Authors. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package hugolib
  14. import (
  15. "context"
  16. "fmt"
  17. "html/template"
  18. "path/filepath"
  19. "strings"
  20. "testing"
  21. "time"
  22. "github.com/bep/clocks"
  23. "github.com/gohugoio/hugo/markup/asciidocext"
  24. "github.com/gohugoio/hugo/markup/rst"
  25. "github.com/gohugoio/hugo/tpl"
  26. "github.com/gohugoio/hugo/config"
  27. "github.com/gohugoio/hugo/common/hashing"
  28. "github.com/gohugoio/hugo/common/htime"
  29. "github.com/gohugoio/hugo/common/loggers"
  30. "github.com/gohugoio/hugo/resources/page"
  31. "github.com/gohugoio/hugo/resources/resource"
  32. qt "github.com/frankban/quicktest"
  33. "github.com/gohugoio/hugo/deps"
  34. )
  35. const (
  36. homePage = "---\ntitle: Home\n---\nHome Page Content\n"
  37. simplePage = "---\ntitle: Simple\n---\nSimple Page\n"
  38. simplePageRFC3339Date = "---\ntitle: RFC3339 Date\ndate: \"2013-05-17T16:59:30Z\"\n---\nrfc3339 content"
  39. simplePageWithoutSummaryDelimiter = `---
  40. title: SimpleWithoutSummaryDelimiter
  41. ---
  42. [Lorem ipsum](https://lipsum.com/) dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  43. Additional text.
  44. Further text.
  45. `
  46. simplePageWithSummaryDelimiter = `---
  47. title: Simple
  48. ---
  49. Summary Next Line
  50. <!--more-->
  51. Some more text
  52. `
  53. simplePageWithSummaryParameter = `---
  54. title: SimpleWithSummaryParameter
  55. summary: "Page with summary parameter and [a link](http://www.example.com/)"
  56. ---
  57. Some text.
  58. Some more text.
  59. `
  60. simplePageWithSummaryDelimiterAndMarkdownThatCrossesBorder = `---
  61. title: Simple
  62. ---
  63. The [best static site generator][hugo].[^1]
  64. <!--more-->
  65. [hugo]: http://gohugo.io/
  66. [^1]: Many people say so.
  67. `
  68. simplePageWithShortcodeInSummary = `---
  69. title: Simple
  70. ---
  71. Summary Next Line. {{<figure src="/not/real" >}}.
  72. More text here.
  73. Some more text
  74. `
  75. simplePageWithSummaryDelimiterSameLine = `---
  76. title: Simple
  77. ---
  78. Summary Same Line<!--more-->
  79. Some more text
  80. `
  81. simplePageWithAllCJKRunes = `---
  82. title: Simple
  83. ---
  84. 你好
  85. 도형이
  86. カテゴリー
  87. `
  88. simplePageWithMainEnglishWithCJKRunes = `---
  89. title: Simple
  90. ---
  91. In Chinese, means good. In Chinese, means good.
  92. In Chinese, means good. In Chinese, means good.
  93. In Chinese, means good. In Chinese, means good.
  94. In Chinese, means good. In Chinese, means good.
  95. In Chinese, means good. In Chinese, means good.
  96. In Chinese, means good. In Chinese, means good.
  97. In Chinese, means good. In Chinese, means good.
  98. More then 70 words.
  99. `
  100. simplePageWithMainEnglishWithCJKRunesSummary = "In Chinese, 好 means good. In Chinese, 好 means good. " +
  101. "In Chinese, 好 means good. In Chinese, 好 means good. " +
  102. "In Chinese, 好 means good. In Chinese, 好 means good. " +
  103. "In Chinese, 好 means good. In Chinese, 好 means good. " +
  104. "In Chinese, 好 means good. In Chinese, 好 means good. " +
  105. "In Chinese, 好 means good. In Chinese, 好 means good. " +
  106. "In Chinese, 好 means good. In Chinese, 好 means good."
  107. simplePageWithIsCJKLanguageFalse = `---
  108. title: Simple
  109. isCJKLanguage: false
  110. ---
  111. In Chinese, 好的啊 means good. In Chinese, 好的呀 means good.
  112. In Chinese, 好的啊 means good. In Chinese, 好的呀 means good.
  113. In Chinese, 好的啊 means good. In Chinese, 好的呀 means good.
  114. In Chinese, 好的啊 means good. In Chinese, 好的呀 means good.
  115. In Chinese, 好的啊 means good. In Chinese, 好的呀 means good.
  116. In Chinese, 好的啊 means good. In Chinese, 好的呀 means good.
  117. In Chinese, 好的啊 means good. In Chinese, 好的呀呀 means good enough.
  118. More then 70 words.
  119. `
  120. simplePageWithIsCJKLanguageFalseSummary = "In Chinese, 好的啊 means good. In Chinese, 好的呀 means good. " +
  121. "In Chinese, 好的啊 means good. In Chinese, 好的呀 means good. " +
  122. "In Chinese, 好的啊 means good. In Chinese, 好的呀 means good. " +
  123. "In Chinese, 好的啊 means good. In Chinese, 好的呀 means good. " +
  124. "In Chinese, 好的啊 means good. In Chinese, 好的呀 means good. " +
  125. "In Chinese, 好的啊 means good. In Chinese, 好的呀 means good. " +
  126. "In Chinese, 好的啊 means good. In Chinese, 好的呀呀 means good enough."
  127. simplePageWithLongContent = `---
  128. title: Simple
  129. ---
  130. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
  131. incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
  132. nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  133. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
  134. fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
  135. culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit
  136. amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
  137. et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
  138. ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
  139. in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
  140. pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
  141. officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet,
  142. consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
  143. dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
  144. laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
  145. reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
  146. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
  147. deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur
  148. adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
  149. aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
  150. ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
  151. voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
  152. occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
  153. id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
  154. do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
  155. veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  156. consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
  157. cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
  158. proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem
  159. ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
  160. incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
  161. nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  162. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
  163. fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
  164. culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit
  165. amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
  166. et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
  167. ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
  168. in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
  169. pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
  170. officia deserunt mollit anim id est laborum.`
  171. pageWithToC = `---
  172. title: TOC
  173. ---
  174. For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
  175. ## AA
  176. I have no idea, of course, how long it took me to reach the limit of the plain,
  177. but at last I entered the foothills, following a pretty little canyon upward
  178. toward the mountains. Beside me frolicked a laughing brooklet, hurrying upon
  179. its noisy way down to the silent sea. In its quieter pools I discovered many
  180. small fish, of four-or five-pound weight I should imagine. In appearance,
  181. except as to size and color, they were not unlike the whale of our own seas. As
  182. I watched them playing about I discovered, not only that they suckled their
  183. young, but that at intervals they rose to the surface to breathe as well as to
  184. feed upon certain grasses and a strange, scarlet lichen which grew upon the
  185. rocks just above the water line.
  186. ### AAA
  187. I remember I felt an extraordinary persuasion that I was being played with,
  188. that presently, when I was upon the very verge of safety, this mysterious
  189. death--as swift as the passage of light--would leap after me from the pit about
  190. the cylinder and strike me down. ## BB
  191. ### BBB
  192. "You're a great Granser," he cried delightedly, "always making believe them little marks mean something."
  193. `
  194. simplePageWithURL = `---
  195. title: Simple
  196. url: simple/url/
  197. ---
  198. Simple Page With URL`
  199. simplePageWithSlug = `---
  200. title: Simple
  201. slug: simple-slug
  202. ---
  203. Simple Page With Slug`
  204. simplePageWithDate = `---
  205. title: Simple
  206. date: '2013-10-15T06:16:13'
  207. ---
  208. Simple Page With Date`
  209. UTF8Page = `---
  210. title: ラーメン
  211. ---
  212. UTF8 Page`
  213. UTF8PageWithURL = `---
  214. title: ラーメン
  215. url: ラーメン/url/
  216. ---
  217. UTF8 Page With URL`
  218. UTF8PageWithSlug = `---
  219. title: ラーメン
  220. slug: ラーメン-slug
  221. ---
  222. UTF8 Page With Slug`
  223. UTF8PageWithDate = `---
  224. title: ラーメン
  225. date: '2013-10-15T06:16:13'
  226. ---
  227. UTF8 Page With Date`
  228. )
  229. func checkPageTitle(t *testing.T, page page.Page, title string) {
  230. if page.Title() != title {
  231. t.Fatalf("Page title is: %s. Expected %s", page.Title(), title)
  232. }
  233. }
  234. func checkPageContent(t *testing.T, page page.Page, expected string, msg ...any) {
  235. t.Helper()
  236. a := normalizeContent(expected)
  237. b := normalizeContent(content(page))
  238. if a != b {
  239. t.Fatalf("Page content is:\n%q\nExpected:\n%q (%q)", b, a, msg)
  240. }
  241. }
  242. func normalizeContent(c string) string {
  243. norm := c
  244. norm = strings.Replace(norm, "\n", " ", -1)
  245. norm = strings.Replace(norm, " ", " ", -1)
  246. norm = strings.Replace(norm, " ", " ", -1)
  247. norm = strings.Replace(norm, " ", " ", -1)
  248. norm = strings.Replace(norm, "p> ", "p>", -1)
  249. norm = strings.Replace(norm, "> <", "> <", -1)
  250. return strings.TrimSpace(norm)
  251. }
  252. func checkPageTOC(t *testing.T, page page.Page, toc string) {
  253. t.Helper()
  254. if page.TableOfContents(context.Background()) != template.HTML(toc) {
  255. t.Fatalf("Page TableOfContents is:\n%q.\nExpected %q", page.TableOfContents(context.Background()), toc)
  256. }
  257. }
  258. func checkPageSummary(t *testing.T, page page.Page, summary string, msg ...any) {
  259. s := string(page.Summary(context.Background()))
  260. a := normalizeContent(s)
  261. b := normalizeContent(summary)
  262. if a != b {
  263. t.Fatalf("Page summary is:\n%q.\nExpected\n%q (%q)", a, b, msg)
  264. }
  265. }
  266. func checkPageType(t *testing.T, page page.Page, pageType string) {
  267. if page.Type() != pageType {
  268. t.Fatalf("Page type is: %s. Expected: %s", page.Type(), pageType)
  269. }
  270. }
  271. func checkPageDate(t *testing.T, page page.Page, time time.Time) {
  272. if page.Date() != time {
  273. t.Fatalf("Page date is: %s. Expected: %s", page.Date(), time)
  274. }
  275. }
  276. func normalizeExpected(ext, str string) string {
  277. str = normalizeContent(str)
  278. switch ext {
  279. default:
  280. return str
  281. case "html":
  282. return strings.Trim(tpl.StripHTML(str), " ")
  283. case "ad":
  284. paragraphs := strings.Split(str, "</p>")
  285. expected := ""
  286. for _, para := range paragraphs {
  287. if para == "" {
  288. continue
  289. }
  290. expected += fmt.Sprintf("<div class=\"paragraph\">\n%s</p></div>\n", para)
  291. }
  292. return expected
  293. case "rst":
  294. if str == "" {
  295. return "<div class=\"document\"></div>"
  296. }
  297. return fmt.Sprintf("<div class=\"document\">\n\n\n%s</div>", str)
  298. }
  299. }
  300. func testAllMarkdownEnginesForPages(t *testing.T,
  301. assertFunc func(t *testing.T, ext string, pages page.Pages), settings map[string]any, pageSources ...string,
  302. ) {
  303. engines := []struct {
  304. ext string
  305. shouldExecute func() bool
  306. }{
  307. {"md", func() bool { return true }},
  308. {"ad", func() bool { return asciidocext.Supports() }},
  309. {"rst", func() bool { return rst.Supports() }},
  310. }
  311. for _, e := range engines {
  312. if !e.shouldExecute() {
  313. continue
  314. }
  315. t.Run(e.ext, func(t *testing.T) {
  316. cfg := config.New()
  317. for k, v := range settings {
  318. cfg.Set(k, v)
  319. }
  320. if s := cfg.GetString("contentDir"); s != "" && s != "content" {
  321. panic("contentDir must be set to 'content' for this test")
  322. }
  323. files := `
  324. -- hugo.toml --
  325. [security]
  326. [security.exec]
  327. allow = ['^python$', '^rst2html.*', '^asciidoctor$']
  328. `
  329. for i, source := range pageSources {
  330. files += fmt.Sprintf("-- content/p%d.%s --\n%s\n", i, e.ext, source)
  331. }
  332. homePath := fmt.Sprintf("_index.%s", e.ext)
  333. files += fmt.Sprintf("-- content/%s --\n%s\n", homePath, homePage)
  334. b := NewIntegrationTestBuilder(
  335. IntegrationTestConfig{
  336. T: t,
  337. TxtarString: files,
  338. NeedsOsFS: true,
  339. BaseCfg: cfg,
  340. },
  341. ).Build()
  342. s := b.H.Sites[0]
  343. b.Assert(len(s.RegularPages()), qt.Equals, len(pageSources))
  344. assertFunc(t, e.ext, s.RegularPages())
  345. home := s.Home()
  346. b.Assert(home, qt.Not(qt.IsNil))
  347. b.Assert(home.File().Path(), qt.Equals, homePath)
  348. b.Assert(content(home), qt.Contains, "Home Page Content")
  349. })
  350. }
  351. }
  352. // Issue #1076
  353. func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) {
  354. t.Parallel()
  355. cfg, fs := newTestCfg()
  356. c := qt.New(t)
  357. configs, err := loadTestConfigFromProvider(cfg)
  358. c.Assert(err, qt.IsNil)
  359. writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageWithSummaryDelimiterAndMarkdownThatCrossesBorder)
  360. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
  361. c.Assert(len(s.RegularPages()), qt.Equals, 1)
  362. p := s.RegularPages()[0]
  363. if p.Summary(context.Background()) != template.HTML(
  364. "<p>The <a href=\"http://gohugo.io/\">best static site generator</a>.<sup id=\"fnref:1\"><a href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\">1</a></sup></p>") {
  365. t.Fatalf("Got summary:\n%q", p.Summary(context.Background()))
  366. }
  367. cnt := content(p)
  368. if cnt != "<p>The <a href=\"http://gohugo.io/\">best static site generator</a>.<sup id=\"fnref:1\"><a href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\">1</a></sup></p>\n<div class=\"footnotes\" role=\"doc-endnotes\">\n<hr>\n<ol>\n<li id=\"fn:1\">\n<p>Many people say so.&#160;<a href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\">&#x21a9;&#xfe0e;</a></p>\n</li>\n</ol>\n</div>" {
  369. t.Fatalf("Got content:\n%q", cnt)
  370. }
  371. }
  372. func TestPageDatesTerms(t *testing.T) {
  373. t.Parallel()
  374. files := `
  375. -- hugo.toml --
  376. baseURL = "http://example.com/"
  377. -- content/p1.md --
  378. ---
  379. title: p1
  380. date: 2022-01-15
  381. lastMod: 2022-01-16
  382. tags: ["a", "b"]
  383. categories: ["c", "d"]
  384. ---
  385. p1
  386. -- content/p2.md --
  387. ---
  388. title: p2
  389. date: 2017-01-16
  390. lastMod: 2017-01-17
  391. tags: ["a", "c"]
  392. categories: ["c", "e"]
  393. ---
  394. p2
  395. -- layouts/_default/list.html --
  396. {{ .Title }}|Date: {{ .Date.Format "2006-01-02" }}|Lastmod: {{ .Lastmod.Format "2006-01-02" }}|
  397. `
  398. b := Test(t, files)
  399. b.AssertFileContent("public/categories/index.html", "Categories|Date: 2022-01-15|Lastmod: 2022-01-16|")
  400. b.AssertFileContent("public/categories/c/index.html", "C|Date: 2022-01-15|Lastmod: 2022-01-16|")
  401. b.AssertFileContent("public/categories/e/index.html", "E|Date: 2017-01-16|Lastmod: 2017-01-17|")
  402. b.AssertFileContent("public/tags/index.html", "Tags|Date: 2022-01-15|Lastmod: 2022-01-16|")
  403. b.AssertFileContent("public/tags/a/index.html", "A|Date: 2022-01-15|Lastmod: 2022-01-16|")
  404. b.AssertFileContent("public/tags/c/index.html", "C|Date: 2017-01-16|Lastmod: 2017-01-17|")
  405. }
  406. func TestPageDatesAllKinds(t *testing.T) {
  407. t.Parallel()
  408. pageContent := `
  409. ---
  410. title: Page
  411. date: 2017-01-15
  412. tags: ["hugo"]
  413. categories: ["cool stuff"]
  414. ---
  415. `
  416. b := newTestSitesBuilder(t)
  417. b.WithSimpleConfigFile().WithContent("page.md", pageContent)
  418. b.WithContent("blog/page.md", pageContent)
  419. b.CreateSites().Build(BuildCfg{})
  420. b.Assert(len(b.H.Sites), qt.Equals, 1)
  421. s := b.H.Sites[0]
  422. checkDate := func(t time.Time, msg string) {
  423. b.Helper()
  424. b.Assert(t.Year(), qt.Equals, 2017, qt.Commentf(msg))
  425. }
  426. checkDated := func(d resource.Dated, msg string) {
  427. b.Helper()
  428. checkDate(d.Date(), "date: "+msg)
  429. checkDate(d.Lastmod(), "lastmod: "+msg)
  430. }
  431. for _, p := range s.Pages() {
  432. checkDated(p, p.Kind())
  433. }
  434. checkDate(s.Lastmod(), "site")
  435. }
  436. func TestPageDatesSections(t *testing.T) {
  437. t.Parallel()
  438. b := newTestSitesBuilder(t)
  439. b.WithSimpleConfigFile().WithContent("no-index/page.md", `
  440. ---
  441. title: Page
  442. date: 2017-01-15
  443. ---
  444. `, "with-index-no-date/_index.md", `---
  445. title: No Date
  446. ---
  447. `,
  448. // https://github.com/gohugoio/hugo/issues/5854
  449. "with-index-date/_index.md", `---
  450. title: Date
  451. date: 2018-01-15
  452. ---
  453. `, "with-index-date/p1.md", `---
  454. title: Date
  455. date: 2018-01-15
  456. ---
  457. `, "with-index-date/p1.md", `---
  458. title: Date
  459. date: 2018-01-15
  460. ---
  461. `)
  462. for i := 1; i <= 20; i++ {
  463. b.WithContent(fmt.Sprintf("main-section/p%d.md", i), `---
  464. title: Date
  465. date: 2012-01-12
  466. ---
  467. `)
  468. }
  469. b.CreateSites().Build(BuildCfg{})
  470. b.Assert(len(b.H.Sites), qt.Equals, 1)
  471. s := b.H.Sites[0]
  472. checkDate := func(p page.Page, year int) {
  473. b.Assert(p.Date().Year(), qt.Equals, year)
  474. b.Assert(p.Lastmod().Year(), qt.Equals, year)
  475. }
  476. checkDate(s.getPageOldVersion("/"), 2018)
  477. checkDate(s.getPageOldVersion("/no-index"), 2017)
  478. b.Assert(s.getPageOldVersion("/with-index-no-date").Date().IsZero(), qt.Equals, true)
  479. checkDate(s.getPageOldVersion("/with-index-date"), 2018)
  480. b.Assert(s.Site().Lastmod().Year(), qt.Equals, 2018)
  481. }
  482. func TestPageSummary(t *testing.T) {
  483. t.Parallel()
  484. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  485. p := pages[0]
  486. checkPageTitle(t, p, "SimpleWithoutSummaryDelimiter")
  487. // Source is not Asciidoctor- or RST-compatible so don't test them
  488. if ext != "ad" && ext != "rst" {
  489. checkPageContent(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Additional text.</p>\n\n<p>Further text.</p>\n"), ext)
  490. checkPageSummary(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><p>Additional text.</p>"), ext)
  491. }
  492. checkPageType(t, p, "page")
  493. }
  494. testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithoutSummaryDelimiter)
  495. }
  496. func TestPageWithDelimiter(t *testing.T) {
  497. t.Parallel()
  498. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  499. p := pages[0]
  500. checkPageTitle(t, p, "Simple")
  501. checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line</p>\n\n<p>Some more text</p>\n"), ext)
  502. checkPageSummary(t, p, normalizeExpected(ext, "<p>Summary Next Line</p>"), ext)
  503. checkPageType(t, p, "page")
  504. }
  505. testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiter)
  506. }
  507. func TestPageWithSummaryParameter(t *testing.T) {
  508. t.Parallel()
  509. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  510. p := pages[0]
  511. checkPageTitle(t, p, "SimpleWithSummaryParameter")
  512. checkPageContent(t, p, normalizeExpected(ext, "<p>Some text.</p>\n\n<p>Some more text.</p>\n"), ext)
  513. // Summary is not Asciidoctor- or RST-compatible so don't test them
  514. if ext != "ad" && ext != "rst" {
  515. checkPageSummary(t, p, normalizeExpected(ext, "Page with summary parameter and <a href=\"http://www.example.com/\">a link</a>"), ext)
  516. }
  517. checkPageType(t, p, "page")
  518. }
  519. testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryParameter)
  520. }
  521. // Issue #3854
  522. // Also see https://github.com/gohugoio/hugo/issues/3977
  523. func TestPageWithDateFields(t *testing.T) {
  524. c := qt.New(t)
  525. pageWithDate := `---
  526. title: P%d
  527. weight: %d
  528. %s: 2017-10-13
  529. ---
  530. Simple Page With Some Date`
  531. hasDate := func(p page.Page) bool {
  532. return p.Date().Year() == 2017
  533. }
  534. datePage := func(field string, weight int) string {
  535. return fmt.Sprintf(pageWithDate, weight, weight, field)
  536. }
  537. t.Parallel()
  538. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  539. c.Assert(len(pages) > 0, qt.Equals, true)
  540. for _, p := range pages {
  541. c.Assert(hasDate(p), qt.Equals, true)
  542. }
  543. }
  544. fields := []string{"date", "publishdate", "pubdate", "published"}
  545. pageContents := make([]string, len(fields))
  546. for i, field := range fields {
  547. pageContents[i] = datePage(field, i+1)
  548. }
  549. testAllMarkdownEnginesForPages(t, assertFunc, nil, pageContents...)
  550. }
  551. func TestPageRawContent(t *testing.T) {
  552. files := `
  553. -- hugo.toml --
  554. -- content/basic.md --
  555. ---
  556. title: "basic"
  557. ---
  558. **basic**
  559. -- content/empty.md --
  560. ---
  561. title: "empty"
  562. ---
  563. -- layouts/_default/single.html --
  564. |{{ .RawContent }}|
  565. `
  566. b := Test(t, files)
  567. b.AssertFileContent("public/basic/index.html", "|**basic**|")
  568. b.AssertFileContent("public/empty/index.html", "! title")
  569. }
  570. func TestTableOfContents(t *testing.T) {
  571. c := qt.New(t)
  572. cfg, fs := newTestCfg()
  573. configs, err := loadTestConfigFromProvider(cfg)
  574. c.Assert(err, qt.IsNil)
  575. writeSource(t, fs, filepath.Join("content", "tocpage.md"), pageWithToC)
  576. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
  577. c.Assert(len(s.RegularPages()), qt.Equals, 1)
  578. p := s.RegularPages()[0]
  579. checkPageContent(t, p, "<p>For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.</p><h2 id=\"aa\">AA</h2> <p>I have no idea, of course, how long it took me to reach the limit of the plain, but at last I entered the foothills, following a pretty little canyon upward toward the mountains. Beside me frolicked a laughing brooklet, hurrying upon its noisy way down to the silent sea. In its quieter pools I discovered many small fish, of four-or five-pound weight I should imagine. In appearance, except as to size and color, they were not unlike the whale of our own seas. As I watched them playing about I discovered, not only that they suckled their young, but that at intervals they rose to the surface to breathe as well as to feed upon certain grasses and a strange, scarlet lichen which grew upon the rocks just above the water line.</p><h3 id=\"aaa\">AAA</h3> <p>I remember I felt an extraordinary persuasion that I was being played with, that presently, when I was upon the very verge of safety, this mysterious death&ndash;as swift as the passage of light&ndash;would leap after me from the pit about the cylinder and strike me down. ## BB</p><h3 id=\"bbb\">BBB</h3> <p>&ldquo;You&rsquo;re a great Granser,&rdquo; he cried delightedly, &ldquo;always making believe them little marks mean something.&rdquo;</p>")
  580. checkPageTOC(t, p, "<nav id=\"TableOfContents\">\n <ul>\n <li><a href=\"#aa\">AA</a>\n <ul>\n <li><a href=\"#aaa\">AAA</a></li>\n <li><a href=\"#bbb\">BBB</a></li>\n </ul>\n </li>\n </ul>\n</nav>")
  581. }
  582. func TestPageWithMoreTag(t *testing.T) {
  583. t.Parallel()
  584. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  585. p := pages[0]
  586. checkPageTitle(t, p, "Simple")
  587. checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Same Line</p>\n\n<p>Some more text</p>\n"))
  588. checkPageSummary(t, p, normalizeExpected(ext, "<p>Summary Same Line</p>"))
  589. checkPageType(t, p, "page")
  590. }
  591. testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithSummaryDelimiterSameLine)
  592. }
  593. func TestSummaryInFrontMatter(t *testing.T) {
  594. t.Parallel()
  595. Test(t, `
  596. -- hugo.toml --
  597. -- content/simple.md --
  598. ---
  599. title: Simple
  600. summary: "Front **matter** summary"
  601. ---
  602. Simple Page
  603. -- layouts/_default/single.html --
  604. Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
  605. `).AssertFileContent("public/simple/index.html", "Summary: Front <strong>matter</strong> summary|", "Truncated: false")
  606. }
  607. func TestSummaryManualSplit(t *testing.T) {
  608. t.Parallel()
  609. Test(t, `
  610. -- hugo.toml --
  611. -- content/simple.md --
  612. ---
  613. title: Simple
  614. ---
  615. This is **summary**.
  616. <!--more-->
  617. This is **content**.
  618. -- layouts/_default/single.html --
  619. Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
  620. Content: {{ .Content }}|
  621. `).AssertFileContent("public/simple/index.html",
  622. "Summary: <p>This is <strong>summary</strong>.</p>|",
  623. "Truncated: true|",
  624. "Content: <p>This is <strong>summary</strong>.</p>\n<p>This is <strong>content</strong>.</p>|",
  625. )
  626. }
  627. func TestSummaryManualSplitHTML(t *testing.T) {
  628. t.Parallel()
  629. Test(t, `
  630. -- hugo.toml --
  631. -- content/simple.html --
  632. ---
  633. title: Simple
  634. ---
  635. <div>
  636. This is <b>summary</b>.
  637. </div>
  638. <!--more-->
  639. <div>
  640. This is <b>content</b>.
  641. </div>
  642. -- layouts/_default/single.html --
  643. Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
  644. Content: {{ .Content }}|
  645. `).AssertFileContent("public/simple/index.html", "Summary: <div>\nThis is <b>summary</b>.\n</div>\n|Truncated: true|\nContent: \n\n<div>\nThis is <b>content</b>.\n</div>|")
  646. }
  647. func TestSummaryAuto(t *testing.T) {
  648. t.Parallel()
  649. Test(t, `
  650. -- hugo.toml --
  651. summaryLength = 10
  652. -- content/simple.md --
  653. ---
  654. title: Simple
  655. ---
  656. This is **summary**.
  657. This is **more summary**.
  658. This is *even more summary**.
  659. This is **more summary**.
  660. This is **content**.
  661. -- layouts/_default/single.html --
  662. Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
  663. Content: {{ .Content }}|
  664. `).AssertFileContent("public/simple/index.html",
  665. "Summary: <p>This is <strong>summary</strong>.\nThis is <strong>more summary</strong>.\nThis is <em>even more summary</em>*.\nThis is <strong>more summary</strong>.</p>|",
  666. "Truncated: true|",
  667. "Content: <p>This is <strong>summary</strong>.")
  668. }
  669. // #2973
  670. func TestSummaryWithHTMLTagsOnNextLine(t *testing.T) {
  671. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  672. c := qt.New(t)
  673. p := pages[0]
  674. s := string(p.Summary(context.Background()))
  675. c.Assert(s, qt.Contains, "Happy new year everyone!")
  676. c.Assert(s, qt.Not(qt.Contains), "User interface")
  677. }
  678. testAllMarkdownEnginesForPages(t, assertFunc, nil, `---
  679. title: Simple
  680. ---
  681. Happy new year everyone!
  682. Here is the last report for commits in the year 2016. It covers hrev50718-hrev50829.
  683. <!--more-->
  684. <h3>User interface</h3>
  685. `)
  686. }
  687. // Issue 9383
  688. func TestRenderStringForRegularPageTranslations(t *testing.T) {
  689. c := qt.New(t)
  690. b := newTestSitesBuilder(t)
  691. b.WithLogger(loggers.NewDefault())
  692. b.WithConfigFile("toml",
  693. `baseurl = "https://example.org/"
  694. title = "My Site"
  695. defaultContentLanguage = "ru"
  696. defaultContentLanguageInSubdir = true
  697. [languages.ru]
  698. contentDir = 'content/ru'
  699. weight = 1
  700. [languages.en]
  701. weight = 2
  702. contentDir = 'content/en'
  703. [outputs]
  704. home = ["HTML", "JSON"]`)
  705. b.WithTemplates("index.html", `
  706. {{- range .Site.Home.Translations -}}
  707. <p>{{- .RenderString "foo" -}}</p>
  708. {{- end -}}
  709. {{- range .Site.Home.AllTranslations -}}
  710. <p>{{- .RenderString "bar" -}}</p>
  711. {{- end -}}
  712. `, "_default/single.html",
  713. `{{ .Content }}`,
  714. "index.json",
  715. `{"Title": "My Site"}`,
  716. )
  717. b.WithContent(
  718. "ru/a.md",
  719. "",
  720. "en/a.md",
  721. "",
  722. )
  723. err := b.BuildE(BuildCfg{})
  724. c.Assert(err, qt.Equals, nil)
  725. b.AssertFileContent("public/ru/index.html", `
  726. <p>foo</p>
  727. <p>foo</p>
  728. <p>bar</p>
  729. <p>bar</p>
  730. `)
  731. b.AssertFileContent("public/en/index.html", `
  732. <p>foo</p>
  733. <p>foo</p>
  734. <p>bar</p>
  735. <p>bar</p>
  736. `)
  737. }
  738. // Issue 8919
  739. func TestContentProviderWithCustomOutputFormat(t *testing.T) {
  740. b := newTestSitesBuilder(t)
  741. b.WithLogger(loggers.NewDefault())
  742. b.WithConfigFile("toml", `baseURL = 'http://example.org/'
  743. title = 'My New Hugo Site'
  744. timeout = 600000 # ten minutes in case we want to pause and debug
  745. defaultContentLanguage = "en"
  746. [languages]
  747. [languages.en]
  748. title = "Repro"
  749. languageName = "English"
  750. contentDir = "content/en"
  751. [languages.zh_CN]
  752. title = "Repro"
  753. languageName = "简体中文"
  754. contentDir = "content/zh_CN"
  755. [outputFormats]
  756. [outputFormats.metadata]
  757. baseName = "metadata"
  758. mediaType = "text/html"
  759. isPlainText = true
  760. notAlternative = true
  761. [outputs]
  762. home = ["HTML", "metadata"]`)
  763. b.WithTemplates("home.metadata.html", `<h2>Translations metadata</h2>
  764. <ul>
  765. {{ $p := .Page }}
  766. {{ range $p.Translations}}
  767. <li>Title: {{ .Title }}, {{ .Summary }}</li>
  768. <li>Content: {{ .Content }}</li>
  769. <li>Plain: {{ .Plain }}</li>
  770. <li>PlainWords: {{ .PlainWords }}</li>
  771. <li>Summary: {{ .Summary }}</li>
  772. <li>Truncated: {{ .Truncated }}</li>
  773. <li>FuzzyWordCount: {{ .FuzzyWordCount }}</li>
  774. <li>ReadingTime: {{ .ReadingTime }}</li>
  775. <li>Len: {{ .Len }}</li>
  776. {{ end }}
  777. </ul>`)
  778. b.WithTemplates("_default/baseof.html", `<html>
  779. <body>
  780. {{ block "main" . }}{{ end }}
  781. </body>
  782. </html>`)
  783. b.WithTemplates("_default/home.html", `{{ define "main" }}
  784. <h2>Translations</h2>
  785. <ul>
  786. {{ $p := .Page }}
  787. {{ range $p.Translations}}
  788. <li>Title: {{ .Title }}, {{ .Summary }}</li>
  789. <li>Content: {{ .Content }}</li>
  790. <li>Plain: {{ .Plain }}</li>
  791. <li>PlainWords: {{ .PlainWords }}</li>
  792. <li>Summary: {{ .Summary }}</li>
  793. <li>Truncated: {{ .Truncated }}</li>
  794. <li>FuzzyWordCount: {{ .FuzzyWordCount }}</li>
  795. <li>ReadingTime: {{ .ReadingTime }}</li>
  796. <li>Len: {{ .Len }}</li>
  797. {{ end }}
  798. </ul>
  799. {{ end }}`)
  800. b.WithContent("en/_index.md", `---
  801. title: Title (en)
  802. summary: Summary (en)
  803. ---
  804. Here is some content.
  805. `)
  806. b.WithContent("zh_CN/_index.md", `---
  807. title: Title (zh)
  808. summary: Summary (zh)
  809. ---
  810. 这是一些内容
  811. `)
  812. b.Build(BuildCfg{})
  813. b.AssertFileContent("public/index.html", `<html>
  814. <body>
  815. <h2>Translations</h2>
  816. <ul>
  817. <li>Title: Title (zh), Summary (zh)</li>
  818. <li>Content: <p>这是一些内容</p>
  819. </li>
  820. <li>Plain: 这是一些内容
  821. </li>
  822. <li>PlainWords: [这是一些内容]</li>
  823. <li>Summary: Summary (zh)</li>
  824. <li>Truncated: false</li>
  825. <li>FuzzyWordCount: 100</li>
  826. <li>ReadingTime: 1</li>
  827. <li>Len: 26</li>
  828. </ul>
  829. </body>
  830. </html>`)
  831. b.AssertFileContent("public/metadata.html", `<h2>Translations metadata</h2>
  832. <ul>
  833. <li>Title: Title (zh), Summary (zh)</li>
  834. <li>Content: <p>这是一些内容</p>
  835. </li>
  836. <li>Plain: 这是一些内容
  837. </li>
  838. <li>PlainWords: [这是一些内容]</li>
  839. <li>Summary: Summary (zh)</li>
  840. <li>Truncated: false</li>
  841. <li>FuzzyWordCount: 100</li>
  842. <li>ReadingTime: 1</li>
  843. <li>Len: 26</li>
  844. </ul>`)
  845. b.AssertFileContent("public/zh_cn/index.html", `<html>
  846. <body>
  847. <h2>Translations</h2>
  848. <ul>
  849. <li>Title: Title (en), Summary (en)</li>
  850. <li>Content: <p>Here is some content.</p>
  851. </li>
  852. <li>Plain: Here is some content.
  853. </li>
  854. <li>PlainWords: [Here is some content.]</li>
  855. <li>Summary: Summary (en)</li>
  856. <li>Truncated: false</li>
  857. <li>FuzzyWordCount: 100</li>
  858. <li>ReadingTime: 1</li>
  859. <li>Len: 29</li>
  860. </ul>
  861. </body>
  862. </html>`)
  863. b.AssertFileContent("public/zh_cn/metadata.html", `<h2>Translations metadata</h2>
  864. <ul>
  865. <li>Title: Title (en), Summary (en)</li>
  866. <li>Content: <p>Here is some content.</p>
  867. </li>
  868. <li>Plain: Here is some content.
  869. </li>
  870. <li>PlainWords: [Here is some content.]</li>
  871. <li>Summary: Summary (en)</li>
  872. <li>Truncated: false</li>
  873. <li>FuzzyWordCount: 100</li>
  874. <li>ReadingTime: 1</li>
  875. <li>Len: 29</li>
  876. </ul>`)
  877. }
  878. func TestPageWithDate(t *testing.T) {
  879. t.Parallel()
  880. c := qt.New(t)
  881. cfg, fs := newTestCfg()
  882. configs, err := loadTestConfigFromProvider(cfg)
  883. c.Assert(err, qt.IsNil)
  884. writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageRFC3339Date)
  885. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
  886. c.Assert(len(s.RegularPages()), qt.Equals, 1)
  887. p := s.RegularPages()[0]
  888. d, _ := time.Parse(time.RFC3339, "2013-05-17T16:59:30Z")
  889. checkPageDate(t, p, d)
  890. }
  891. func TestPageWithFrontMatterConfig(t *testing.T) {
  892. for _, dateHandler := range []string{":filename", ":fileModTime"} {
  893. dateHandler := dateHandler
  894. t.Run(fmt.Sprintf("dateHandler=%q", dateHandler), func(t *testing.T) {
  895. t.Parallel()
  896. c := qt.New(t)
  897. cfg, fs := newTestCfg()
  898. pageTemplate := `
  899. ---
  900. title: Page
  901. weight: %d
  902. lastMod: 2018-02-28
  903. %s
  904. ---
  905. Content
  906. `
  907. cfg.Set("frontmatter", map[string]any{
  908. "date": []string{dateHandler, "date"},
  909. })
  910. configs, err := loadTestConfigFromProvider(cfg)
  911. c.Assert(err, qt.IsNil)
  912. c1 := filepath.Join("content", "section", "2012-02-21-noslug.md")
  913. c2 := filepath.Join("content", "section", "2012-02-22-slug.md")
  914. writeSource(t, fs, c1, fmt.Sprintf(pageTemplate, 1, ""))
  915. writeSource(t, fs, c2, fmt.Sprintf(pageTemplate, 2, "slug: aslug"))
  916. c1fi, err := fs.Source.Stat(c1)
  917. c.Assert(err, qt.IsNil)
  918. c2fi, err := fs.Source.Stat(c2)
  919. c.Assert(err, qt.IsNil)
  920. b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{Fs: fs, Configs: configs}).WithNothingAdded()
  921. b.Build(BuildCfg{SkipRender: true})
  922. s := b.H.Sites[0]
  923. c.Assert(len(s.RegularPages()), qt.Equals, 2)
  924. noSlug := s.RegularPages()[0]
  925. slug := s.RegularPages()[1]
  926. c.Assert(noSlug.Lastmod().Day(), qt.Equals, 28)
  927. switch strings.ToLower(dateHandler) {
  928. case ":filename":
  929. c.Assert(noSlug.Date().IsZero(), qt.Equals, false)
  930. c.Assert(slug.Date().IsZero(), qt.Equals, false)
  931. c.Assert(noSlug.Date().Year(), qt.Equals, 2012)
  932. c.Assert(slug.Date().Year(), qt.Equals, 2012)
  933. c.Assert(noSlug.Slug(), qt.Equals, "noslug")
  934. c.Assert(slug.Slug(), qt.Equals, "aslug")
  935. case ":filemodtime":
  936. c.Assert(noSlug.Date().Year(), qt.Equals, c1fi.ModTime().Year())
  937. c.Assert(slug.Date().Year(), qt.Equals, c2fi.ModTime().Year())
  938. fallthrough
  939. default:
  940. c.Assert(noSlug.Slug(), qt.Equals, "")
  941. c.Assert(slug.Slug(), qt.Equals, "aslug")
  942. }
  943. })
  944. }
  945. }
  946. func TestWordCountWithAllCJKRunesWithoutHasCJKLanguage(t *testing.T) {
  947. t.Parallel()
  948. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  949. p := pages[0]
  950. if p.WordCount(context.Background()) != 8 {
  951. t.Fatalf("[%s] incorrect word count. expected %v, got %v", ext, 8, p.WordCount(context.Background()))
  952. }
  953. }
  954. testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithAllCJKRunes)
  955. }
  956. func TestWordCountWithAllCJKRunesHasCJKLanguage(t *testing.T) {
  957. t.Parallel()
  958. settings := map[string]any{"hasCJKLanguage": true}
  959. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  960. p := pages[0]
  961. if p.WordCount(context.Background()) != 15 {
  962. t.Fatalf("[%s] incorrect word count, expected %v, got %v", ext, 15, p.WordCount(context.Background()))
  963. }
  964. }
  965. testAllMarkdownEnginesForPages(t, assertFunc, settings, simplePageWithAllCJKRunes)
  966. }
  967. func TestWordCountWithMainEnglishWithCJKRunes(t *testing.T) {
  968. t.Parallel()
  969. settings := map[string]any{"hasCJKLanguage": true}
  970. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  971. p := pages[0]
  972. if p.WordCount(context.Background()) != 74 {
  973. t.Fatalf("[%s] incorrect word count, expected %v, got %v", ext, 74, p.WordCount(context.Background()))
  974. }
  975. }
  976. testAllMarkdownEnginesForPages(t, assertFunc, settings, simplePageWithMainEnglishWithCJKRunes)
  977. }
  978. func TestWordCountWithIsCJKLanguageFalse(t *testing.T) {
  979. t.Parallel()
  980. settings := map[string]any{
  981. "hasCJKLanguage": true,
  982. }
  983. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  984. p := pages[0]
  985. if p.WordCount(context.Background()) != 75 {
  986. t.Fatalf("[%s] incorrect word count for content '%s'. expected %v, got %v", ext, p.Plain(context.Background()), 74, p.WordCount(context.Background()))
  987. }
  988. }
  989. testAllMarkdownEnginesForPages(t, assertFunc, settings, simplePageWithIsCJKLanguageFalse)
  990. }
  991. func TestWordCount(t *testing.T) {
  992. t.Parallel()
  993. assertFunc := func(t *testing.T, ext string, pages page.Pages) {
  994. p := pages[0]
  995. if p.WordCount(context.Background()) != 483 {
  996. t.Fatalf("[%s] incorrect word count. expected %v, got %v", ext, 483, p.WordCount(context.Background()))
  997. }
  998. if p.FuzzyWordCount(context.Background()) != 500 {
  999. t.Fatalf("[%s] incorrect word count. expected %v, got %v", ext, 500, p.FuzzyWordCount(context.Background()))
  1000. }
  1001. if p.ReadingTime(context.Background()) != 3 {
  1002. t.Fatalf("[%s] incorrect min read. expected %v, got %v", ext, 3, p.ReadingTime(context.Background()))
  1003. }
  1004. }
  1005. testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithLongContent)
  1006. }
  1007. func TestPagePaths(t *testing.T) {
  1008. t.Parallel()
  1009. c := qt.New(t)
  1010. siteParmalinksSetting := map[string]string{
  1011. "post": ":year/:month/:day/:title/",
  1012. }
  1013. tests := []struct {
  1014. content string
  1015. path string
  1016. hasPermalink bool
  1017. expected string
  1018. }{
  1019. {simplePage, "post/x.md", false, "post/x.html"},
  1020. {simplePageWithURL, "post/x.md", false, "simple/url/index.html"},
  1021. {simplePageWithSlug, "post/x.md", false, "post/simple-slug.html"},
  1022. {simplePageWithDate, "post/x.md", true, "2013/10/15/simple/index.html"},
  1023. {UTF8Page, "post/x.md", false, "post/x.html"},
  1024. {UTF8PageWithURL, "post/x.md", false, "ラーメン/url/index.html"},
  1025. {UTF8PageWithSlug, "post/x.md", false, "post/ラーメン-slug.html"},
  1026. {UTF8PageWithDate, "post/x.md", true, "2013/10/15/ラーメン/index.html"},
  1027. }
  1028. for _, test := range tests {
  1029. cfg, fs := newTestCfg()
  1030. configs, err := loadTestConfigFromProvider(cfg)
  1031. c.Assert(err, qt.IsNil)
  1032. if test.hasPermalink {
  1033. cfg.Set("permalinks", siteParmalinksSetting)
  1034. }
  1035. writeSource(t, fs, filepath.Join("content", filepath.FromSlash(test.path)), test.content)
  1036. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
  1037. c.Assert(len(s.RegularPages()), qt.Equals, 1)
  1038. }
  1039. }
  1040. func TestTranslationKey(t *testing.T) {
  1041. files := `
  1042. -- hugo.toml --
  1043. disableKinds = ["taxonomy", "term"]
  1044. defaultContentLanguage = "en"
  1045. defaultContentLanguageInSubdir = true
  1046. [languages]
  1047. [languages.en]
  1048. weight = 1
  1049. [languages.nn]
  1050. weight = 2
  1051. -- content/sect/p1.en.md --
  1052. ---
  1053. translationkey: "adfasdf"
  1054. title: "p1 en"
  1055. ---
  1056. -- content/sect/p1.nn.md --
  1057. ---
  1058. translationkey: "adfasdf"
  1059. title: "p1 nn"
  1060. ---
  1061. -- layouts/_default/single.html --
  1062. Title: {{ .Title }}|TranslationKey: {{ .TranslationKey }}|
  1063. Translations: {{ range .Translations }}{{ .Language.Lang }}|{{ end }}|
  1064. AllTranslations: {{ range .AllTranslations }}{{ .Language.Lang }}|{{ end }}|
  1065. `
  1066. b := Test(t, files)
  1067. b.AssertFileContent("public/en/sect/p1/index.html",
  1068. "TranslationKey: adfasdf|",
  1069. "AllTranslations: en|nn||",
  1070. "Translations: nn||",
  1071. )
  1072. b.AssertFileContent("public/nn/sect/p1/index.html",
  1073. "TranslationKey: adfasdf|",
  1074. "Translations: en||",
  1075. "AllTranslations: en|nn||",
  1076. )
  1077. }
  1078. func TestTranslationKeyTermPages(t *testing.T) {
  1079. t.Parallel()
  1080. files := `
  1081. -- hugo.toml --
  1082. disableKinds = ['home','rss','section','sitemap','taxonomy']
  1083. defaultContentLanguage = 'en'
  1084. defaultContentLanguageInSubdir = true
  1085. [languages.en]
  1086. weight = 1
  1087. [languages.pt]
  1088. weight = 2
  1089. [taxonomies]
  1090. category = 'categories'
  1091. -- layouts/_default/list.html --
  1092. {{ .IsTranslated }}|{{ range .Translations }}{{ .RelPermalink }}|{{ end }}
  1093. -- layouts/_default/single.html --
  1094. {{ .Title }}|
  1095. -- content/p1.en.md --
  1096. ---
  1097. title: p1 (en)
  1098. categories: [music]
  1099. ---
  1100. -- content/p1.pt.md --
  1101. ---
  1102. title: p1 (pt)
  1103. categories: [música]
  1104. ---
  1105. -- content/categories/music/_index.en.md --
  1106. ---
  1107. title: music
  1108. translationKey: foo
  1109. ---
  1110. -- content/categories/música/_index.pt.md --
  1111. ---
  1112. title: música
  1113. translationKey: foo
  1114. ---
  1115. `
  1116. b := Test(t, files)
  1117. b.AssertFileContent("public/en/categories/music/index.html", "true|/pt/categories/m%C3%BAsica/|")
  1118. b.AssertFileContent("public/pt/categories/música/index.html", "true|/en/categories/music/|")
  1119. }
  1120. // Issue #11540.
  1121. func TestTranslationKeyResourceSharing(t *testing.T) {
  1122. files := `
  1123. -- hugo.toml --
  1124. disableKinds = ["taxonomy", "term"]
  1125. defaultContentLanguage = "en"
  1126. defaultContentLanguageInSubdir = true
  1127. [languages]
  1128. [languages.en]
  1129. weight = 1
  1130. [languages.nn]
  1131. weight = 2
  1132. -- content/sect/mybundle_en/index.en.md --
  1133. ---
  1134. translationkey: "adfasdf"
  1135. title: "mybundle en"
  1136. ---
  1137. -- content/sect/mybundle_en/f1.txt --
  1138. f1.en
  1139. -- content/sect/mybundle_en/f2.txt --
  1140. f2.en
  1141. -- content/sect/mybundle_nn/index.nn.md --
  1142. ---
  1143. translationkey: "adfasdf"
  1144. title: "mybundle nn"
  1145. ---
  1146. -- content/sect/mybundle_nn/f2.nn.txt --
  1147. f2.nn
  1148. -- layouts/_default/single.html --
  1149. Title: {{ .Title }}|TranslationKey: {{ .TranslationKey }}|
  1150. Resources: {{ range .Resources }}{{ .RelPermalink }}|{{ .Content }}|{{ end }}|
  1151. `
  1152. b := Test(t, files)
  1153. b.AssertFileContent("public/en/sect/mybundle_en/index.html",
  1154. "TranslationKey: adfasdf|",
  1155. "Resources: /en/sect/mybundle_en/f1.txt|f1.en|/en/sect/mybundle_en/f2.txt|f2.en||",
  1156. )
  1157. b.AssertFileContent("public/nn/sect/mybundle_nn/index.html",
  1158. "TranslationKey: adfasdf|",
  1159. "Title: mybundle nn|TranslationKey: adfasdf|\nResources: /en/sect/mybundle_en/f1.txt|f1.en|/nn/sect/mybundle_nn/f2.nn.txt|f2.nn||",
  1160. )
  1161. }
  1162. func TestChompBOM(t *testing.T) {
  1163. t.Parallel()
  1164. c := qt.New(t)
  1165. const utf8BOM = "\xef\xbb\xbf"
  1166. cfg, fs := newTestCfg()
  1167. configs, err := loadTestConfigFromProvider(cfg)
  1168. c.Assert(err, qt.IsNil)
  1169. writeSource(t, fs, filepath.Join("content", "simple.md"), utf8BOM+simplePage)
  1170. s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
  1171. c.Assert(len(s.RegularPages()), qt.Equals, 1)
  1172. p := s.RegularPages()[0]
  1173. checkPageTitle(t, p, "Simple")
  1174. }
  1175. // https://github.com/gohugoio/hugo/issues/5381
  1176. func TestPageManualSummary(t *testing.T) {
  1177. b := newTestSitesBuilder(t)
  1178. b.WithSimpleConfigFile()
  1179. b.WithContent("page-md-shortcode.md", `---
  1180. title: "Hugo"
  1181. ---
  1182. This is a {{< sc >}}.
  1183. <!--more-->
  1184. Content.
  1185. `)
  1186. // https://github.com/gohugoio/hugo/issues/5464
  1187. b.WithContent("page-md-only-shortcode.md", `---
  1188. title: "Hugo"
  1189. ---
  1190. {{< sc >}}
  1191. <!--more-->
  1192. {{< sc >}}
  1193. `)
  1194. b.WithContent("page-md-shortcode-same-line.md", `---
  1195. title: "Hugo"
  1196. ---
  1197. This is a {{< sc >}}<!--more-->Same line.
  1198. `)
  1199. b.WithContent("page-md-shortcode-same-line-after.md", `---
  1200. title: "Hugo"
  1201. ---
  1202. Summary<!--more-->{{< sc >}}
  1203. `)
  1204. b.WithContent("page-org-shortcode.org", `#+TITLE: T1
  1205. #+AUTHOR: A1
  1206. #+DESCRIPTION: D1
  1207. This is a {{< sc >}}.
  1208. # more
  1209. Content.
  1210. `)
  1211. b.WithContent("page-org-variant1.org", `#+TITLE: T1
  1212. Summary.
  1213. # more
  1214. Content.
  1215. `)
  1216. b.WithTemplatesAdded("layouts/shortcodes/sc.html", "a shortcode")
  1217. b.WithTemplatesAdded("layouts/_default/single.html", `
  1218. SUMMARY:{{ .Summary }}:END
  1219. --------------------------
  1220. CONTENT:{{ .Content }}
  1221. `)
  1222. b.CreateSites().Build(BuildCfg{})
  1223. b.AssertFileContent("public/page-md-shortcode/index.html",
  1224. "SUMMARY:<p>This is a a shortcode.</p>:END",
  1225. "CONTENT:<p>This is a a shortcode.</p>\n\n<p>Content.</p>\n",
  1226. )
  1227. b.AssertFileContent("public/page-md-shortcode-same-line/index.html",
  1228. "SUMMARY:<p>This is a a shortcode</p>:END",
  1229. "CONTENT:<p>This is a a shortcode</p>\n\n<p>Same line.</p>\n",
  1230. )
  1231. b.AssertFileContent("public/page-md-shortcode-same-line-after/index.html",
  1232. "SUMMARY:<p>Summary</p>:END",
  1233. "CONTENT:<p>Summary</p>\n\na shortcode",
  1234. )
  1235. b.AssertFileContent("public/page-org-shortcode/index.html",
  1236. "SUMMARY:<p>\nThis is a a shortcode.\n</p>:END",
  1237. "CONTENT:<p>\nThis is a a shortcode.\n</p>\n<p>\nContent.\t\n</p>\n",
  1238. )
  1239. b.AssertFileContent("public/page-org-variant1/index.html",
  1240. "SUMMARY:<p>\nSummary.\n</p>:END",
  1241. "CONTENT:<p>\nSummary.\n</p>\n<p>\nContent.\t\n</p>\n",
  1242. )
  1243. b.AssertFileContent("public/page-md-only-shortcode/index.html",
  1244. "SUMMARY:a shortcode:END",
  1245. "CONTENT:a shortcode\n\na shortcode\n",
  1246. )
  1247. }
  1248. func TestHomePageWithNoTitle(t *testing.T) {
  1249. b := newTestSitesBuilder(t).WithConfigFile("toml", `
  1250. title = "Site Title"
  1251. `)
  1252. b.WithTemplatesAdded("index.html", "Title|{{ with .Title }}{{ . }}{{ end }}|")
  1253. b.WithContent("_index.md", `---
  1254. description: "No title for you!"
  1255. ---
  1256. Content.
  1257. `)
  1258. b.Build(BuildCfg{})
  1259. b.AssertFileContent("public/index.html", "Title||")
  1260. }
  1261. func TestShouldBuild(t *testing.T) {
  1262. past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
  1263. future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC)
  1264. zero := time.Time{}
  1265. publishSettings := []struct {
  1266. buildFuture bool
  1267. buildExpired bool
  1268. buildDrafts bool
  1269. draft bool
  1270. publishDate time.Time
  1271. expiryDate time.Time
  1272. out bool
  1273. }{
  1274. // publishDate and expiryDate
  1275. {false, false, false, false, zero, zero, true},
  1276. {false, false, false, false, zero, future, true},
  1277. {false, false, false, false, past, zero, true},
  1278. {false, false, false, false, past, future, true},
  1279. {false, false, false, false, past, past, false},
  1280. {false, false, false, false, future, future, false},
  1281. {false, false, false, false, future, past, false},
  1282. // buildFuture and buildExpired
  1283. {false, true, false, false, past, past, true},
  1284. {true, true, false, false, past, past, true},
  1285. {true, false, false, false, past, past, false},
  1286. {true, false, false, false, future, future, true},
  1287. {true, true, false, false, future, future, true},
  1288. {false, true, false, false, future, past, false},
  1289. // buildDrafts and draft
  1290. {true, true, false, true, past, future, false},
  1291. {true, true, true, true, past, future, true},
  1292. {true, true, true, true, past, future, true},
  1293. }
  1294. for _, ps := range publishSettings {
  1295. s := shouldBuild(ps.buildFuture, ps.buildExpired, ps.buildDrafts, ps.draft,
  1296. ps.publishDate, ps.expiryDate)
  1297. if s != ps.out {
  1298. t.Errorf("AssertShouldBuild unexpected output with params: %+v", ps)
  1299. }
  1300. }
  1301. }
  1302. func TestShouldBuildWithClock(t *testing.T) {
  1303. htime.Clock = clocks.Start(time.Date(2021, 11, 17, 20, 34, 58, 651387237, time.UTC))
  1304. t.Cleanup(func() { htime.Clock = clocks.System() })
  1305. past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
  1306. future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC)
  1307. zero := time.Time{}
  1308. publishSettings := []struct {
  1309. buildFuture bool
  1310. buildExpired bool
  1311. buildDrafts bool
  1312. draft bool
  1313. publishDate time.Time
  1314. expiryDate time.Time
  1315. out bool
  1316. }{
  1317. // publishDate and expiryDate
  1318. {false, false, false, false, zero, zero, true},
  1319. {false, false, false, false, zero, future, true},
  1320. {false, false, false, false, past, zero, true},
  1321. {false, false, false, false, past, future, true},
  1322. {false, false, false, false, past, past, false},
  1323. {false, false, false, false, future, future, false},
  1324. {false, false, false, false, future, past, false},
  1325. // buildFuture and buildExpired
  1326. {false, true, false, false, past, past, true},
  1327. {true, true, false, false, past, past, true},
  1328. {true, false, false, false, past, past, false},
  1329. {true, false, false, false, future, future, true},
  1330. {true, true, false, false, future, future, true},
  1331. {false, true, false, false, future, past, false},
  1332. // buildDrafts and draft
  1333. {true, true, false, true, past, future, false},
  1334. {true, true, true, true, past, future, true},
  1335. {true, true, true, true, past, future, true},
  1336. }
  1337. for _, ps := range publishSettings {
  1338. s := shouldBuild(ps.buildFuture, ps.buildExpired, ps.buildDrafts, ps.draft,
  1339. ps.publishDate, ps.expiryDate)
  1340. if s != ps.out {
  1341. t.Errorf("AssertShouldBuildWithClock unexpected output with params: %+v", ps)
  1342. }
  1343. }
  1344. }
  1345. // See https://github.com/gohugoio/hugo/issues/9171
  1346. // We redefined disablePathToLower in v0.121.0.
  1347. func TestPagePathDisablePathToLower(t *testing.T) {
  1348. files := `
  1349. -- hugo.toml --
  1350. baseURL = "http://example.com"
  1351. disablePathToLower = true
  1352. [permalinks]
  1353. sect2 = "/:section/:filename/"
  1354. sect3 = "/:section/:title/"
  1355. -- content/sect/p1.md --
  1356. ---
  1357. title: "Page1"
  1358. ---
  1359. p1.
  1360. -- content/sect/p2.md --
  1361. ---
  1362. title: "Page2"
  1363. slug: "PaGe2"
  1364. ---
  1365. p2.
  1366. -- content/sect2/PaGe3.md --
  1367. ---
  1368. title: "Page3"
  1369. ---
  1370. -- content/seCt3/p4.md --
  1371. ---
  1372. title: "Pag.E4"
  1373. slug: "PaGe4"
  1374. ---
  1375. p4.
  1376. -- layouts/_default/single.html --
  1377. Single: {{ .Title}}|{{ .RelPermalink }}|{{ .Path }}|
  1378. `
  1379. b := Test(t, files)
  1380. b.AssertFileContent("public/sect/p1/index.html", "Single: Page1|/sect/p1/|/sect/p1")
  1381. b.AssertFileContent("public/sect/PaGe2/index.html", "Single: Page2|/sect/PaGe2/|/sect/p2")
  1382. b.AssertFileContent("public/sect2/PaGe3/index.html", "Single: Page3|/sect2/PaGe3/|/sect2/page3|")
  1383. b.AssertFileContent("public/sect3/Pag.E4/index.html", "Single: Pag.E4|/sect3/Pag.E4/|/sect3/p4|")
  1384. }
  1385. func TestScratch(t *testing.T) {
  1386. t.Parallel()
  1387. b := newTestSitesBuilder(t)
  1388. b.WithSimpleConfigFile().WithTemplatesAdded("index.html", `
  1389. {{ .Scratch.Set "b" "bv" }}
  1390. B: {{ .Scratch.Get "b" }}
  1391. `,
  1392. "shortcodes/scratch.html", `
  1393. {{ .Scratch.Set "c" "cv" }}
  1394. C: {{ .Scratch.Get "c" }}
  1395. `,
  1396. )
  1397. b.WithContentAdded("scratchme.md", `
  1398. ---
  1399. title: Scratch Me!
  1400. ---
  1401. {{< scratch >}}
  1402. `)
  1403. b.Build(BuildCfg{})
  1404. b.AssertFileContent("public/index.html", "B: bv")
  1405. b.AssertFileContent("public/scratchme/index.html", "C: cv")
  1406. }
  1407. // Issue 13016.
  1408. func TestScratchAliasToStore(t *testing.T) {
  1409. t.Parallel()
  1410. files := `
  1411. -- hugo.toml --
  1412. disableKinds = ["taxonomy", "term", "page", "section"]
  1413. disableLiveReload = true
  1414. -- layouts/index.html --
  1415. {{ .Scratch.Set "a" "b" }}
  1416. {{ .Store.Set "c" "d" }}
  1417. .Scratch eq .Store: {{ eq .Scratch .Store }}
  1418. a: {{ .Store.Get "a" }}
  1419. c: {{ .Scratch.Get "c" }}
  1420. `
  1421. b := Test(t, files)
  1422. b.AssertFileContent("public/index.html",
  1423. ".Scratch eq .Store: true",
  1424. "a: b",
  1425. "c: d",
  1426. )
  1427. }
  1428. func TestPageParam(t *testing.T) {
  1429. t.Parallel()
  1430. b := newTestSitesBuilder(t).WithConfigFile("toml", `
  1431. baseURL = "https://example.org"
  1432. [params]
  1433. [params.author]
  1434. name = "Kurt Vonnegut"
  1435. `)
  1436. b.WithTemplatesAdded("index.html", `
  1437. {{ $withParam := .Site.GetPage "withparam" }}
  1438. {{ $noParam := .Site.GetPage "noparam" }}
  1439. {{ $withStringParam := .Site.GetPage "withstringparam" }}
  1440. Author page: {{ $withParam.Param "author.name" }}
  1441. Author name page string: {{ $withStringParam.Param "author.name" }}|
  1442. Author page string: {{ $withStringParam.Param "author" }}|
  1443. Author site config: {{ $noParam.Param "author.name" }}
  1444. `,
  1445. )
  1446. b.WithContent("withparam.md", `
  1447. +++
  1448. title = "With Param!"
  1449. [author]
  1450. name = "Ernest Miller Hemingway"
  1451. +++
  1452. `,
  1453. "noparam.md", `
  1454. ---
  1455. title: "No Param!"
  1456. ---
  1457. `, "withstringparam.md", `
  1458. +++
  1459. title = "With string Param!"
  1460. author = "Jo Nesbø"
  1461. +++
  1462. `)
  1463. b.Build(BuildCfg{})
  1464. b.AssertFileContent("public/index.html",
  1465. "Author page: Ernest Miller Hemingway",
  1466. "Author name page string: Kurt Vonnegut|",
  1467. "Author page string: Jo Nesbø|",
  1468. "Author site config: Kurt Vonnegut")
  1469. }
  1470. func TestGoldmark(t *testing.T) {
  1471. t.Parallel()
  1472. b := newTestSitesBuilder(t).WithConfigFile("toml", `
  1473. baseURL = "https://example.org"
  1474. [markup]
  1475. defaultMarkdownHandler="goldmark"
  1476. [markup.goldmark]
  1477. [markup.goldmark.renderer]
  1478. unsafe = false
  1479. [markup.highlight]
  1480. noClasses=false
  1481. `)
  1482. b.WithTemplatesAdded("_default/single.html", `
  1483. Title: {{ .Title }}
  1484. ToC: {{ .TableOfContents }}
  1485. Content: {{ .Content }}
  1486. `, "shortcodes/t.html", `T-SHORT`, "shortcodes/s.html", `## Code
  1487. {{ .Inner }}
  1488. `)
  1489. content := `
  1490. +++
  1491. title = "A Page!"
  1492. +++
  1493. ## Shortcode {{% t %}} in header
  1494. ## Code Fense in Shortcode
  1495. {{% s %}}
  1496. $$$bash {hl_lines=[1]}
  1497. SHORT
  1498. $$$
  1499. {{% /s %}}
  1500. ## Code Fence
  1501. $$$bash {hl_lines=[1]}
  1502. MARKDOWN
  1503. $$$
  1504. Link with URL as text
  1505. [https://google.com](https://google.com)
  1506. `
  1507. content = strings.ReplaceAll(content, "$$$", "```")
  1508. b.WithContent("page.md", content)
  1509. b.Build(BuildCfg{})
  1510. b.AssertFileContent("public/page/index.html",
  1511. `<nav id="TableOfContents">
  1512. <li><a href="#shortcode-t-short-in-header">Shortcode T-SHORT in header</a></li>
  1513. <code class="language-bash" data-lang="bash"><span class="line hl"><span class="cl">SHORT
  1514. <code class="language-bash" data-lang="bash"><span class="line hl"><span class="cl">MARKDOWN
  1515. <p><a href="https://google.com">https://google.com</a></p>
  1516. `)
  1517. }
  1518. func TestPageHashString(t *testing.T) {
  1519. files := `
  1520. -- config.toml --
  1521. baseURL = "https://example.org"
  1522. [languages]
  1523. [languages.en]
  1524. weight = 1
  1525. title = "English"
  1526. [languages.no]
  1527. weight = 2
  1528. title = "Norsk"
  1529. -- content/p1.md --
  1530. ---
  1531. title: "p1"
  1532. ---
  1533. -- content/p2.md --
  1534. ---
  1535. title: "p2"
  1536. ---
  1537. `
  1538. b := NewIntegrationTestBuilder(IntegrationTestConfig{
  1539. T: t,
  1540. TxtarString: files,
  1541. }).Build()
  1542. p1 := b.H.Sites[0].RegularPages()[0]
  1543. p2 := b.H.Sites[0].RegularPages()[1]
  1544. sites := p1.Sites()
  1545. b.Assert(p1, qt.Not(qt.Equals), p2)
  1546. b.Assert(hashing.HashString(p1), qt.Not(qt.Equals), hashing.HashString(p2))
  1547. b.Assert(hashing.HashString(sites[0]), qt.Not(qt.Equals), hashing.HashString(sites[1]))
  1548. }
  1549. // Issue #11243
  1550. func TestRenderWithoutArgument(t *testing.T) {
  1551. t.Parallel()
  1552. files := `
  1553. -- hugo.toml --
  1554. -- layouts/index.html --
  1555. {{ .Render }}
  1556. `
  1557. b, err := NewIntegrationTestBuilder(
  1558. IntegrationTestConfig{
  1559. T: t,
  1560. TxtarString: files,
  1561. },
  1562. ).BuildE()
  1563. b.Assert(err, qt.IsNotNil)
  1564. }
  1565. // Issue #13021
  1566. func TestAllStores(t *testing.T) {
  1567. t.Parallel()
  1568. files := `
  1569. -- hugo.toml --
  1570. disableKinds = ["taxonomy", "term", "page", "section"]
  1571. disableLiveReload = true
  1572. -- content/_index.md --
  1573. ---
  1574. title: "Home"
  1575. ---
  1576. {{< s >}}
  1577. -- layouts/shortcodes/s.html --
  1578. {{ if not (.Store.Get "Shortcode") }}{{ .Store.Set "Shortcode" (printf "sh-%s" $.Page.Title) }}{{ end }}
  1579. Shortcode: {{ .Store.Get "Shortcode" }}|
  1580. -- layouts/index.html --
  1581. {{ .Content }}
  1582. {{ if not (.Store.Get "Page") }}{{ .Store.Set "Page" (printf "p-%s" $.Title) }}{{ end }}
  1583. {{ if not (hugo.Store.Get "Hugo") }}{{ hugo.Store.Set "Hugo" (printf "h-%s" $.Title) }}{{ end }}
  1584. {{ if not (site.Store.Get "Site") }}{{ site.Store.Set "Site" (printf "s-%s" $.Title) }}{{ end }}
  1585. Page: {{ .Store.Get "Page" }}|
  1586. Hugo: {{ hugo.Store.Get "Hugo" }}|
  1587. Site: {{ site.Store.Get "Site" }}|
  1588. `
  1589. b := TestRunning(t, files)
  1590. b.AssertFileContent("public/index.html",
  1591. `
  1592. Shortcode: sh-Home|
  1593. Page: p-Home|
  1594. Site: s-Home|
  1595. Hugo: h-Home|
  1596. `,
  1597. )
  1598. b.EditFileReplaceAll("content/_index.md", "Home", "Homer").Build()
  1599. b.AssertFileContent("public/index.html",
  1600. `
  1601. Shortcode: sh-Homer|
  1602. Page: p-Homer|
  1603. Site: s-Home|
  1604. Hugo: h-Home|
  1605. `,
  1606. )
  1607. }
  1608. // See #12484
  1609. func TestPageFrontMatterDeprecatePathKindLang(t *testing.T) {
  1610. // This cannot be parallel as it depends on output from the global logger.
  1611. files := `
  1612. -- hugo.toml --
  1613. disableKinds = ["taxonomy", "term", "home", "section"]
  1614. -- content/p1.md --
  1615. ---
  1616. title: "p1"
  1617. kind: "page"
  1618. lang: "en"
  1619. path: "mypath"
  1620. ---
  1621. -- layouts/_default/single.html --
  1622. Title: {{ .Title }}
  1623. `
  1624. b := Test(t, files, TestOptWarn())
  1625. b.AssertFileContent("public/mypath/index.html", "p1")
  1626. b.AssertLogContains(
  1627. "deprecated: kind in front matter was deprecated",
  1628. "deprecated: lang in front matter was deprecated",
  1629. "deprecated: path in front matter was deprecated",
  1630. )
  1631. }
  1632. // Issue 13538
  1633. func TestHomePageIsLeafBundle(t *testing.T) {
  1634. t.Parallel()
  1635. files := `
  1636. -- hugo.toml --
  1637. defaultContentLanguage = 'de'
  1638. defaultContentLanguageInSubdir = true
  1639. [languages.de]
  1640. weight = 1
  1641. [languages.en]
  1642. weight = 2
  1643. -- layouts/all.html --
  1644. {{ .Title }}
  1645. -- content/index.de.md --
  1646. ---
  1647. title: home de
  1648. ---
  1649. -- content/index.en.org --
  1650. ---
  1651. title: home en
  1652. ---
  1653. `
  1654. b := Test(t, files, TestOptWarn())
  1655. b.AssertFileContent("public/de/index.html", "home de")
  1656. b.AssertFileContent("public/en/index.html", "home en")
  1657. b.AssertLogContains("Using index.de.md in your content's root directory is usually incorrect for your home page. You should use _index.de.md instead.")
  1658. b.AssertLogContains("Using index.en.org in your content's root directory is usually incorrect for your home page. You should use _index.en.org instead.")
  1659. }