diff options
Diffstat (limited to 'layouts/_default')
-rw-r--r-- | layouts/_default/list.html | 11 | ||||
-rw-r--r-- | layouts/_default/search.html | 19 | ||||
-rw-r--r-- | layouts/_default/search.json.json | 82 |
3 files changed, 110 insertions, 2 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 3070079..492b335 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -2,8 +2,16 @@ {{ $currentTitle := .Scratch.Get "currentTitle" }} - <main class="list"> + <!-- Collect pages using the "search" layout --> + {{ $searchPages := where .Site.RegularPages "Layout" "eq" "search" }} + <main class="list"> + + <!-- Display search form before listing posts --> + {{ if and .Site.Params.Search.enable (gt (len $searchPages) 0) (eq .Kind "section") }} + {{ partial "search-form" . }} + {{ end }} + <h1>{{ $currentTitle }}</h1> {{ if eq .Kind "taxonomyTerm" }} @@ -15,7 +23,6 @@ {{ else }} {{ $pages := where site.RegularPages "Type" "in" .Site.Params.mainSections }} - {{ $paginator := .Paginate .Pages }} <ul class="posts"> diff --git a/layouts/_default/search.html b/layouts/_default/search.html new file mode 100644 index 0000000..851f6bf --- /dev/null +++ b/layouts/_default/search.html @@ -0,0 +1,19 @@ +{{ define "main" }} + + <main class="list"> + + {{ partial "search-form" . }} + + <section id="search-info"> + <!-- Info --> + </section> + + <ul id="search-results" class="posts"> + <!-- x-js-template --> + </ul> + + <script id=search-result-template type=text/x-js-template><li><a class=btn href='${link}'><p>${title}</p>${date}</a></li></script> + + </main> + +{{ end }} diff --git a/layouts/_default/search.json.json b/layouts/_default/search.json.json new file mode 100644 index 0000000..279aeb2 --- /dev/null +++ b/layouts/_default/search.json.json @@ -0,0 +1,82 @@ +{{- $stopWords := or .Params.stopWords .Site.Params.Search.stopWords -}} + +{{- $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections -}} + +{{- $lastIndex := (sub (len $pages) 1) -}} + +{{- $.Scratch.Add "index" slice -}} + +{{- range $index, $page := $pages -}} + + {{- $.Scratch.Delete "date" -}} + {{- $.Scratch.Delete "description" -}} + {{- $.Scratch.Delete "tags" -}} + + {{- if not .Date.IsZero -}} + {{- $.Scratch.Set "date" (.Date.Format "2006-01-02") -}} + {{- end -}} + + {{- if .Description -}} + {{- $.Scratch.Set "description" (.Description | emojify) -}} + {{- end -}} + + {{- if .Params.tags -}} + {{- $.Scratch.Set "tags" .Params.tags -}} + {{- end -}} + + {{- $scratch := newScratch -}} + + {{- $content := (.Content | replaceRE "(?s)<div class=\"highlight\".*?</div>" "" ) -}} + {{- $content := ($content | replaceRE "(?s)<p class=\"error\".*?</p>" "" ) -}} + {{- $content := ($content | replaceRE "<code.*?</code>" "" ) -}} + {{- $content := ($content | replaceRE "(http|https)\\S+" "" ) -}} + {{- $content := ($content | replaceRE "<!--(.|\n)+?-->" "" ) -}} + {{- $content := ($content | plainify | emojify | lower) -}} + {{- $content := (replaceRE "\"" "" $content) -}} + {{- $content := (replaceRE "“" "" $content) -}} + {{- $content := (replaceRE "”" "" $content) -}} + {{- $content := (replaceRE "\n+" " " $content) -}} + {{- $content := (replaceRE "\r+" " " $content) -}} + {{- $content := (replaceRE "\t+" " " $content) -}} + {{- $content := (replaceRE "<" "" $content) -}} + {{- $content := (replaceRE ">" "" $content) -}} + {{- $content := (replaceRE "…" "" $content) -}} + {{- $content := (replaceRE "\\(" "" $content) -}} + {{- $content := (replaceRE "\\)" "" $content) -}} + {{- $content := (replaceRE "\\. " " " $content) -}} + {{- $content := (replaceRE "\\," "" $content) -}} + {{- $content := (replaceRE "\\:" "" $content) -}} + {{- $content := (replaceRE "\\;" "" $content) -}} + {{- $content := (replaceRE "\\!" "" $content) -}} + {{- $content := (replaceRE "\\?" "" $content) -}} + {{- $content := (replaceRE "\\/" " " $content) -}} + {{- $content := (replaceRE " +" " " $content) -}} + {{- $content := (trim $content " ") -}} + {{- $words := (split $content " ") -}} + + + {{- range $words -}} + {{- $word := (.) -}} + {{- if and (not (in ($scratch.Get "seenWords") $word)) (ne (substr $word 0 1) $word) (not (in $stopWords $word)) -}} + {{- $.Scratch.Add "currentWords" (slice $word) -}} + {{- end -}} + {{- $scratch.Add "seenWords" (slice $word) -}} + {{- end -}} + + {{- $scratch.Delete "seenWords" -}} + + + {{- $filtered := ($.Scratch.Get "currentWords") -}} + + {{- if $filtered -}} + {{- $.Scratch.Set "uniqueContent" (delimit $filtered " ") -}} + {{- end -}} + + + {{- $.Scratch.Add "index" (dict "title" (.Title | emojify) "date" ($.Scratch.Get "date") "description" ($.Scratch.Get "description") "content" ($.Scratch.Get "uniqueContent") "permalink" .Permalink "tags" ($.Scratch.Get "tags")) -}} + + {{- $.Scratch.Delete "currentWords" -}} + +{{- end -}} + +{{- $.Scratch.Get "index" | jsonify -}} |