Skip to content

Instantly share code, notes, and snippets.

@budparr
Created October 16, 2018 14:21
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save budparr/c09ab912d2ba184b7d962aacbecb2816 to your computer and use it in GitHub Desktop.
#gohugo search index with "some" stop words removed
{{- $.Scratch.Add "index" slice -}}
{{$index := where .Site.RegularPages ".Section" "not in" (slice "links" "internal") }}
{{- range $index -}}
{{ with .Params.images }}
{{ $.Scratch.Set "image" (index . 0)}}
{{ else }}
{{ $.Scratch.Set "image" "/uploads/logo.jpg"}}
{{ end }}
{{ $image := printf "%s%s" (replace ($.Scratch.Get "image") "/uploads" .Site.Params.image_url) "?fit=crop&h=201&w=358" }}
{{- $content_filtered := replaceRE "(?m)(?i)(?s:\\ba\\b|\\band\\b|\\barchival\\b|\\bagain\\b|\\bin\\b|\\bto\\b|\\bis\\b|\\bno\\b|\\bor\\b|\\bthis\\b|\\bwell\\b|\\byes\\b|\\bthe\\b|\\bthere\\b|\\bthese\\b|\\bthen\\b)" "" (delimit .PlainWords " ") -}}
{{- $.Scratch.Add "index" (dict "Section" .Section "objectID" (md5 .File.Path) "date" (.Date.Format "January 2, 2006") "sort_date" .Date.Unix "title" .Title "ref" .RelPermalink "tags" .Params.tags "content" $content_filtered "producer" .Params.producers "image" $image) -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment