Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 67 additions & 3 deletions layouts/_default/list.mxdocsalgolia.json
Original file line number Diff line number Diff line change
@@ -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 */ -}}
Expand Down Expand Up @@ -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 */ -}}
Expand All @@ -71,24 +96,50 @@ Define Global variables
{{- /* Set up the heading level we are in */ -}}
{{- if eq $startSlice "<h2" -}}
{{- $h2 = strings.TrimSpace (htmlUnescape ($processSlice | plainify)) -}}
{{- /* Extract the id attribute from the heading element for use as a URL anchor */ -}}
{{- $anchorMatch := findRE `id="([^"]+)"` $processSlice 1 -}}
{{- $h2anchor = "" -}}
{{- range $anchorMatch -}}{{- $h2anchor = strings.TrimPrefix `id="` (strings.TrimSuffix `"` .) -}}{{- end -}}
{{- $h3 = "" -}}
{{- $h4 = "" -}}
{{- $h5 = "" -}}
{{- $h6 = "" -}}
{{- $h3anchor = "" -}}
{{- $h4anchor = "" -}}
{{- $h5anchor = "" -}}
{{- $h6anchor = "" -}}
{{- else if eq $startSlice "<h3" -}}
{{- $h3 = strings.TrimSpace (htmlUnescape ($processSlice | plainify)) -}}
{{- $anchorMatch := findRE `id="([^"]+)"` $processSlice 1 -}}
{{- $h3anchor = "" -}}
{{- range $anchorMatch -}}{{- $h3anchor = strings.TrimPrefix `id="` (strings.TrimSuffix `"` .) -}}{{- end -}}
{{- $h4 = "" -}}
{{- $h5 = "" -}}
{{- $h6 = "" -}}
{{- $h4anchor = "" -}}
{{- $h5anchor = "" -}}
{{- $h6anchor = "" -}}
{{- else if eq $startSlice "<h4" -}}
{{- $h4 = strings.TrimSpace (htmlUnescape ($processSlice | plainify)) -}}
{{- $anchorMatch := findRE `id="([^"]+)"` $processSlice 1 -}}
{{- $h4anchor = "" -}}
{{- range $anchorMatch -}}{{- $h4anchor = strings.TrimPrefix `id="` (strings.TrimSuffix `"` .) -}}{{- end -}}
{{- $h5 = "" -}}
{{- $h6 = "" -}}
{{- $h5anchor = "" -}}
{{- $h6anchor = "" -}}
{{- else if eq $startSlice "<h5" -}}
{{- $h5 = strings.TrimSpace (htmlUnescape ($processSlice | plainify)) -}}
{{- $anchorMatch := findRE `id="([^"]+)"` $processSlice 1 -}}
{{- $h5anchor = "" -}}
{{- range $anchorMatch -}}{{- $h5anchor = strings.TrimPrefix `id="` (strings.TrimSuffix `"` .) -}}{{- end -}}
{{- $h6 = "" -}}
{{- $h6anchor = "" -}}
{{- else if eq $startSlice "<h6" -}}
{{- $h6 = strings.TrimSpace (htmlUnescape ($processSlice | plainify)) -}}
{{- $anchorMatch := findRE `id="([^"]+)"` $processSlice 1 -}}
{{- $h6anchor = "" -}}
{{- range $anchorMatch -}}{{- $h6anchor = strings.TrimPrefix `id="` (strings.TrimSuffix `"` .) -}}{{- end -}}
{{- else -}}
{{- /*
* Get all the information for this piece of text (not a heading) and label it uniquely
Expand Down Expand Up @@ -148,7 +199,20 @@ Define Global variables
{{- end -}}
{{- $scratch.SetInMap $uniqueHit "weight.tag_name" $tagName -}}
{{- /* .RelPermalink gives the page address relative to the baseURL. It reflects any changes from the url: tag in the front matter */ -}}
{{- $scratch.SetInMap $uniqueHit "url" $pageDot.RelPermalink -}}
{{- /* Append the deepest available heading anchor so search results link directly to the relevant section */ -}}
{{- $anchor := "" -}}
{{- with $h6anchor -}}{{- $anchor = $h6anchor -}}{{- else -}}
{{- with $h5anchor -}}{{- $anchor = $h5anchor -}}{{- else -}}
{{- with $h4anchor -}}{{- $anchor = $h4anchor -}}{{- else -}}
{{- with $h3anchor -}}{{- $anchor = $h3anchor -}}{{- else -}}
{{- with $h2anchor -}}{{- $anchor = $h2anchor -}}{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $pageURL := $pageDot.RelPermalink -}}
{{- with $anchor -}}{{- $pageURL = printf "%s#%s" $pageDot.RelPermalink $anchor -}}{{- end -}}
{{- $scratch.SetInMap $uniqueHit "url" $pageURL -}}
{{- $scratch.SetInMap $uniqueHit "slug" $pageDot.File.TranslationBaseName -}}
{{- $scratch.SetInMap $uniqueHit "unique_hierarchy" $uniqueHierarchy -}}
{{- end -}}
Expand Down