{{- /* fragments.html - Split page content into searchable fragments This partial processes a Hugo page and splits its content into fragments based on headings, creating a data structure suitable for search indexing. It supports different fragment types and handles hierarchical heading structures (h1, h2). Parameters: - .context (Page): The Hugo page to process - .type (string): Fragment type - "content" (default), "heading", "title", or "summary" Returns: - dict: Map of heading keys to content fragments Example: Input page with content: # Introduction This is the intro text. ## Setup Setup instructions here. # Configuration Config details here. Output (type "content"): { "": "This is the intro text.", "intro#Introduction": "This is the intro text. Setup instructions here.", "setup#Setup": "Setup instructions here.", "config#Configuration": "Config details here." } Fragment types: - "content": Splits page content by headings (default) - "heading": Returns heading keys with empty content - "title": Returns empty content (title handled elsewhere) - "summary": Returns page summary only */ -}} {{- /* Extract page context and fragment type */ -}} {{- $page := .context -}} {{- $type := .type | default "content" -}} {{- /* Initialize slices to store heading data */ -}} {{- $headingKeys := slice -}} {{- /* Keys for indexing (ID#Title or just Title) */ -}} {{- $headingTitles := slice -}} {{- /* HTML heading tags for content splitting */ -}} {{- /* Process all h1 headings and their nested h2 headings */ -}} {{- range $h1 := $page.Fragments.Headings -}} {{- /* Handle h1 headings - empty titles get special treatment */ -}} {{- if eq $h1.Title "" -}} {{- $headingKeys = $headingKeys | append $h1.Title -}} {{- else -}} {{- $headingKeys = $headingKeys | append (printf "%s#%s" $h1.ID $h1.Title) -}} {{- end -}} {{- $headingTitles = $headingTitles | append (printf "