search logic changed to use .Permalink
This commit is contained in:
parent
10c14879cb
commit
8e6013a964
|
@ -35,7 +35,18 @@ googleAnalytics = ""
|
||||||
startLevel = 2
|
startLevel = 2
|
||||||
|
|
||||||
[outputs]
|
[outputs]
|
||||||
home = ["HTML", "RSS", "JSON"]
|
page = ["HTML", "SearchIndex"]
|
||||||
|
home = ["HTML", "RSS", "SearchIndex"]
|
||||||
|
section = ["HTML", "RSS", "SearchIndex"]
|
||||||
|
taxonomyTerm = ["HTML", "RSS", "SearchIndex"]
|
||||||
|
taxonomy = ["HTML", "RSS", "SearchIndex"]
|
||||||
|
|
||||||
|
[outputFormats]
|
||||||
|
[outputFormats.SearchIndex]
|
||||||
|
mediaType = "application/json"
|
||||||
|
baseName = "index"
|
||||||
|
isPlainText = true
|
||||||
|
notAlternative = true
|
||||||
|
|
||||||
[taxonomies]
|
[taxonomies]
|
||||||
category = "categories"
|
category = "categories"
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
{{ if eq .Type "publication" }}
|
|
||||||
{{ $paginator := .Paginate (where .Pages "Type" "publication") 100 }}
|
|
||||||
[{{ range $index, $page := $paginator.Pages }}
|
|
||||||
{{- if ne $page.Type "json" -}}
|
|
||||||
{{- if and $index (gt $index 0) -}},{{- end }}
|
|
||||||
{
|
|
||||||
"uri": "{{ $page.Permalink }}",
|
|
||||||
"title": "{{ htmlEscape $page.Title}}",
|
|
||||||
"shorttitle": "{{ htmlEscape $page.Params.shorttitle}}",
|
|
||||||
"booktitle": "{{ htmlEscape $page.Params.booktitle}}",
|
|
||||||
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
|
|
||||||
"authors": "{{ with $page.Params.authors }}{{ delimit . ", " }}{{ end }}",
|
|
||||||
"abstract": "{{ with $page.Params.abstract }}{{ . | markdownify }}{{ end }}",
|
|
||||||
"ENTRYTYPE": "{{ with $page.Params.ENTRYTYPE }}{{ . }}{{ end }}",
|
|
||||||
"publication": "{{ with $page.Params.publication }}{{ . }}{{ end }}",
|
|
||||||
"publishDate": "{{ with $page.Params.publishDate }}{{ . }}{{ end }}",
|
|
||||||
"permalink": "{{ .Permalink }}",
|
|
||||||
"content": {{$page.Plain | jsonify}}
|
|
||||||
}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}]
|
|
||||||
{{ end }}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
{{- $.Scratch.Add "searchindex" slice -}}
|
||||||
|
|
||||||
|
{{ if eq .Type "publication" }}
|
||||||
|
|
||||||
|
{{ if eq .Permalink .FirstSection.Permalink }}
|
||||||
|
{{- range $index, $element := (where .Site.RegularPages "Section" "publication") -}}
|
||||||
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "shorttitle" $element.Params.shorttitle "booktitle" $element.Params.booktitle "uri" $element.Permalink "tags" $element.Params.tags "authors" $element.Params.authors "abstract" $element.Params.abstract "ENTRYTYPE" $element.Params.ENTRYTYPE "publication" $element.Params.publication "publishDate" $element.Params.publishDate) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{ else }}
|
||||||
|
{{ $paginator := .Paginate (where .Pages "Type" .Type) }}
|
||||||
|
{{- range $index, $element := $paginator.Pages -}}
|
||||||
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "shorttitle" $element.Params.shorttitle "booktitle" $element.Params.booktitle "uri" $element.Permalink "tags" $element.Params.tags "authors" $element.Params.authors "abstract" $element.Params.abstract "ENTRYTYPE" $element.Params.ENTRYTYPE "publication" $element.Params.publication "publishDate" $element.Params.publishDate) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ else }}
|
||||||
|
|
||||||
|
{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
|
||||||
|
{{ with $element.Plain }}
|
||||||
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
|
||||||
|
{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{{- $.Scratch.Add "searchindex" slice -}}
|
||||||
|
{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
|
||||||
|
{{ with $element.Plain }}
|
||||||
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
|
||||||
|
{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{{- $.Scratch.Add "searchindex" slice -}}
|
||||||
|
{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
|
||||||
|
{{ with $element.Plain }}
|
||||||
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
|
||||||
|
{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{{- $.Scratch.Add "searchindex" slice -}}
|
||||||
|
{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
|
||||||
|
{{ with $element.Plain }}
|
||||||
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
|
||||||
|
{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
|
@ -1,14 +1,7 @@
|
||||||
[{{ range $index, $page := .Site.Pages }}
|
{{- $.Scratch.Add "searchindex" slice -}}
|
||||||
{{- if ne $page.Type "json" -}}
|
{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
|
||||||
{{- if and $index (gt $index 0) -}},{{- end }}
|
{{ with $element.Plain }}
|
||||||
{
|
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "uri" $element.Permalink "tags" $element.Params.tags "section" $element.Section "content" $element.Plain "description" $element.Description) -}}
|
||||||
"uri": "{{ $page.Permalink }}",
|
{{ end }}
|
||||||
"title": "{{ htmlEscape $page.Title}}",
|
|
||||||
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
|
|
||||||
"categories": [{{ range $cindex, $category := $page.Params.categoris }}{{ if $cindex }}, {{ end }}"{{ $category| htmlEscape }}"{{ end }}],
|
|
||||||
"series": [{{ range $sindex, $series := $page.Params.series }}{{ if $sindex }}, {{ end }}"{{ $series| htmlEscape }}"{{ end }}],
|
|
||||||
"description": "{{ htmlEscape .Description}}",
|
|
||||||
"content": {{$page.Plain | jsonify}}
|
|
||||||
}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}]
|
{{- $.Scratch.Get "searchindex" | jsonify -}}
|
|
@ -551,44 +551,8 @@
|
||||||
|
|
||||||
|
|
||||||
// ========================== search ==========================
|
// ========================== search ==========================
|
||||||
var baseurl = null;
|
{{ $permalink:= .Permalink }}
|
||||||
{{ $siteBaseURL:= .Site.BaseURL }}
|
var permalink = JSON.parse({{ $permalink | jsonify }});
|
||||||
var siteBaseURL = JSON.parse({{ $siteBaseURL | jsonify }});
|
|
||||||
var siteBaseChecker = /\/\w+\//i;
|
|
||||||
var isSlug = siteBaseChecker.test(siteBaseURL);
|
|
||||||
var isThemeSite = location.origin.includes('themes.gohugo.io');
|
|
||||||
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
if (isThemeSite) {
|
|
||||||
baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
} else {
|
|
||||||
var hasLangPostfix = location.pathname.includes("/{{.Site.Language.Lang}}");
|
|
||||||
if (hasLangPostfix) {
|
|
||||||
if (isSlug) {
|
|
||||||
baseurl = location.origin + siteBaseURL.match(siteBaseChecker)[0] + "{{.Site.Language.Lang}}";
|
|
||||||
} else {
|
|
||||||
baseurl = location.origin + "/{{.Site.Language.Lang}}";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isSlug) {
|
|
||||||
baseurl = location.origin + siteBaseURL.match(siteBaseChecker)[0];
|
|
||||||
} else {
|
|
||||||
baseurl = location.origin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{ else }}
|
|
||||||
if (isThemeSite) {
|
|
||||||
baseurl = "{{.Site.BaseURL}}";
|
|
||||||
} else {
|
|
||||||
if (isSlug) {
|
|
||||||
baseurl = location.origin + siteBaseURL.match(siteBaseChecker)[0];
|
|
||||||
} else {
|
|
||||||
baseurl = location.origin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
var searchResults = null;
|
var searchResults = null;
|
||||||
var searchMenu = null;
|
var searchMenu = null;
|
||||||
var searchText = null;
|
var searchText = null;
|
||||||
|
@ -598,17 +562,9 @@
|
||||||
|
|
||||||
var fuse = null;
|
var fuse = null;
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initFuse() {
|
function initFuse() {
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', baseurl + "index.json");
|
xhr.open('GET', permalink + "index.json");
|
||||||
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
|
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
<script>
|
<script>
|
||||||
{{ $permalink := .Permalink }}
|
{{ $permalink := .Permalink }}
|
||||||
var permalink = JSON.parse({{ $permalink | jsonify }});
|
var permalink = JSON.parse({{ $permalink | jsonify }});
|
||||||
{{ $isRootSection := eq .Permalink .FirstSection.Permalink }}
|
|
||||||
var isRootSection = JSON.parse({{ $isRootSection | jsonify }});
|
|
||||||
var data = null;
|
var data = null;
|
||||||
const options = {
|
const options = {
|
||||||
limit: 100, // don't return more results than you need!
|
limit: 100, // don't return more results than you need!
|
||||||
|
@ -58,7 +56,7 @@
|
||||||
if (obj.publishDate) {
|
if (obj.publishDate) {
|
||||||
var dateSpan = document.createElement('span');
|
var dateSpan = document.createElement('span');
|
||||||
dateSpan.className = 'caption pub__meta';
|
dateSpan.className = 'caption pub__meta';
|
||||||
dateSpan.innerText = '📅 ' + obj.publishDate.slice(0, 11);
|
dateSpan.innerText = '📅 ' + obj.publishDate.slice(0, 10);
|
||||||
metaDiv.appendChild(dateSpan);
|
metaDiv.appendChild(dateSpan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +95,6 @@
|
||||||
|
|
||||||
pubSearch ?
|
pubSearch ?
|
||||||
pubSearch.addEventListener('input', function(e) {
|
pubSearch.addEventListener('input', function(e) {
|
||||||
if (isRootSection) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var originUl = pubList.querySelector('ul');
|
var originUl = pubList.querySelector('ul');
|
||||||
var ul = document.createElement('ul');
|
var ul = document.createElement('ul');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue