From b2f9d57f57fb3d110112e4ce86fb9891e1fda1d9 Mon Sep 17 00:00:00 2001 From: Mark van Ments <35492184+MarkvanMents@users.noreply.github.com> Date: Wed, 30 Sep 2026 17:25:36 +0200 Subject: [PATCH 1/2] Revert "Revert "Add anchors to Algolia indexes (#11976)" (#11993)" This reverts commit 7c0957a208a0502b06bc74ed840a55af45e6a274. --- layouts/_default/list.mxdocsalgolia.json | 70 +++++++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/layouts/_default/list.mxdocsalgolia.json b/layouts/_default/list.mxdocsalgolia.json index 5637f341c96..9ff0a7eac44 100644 --- a/layouts/_default/list.mxdocsalgolia.json +++ b/layouts/_default/list.mxdocsalgolia.json @@ -1,6 +1,26 @@ {{- /* -Algolia generation based on this blog: https://web.archive.org/web/20201109041339/https://forestry.io/blog/search-with-algolia-in-hugo/ -Define Global variables +Algolia search index generator — based on https://web.archive.org/web/20201109041339/https://forestry.io/blog/search-with-algolia-in-hugo/ + +Outputs a JSON array of Algolia records, one per content chunk per page. + +Pages included: all non-draft, non-private pages of type "docs" or "swagger" +that are descendants of the current section. + +How records are created: +1. Each page's rendered HTML is split on heading tags (h2–h6), paragraph, + list item, table cell, alert div, and code block tags. This produces one + chunk per distinct piece of content. +2. As chunks are processed, heading context (h2–h6 text and id anchors) is + tracked and updated. When a higher-level heading is encountered, all + deeper heading levels are reset. +3. Heading chunks themselves are never written as records. Only non-heading + chunks produce a record, carrying the current heading context as fields. +4. Each record includes: objectID (unique per chunk), title, h2–h6 heading + text, text (plain content), url (page URL with #anchor of deepest heading + in scope), unique_hierarchy (breadcrumb string), slug, description, + content_type, type, mendix_version, menu_order, time_stamp, weight.position, + and weight.tag_name (p / li / th / td / code / alert). +5. Records with empty text are excluded. */ -}} {{- $firstloop := true -}} {{- /* Use a local scratchpad - Page scratchpad already contains other stuff */ -}} @@ -59,6 +79,11 @@ Define Global variables {{- $h4 := "" }} {{- $h5 := "" }} {{- $h6 := "" }} + {{- $h2anchor := "" }} + {{- $h3anchor := "" }} + {{- $h4anchor := "" }} + {{- $h5anchor := "" }} + {{- $h6anchor := "" }} {{- $text := "" }} {{- range $processSlice := $contentSlices -}} {{- /* sliceNumber tells us where we are in the file and gives us a way of making each hit unique */ -}} @@ -71,24 +96,50 @@ Define Global variables {{- /* Set up the heading level we are in */ -}} {{- if eq $startSlice " Date: Thu, 1 Oct 2026 13:32:39 +0200 Subject: [PATCH 2/2] Add page_url field to Algolia records for deduplication The url field now includes a heading anchor (e.g. /refguide/entities/#entity-types), which broke deduplication of multiple hits from the same page. The new page_url field carries the bare page URL without any anchor, providing a stable key for deduplicating hits per page in Algolia. Co-Authored-By: Claude Sonnet 4.6 --- layouts/_default/list.mxdocsalgolia.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/layouts/_default/list.mxdocsalgolia.json b/layouts/_default/list.mxdocsalgolia.json index 9ff0a7eac44..c90a2f7524c 100644 --- a/layouts/_default/list.mxdocsalgolia.json +++ b/layouts/_default/list.mxdocsalgolia.json @@ -19,7 +19,8 @@ How records are created: text, text (plain content), url (page URL with #anchor of deepest heading in scope), unique_hierarchy (breadcrumb string), slug, description, content_type, type, mendix_version, menu_order, time_stamp, weight.position, - and weight.tag_name (p / li / th / td / code / alert). + weight.tag_name (p / li / th / td / code / alert), and page_url (bare page + URL without anchor, for deduplicating multiple hits from the same page). 5. Records with empty text are excluded. */ -}} {{- $firstloop := true -}} @@ -213,6 +214,8 @@ How records are created: {{- $pageURL := $pageDot.RelPermalink -}} {{- with $anchor -}}{{- $pageURL = printf "%s#%s" $pageDot.RelPermalink $anchor -}}{{- end -}} {{- $scratch.SetInMap $uniqueHit "url" $pageURL -}} + {{- /* page_url is the bare page URL without any anchor, for deduplicating multiple hits from the same page */ -}} + {{- $scratch.SetInMap $uniqueHit "page_url" $pageDot.RelPermalink -}} {{- $scratch.SetInMap $uniqueHit "slug" $pageDot.File.TranslationBaseName -}} {{- $scratch.SetInMap $uniqueHit "unique_hierarchy" $uniqueHierarchy -}} {{- end -}}