Dividing the content by subheading for Algolia search

Are there any way to divide the content or split the content by subheading? Actually, in algolia, it’s recommended to split the contents by subheading.

This might work for you:
https://discourse.gohugo.io/t/splitting-content-into-sections-based-on-header-level/33749/6

Sorry, but It doesn’t help me. I’ve explored this, I pasted the code in list.algolia.json, as Hugo generates the JSON file automatically while running the hugo command. As of now, this is my code which separates the content by 1000 characters, but I want to split it by heading, making searching efficient with algolia.

{{/* Generates a valid Algolia search index */}}
{{- $index := slice -}}
{{- $section := $.Site.GetPage "section" .Section }}
{{- range .Site.AllPages -}}
{{- if or (and (.IsDescendant $section) (and (not .Draft) (not .Params.private))) $section.IsHome -}}
  {{- $page := . -}}
  {{- $chunked := slice -}}
  {{- $post_len := len .PlainWords -}}
  {{- range $i := (seq 0 1000 $post_len) -}}
    {{- $chunked = $chunked | append (delimit (first 1000 (after $i $page.PlainWords) ) " " ) -}}
  {{- end -}}
  {{- range $i, $c := $chunked -}}
    {{- $index = $index | append (dict "objectID" (print $page.File.UniqueID "_" $i) "content" $c "order" $i "pagetitle" $page.Title "date" $page.Date "url" $page.Permalink "tags" $page.Params.tags "searchAliases" $page.Params.searchAliases ) -}}
  {{- end -}}
{{- end -}}
{{- end -}}
{{- $index | jsonify -}}

The example that I referenced does exactly that.

I don’t know what that means.

Please post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.