]> git.maquefel.me Git - brevno-suite/hugo/commit
Add page fragments support to Related
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 11 Feb 2023 15:20:24 +0000 (16:20 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 21 Feb 2023 16:56:41 +0000 (17:56 +0100)
commit90da7664bf1f3a0ca2e18144b5deacf532c6e3cf
tree78d8ac72ebb2ccee4ca4bbeeb9add3365c743e90
parent0afec0a9f4aace1f5f4af6822aeda6223ee3e3a9
Add page fragments support to Related

The main topic of this commit is that you can now index fragments (content heading identifiers) when calling `.Related`.

You can do this by:

* Configure one or more indices with type `fragments`
* The name of those index configurations maps to an (optional) front matter slice with fragment references. This allows you to link
page<->fragment and page<->page.
* This also will index all the fragments (heading identifiers) of the pages.

It's also possible to use type `fragments` indices in shortcode, e.g.:

```
{{ $related := site.RegularPages.Related .Page }}
```

But, and this is important, you need to include the shortcode using the `{{<` delimiter. Not doing so will create infinite loops and timeouts.

This commit also:

* Adds two new methods to Page: Fragments (can also be used to build ToC) and HeadingsFiltered (this is only used in Related Content with
index type `fragments` and `enableFilter` set to true.
* Consolidates all `.Related*` methods into one, which takes either a `Page` or an options map as its only argument.
* Add `context.Context` to all of the content related Page API. Turns out it wasn't strictly needed for this particular feature, but it will
soon become usefil, e.g. in #9339.

Closes #10711
Updates #9339
Updates #10725
66 files changed:
.gitignore [new file with mode: 0644]
common/collections/slice.go
common/collections/slice_test.go
compare/compare.go
docs/content/en/content-management/related.md
go.mod
go.sum
hugolib/content_factory.go
hugolib/content_map_page.go
hugolib/embedded_shortcodes_test.go
hugolib/hugo_sites.go
hugolib/hugo_sites_build.go
hugolib/hugo_sites_build_errors_test.go
hugolib/image_test.go
hugolib/language_content_dir_test.go
hugolib/page.go
hugolib/page__content.go
hugolib/page__menus.go
hugolib/page__new.go
hugolib/page__per_output.go
hugolib/page__position.go
hugolib/page_test.go
hugolib/shortcode.go
hugolib/shortcode_page.go
hugolib/shortcode_test.go
hugolib/site.go
hugolib/site_render.go
hugolib/site_test.go
hugolib/testhelpers_test.go
lazy/init.go
lazy/init_test.go
markup/asciidocext/convert.go
markup/asciidocext/convert_test.go
markup/converter/converter.go
markup/goldmark/convert.go
markup/goldmark/toc.go
markup/tableofcontents/tableofcontents.go
markup/tableofcontents/tableofcontents_test.go
related/integration_test.go
related/inverted_index.go
related/inverted_index_test.go
resources/errorResource.go
resources/image_test.go
resources/page/page.go
resources/page/page_lazy_contentprovider.go
resources/page/page_marshaljson.autogen.go
resources/page/page_nop.go
resources/page/pagegroup.go
resources/page/pagegroup_test.go
resources/page/pages.go
resources/page/pages_related.go
resources/page/pages_related_test.go
resources/page/pages_sort.go
resources/page/pages_sort_test.go
resources/page/pagination_test.go
resources/page/testhelpers_test.go
resources/postpub/postpub.go
resources/resource.go
resources/resource/resourcetypes.go
resources/resource_transformers/integrity/integrity_test.go
resources/resource_transformers/minifier/minify_test.go
resources/transform.go
resources/transform_test.go
tpl/internal/go_templates/texttemplate/hugo_template.go
tpl/transform/transform.go
tpl/transform/transform_test.go