-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds new output format for devcenter-specific search data to config f…
…or both sites adds new devcenter.json template to layouts adds supporting partials to generate the json layout
- Loading branch information
Showing
5 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{/* FlexSearch Data structure for use in devcenter.upsun.com */}} | ||
{{- $indexType := site.Params.search.flexsearch.index | default "content" -}} | ||
{{- $baseURL := .Site.BaseURL -}} | ||
{{- if not (in (slice "content" "summary" "heading" "title" ) $indexType) -}} | ||
{{- errorf "unknown flexsearch index type: %s" $indexType -}} | ||
{{- end -}} | ||
|
||
{{- $pages := where .Site.Pages "Kind" "in" (slice "page" "section") -}} | ||
{{- $pages = where $pages "Params.excludeSearch" "!=" true -}} | ||
{{- $pages = where $pages "Content" "!=" "" -}} | ||
|
||
{{- $output := dict -}} | ||
|
||
{{- range $index, $page := $pages -}} | ||
{{- $pageTitle := $page.LinkTitle | default $page.File.BaseFileName -}} | ||
{{- $pageLink := $page.RelPermalink -}} | ||
{{- $fullURL := printf "%s%s" $baseURL $pageLink -}} | ||
{{- $data := partial "utils/fragments" (dict "context" $page "type" $indexType) -}} | ||
{{- $output = $output | merge (dict $pageLink (dict "title" $pageTitle "data" $data "base" $baseURL "full" $fullURL )) -}} | ||
{{- end -}} | ||
|
||
{{- $output | jsonify -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{- $excludeStart := "<!-- excludeSearch -->" -}} | ||
{{- $excludeEnd := "<!-- /excludeSearch -->" -}} | ||
{{- $append := true -}} | ||
{{- $data := slice -}} | ||
|
||
{{- $splitC := split .content "\n" -}} | ||
{{- range $splitC -}} | ||
{{- if $append -}} | ||
{{- if eq $excludeStart . -}} | ||
{{- $append = false -}} | ||
{{- else -}} | ||
{{- $data = $data | append . -}} | ||
{{- end -}} | ||
{{- else if eq $excludeEnd . -}} | ||
{{- $append = true -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- $final := delimit $data "\n" -}} | ||
{{- return $final -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{/* Split page raw content into fragments */}} | ||
{{ $page := .context }} | ||
{{ $type := .type | default "content" }} | ||
{{ $headingKeys := slice }} | ||
{{ $headingTitles := slice }} | ||
|
||
{{ range $h1 := $page.Fragments.Headings }} | ||
{{ 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 "# %s" $h1.Title) }} | ||
|
||
{{ range $h2 := $h1.Headings }} | ||
{{ $headingKeys = $headingKeys | append (printf "%s#%s" $h2.ID $h2.Title) }} | ||
{{ $headingTitles = $headingTitles | append (printf "## %s" $h2.Title) }} | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ $content := partial "utils/excludeSearch.html" (dict "context" . "content" $page.RawContent) }} | ||
{{ $len := len $headingKeys }} | ||
{{ $data := dict }} | ||
|
||
{{ if eq $type "content" }} | ||
{{/* Include full content of the page */}} | ||
{{ if eq $len 0 }} | ||
{{ $plainContent := partial "utils/excludeSearch.html" (dict "context" . "content" $page.RawContent) }} | ||
{{ $data = $data | merge (dict "" ($plainContent | htmlUnescape | chomp)) }} | ||
{{ else }} | ||
{{/* Split the raw content from bottom to top */}} | ||
{{ range seq $len }} | ||
{{ $i := sub $len . }} | ||
{{ $headingKey := index $headingKeys $i }} | ||
{{ $headingTitle := index $headingTitles $i }} | ||
|
||
{{ if eq $i 0 }} | ||
{{ $data = $data | merge (dict $headingKey ($content | $page.RenderString | plainify | htmlUnescape | chomp)) }} | ||
{{ else }} | ||
{{ $parts := split $content (printf "\n%s\n" $headingTitle) }} | ||
{{ $lastPart := index $parts (sub (len $parts) 1) }} | ||
|
||
{{ $data = $data | merge (dict $headingKey ($lastPart | $page.RenderString | plainify | htmlUnescape | chomp)) }} | ||
{{ $content = strings.TrimSuffix $lastPart $content }} | ||
{{ $content = strings.TrimSuffix (printf "\n%s\n" $headingTitle) $content }} | ||
{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
{{ else if (eq $type "heading" ) }} | ||
{{/* Put heading keys with empty content to the data object */}} | ||
{{ $data = dict "" "" }} | ||
{{ range $headingKeys }} | ||
{{ $data = $data | merge (dict . "") }} | ||
{{ end }} | ||
{{ else if (eq $type "title") }} | ||
{{/* Use empty data object since title is included in search-data.json */}} | ||
{{ $data = $data | merge (dict "" "") }} | ||
{{ else if (eq $type "summary" ) }} | ||
{{ $data = $data | merge (dict "" ($page.Summary | plainify | htmlUnescape | chomp)) }} | ||
{{ end }} | ||
|
||
{{ return $data }} |