diff --git a/assets/js/search.js b/assets/js/search.js index 79ff895..476edb7 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -55,14 +55,14 @@ const queryNgramSeparator = (query) => { */ const initLunr = () => { $.getJSON('index.json').done((index) => { - pagesIndex = index + pagesIndex = index['items'] lunrIndex = lunr(builder => { builder.tokenizer = bigramTokeniser builder.pipeline.reset() - builder.ref('ref') + builder.ref('url') builder.field('title', { boost: 10 }) builder.field('tags', { boost: 10 }) - builder.field('body') + builder.field('content_html') builder.metadataWhitelist = ['position'] for (let page of pagesIndex) { builder.add(page) @@ -83,7 +83,7 @@ const search = (query) => { lunrResult = lunrIndex.search(queryNgramSeparator(query)) return lunrResult.map((result) => { return pagesIndex.filter((page) => { - return page.ref === result.ref + return page.url === result.ref })[0] }) } @@ -158,9 +158,9 @@ const renderResults = (results) => { const matchPosition = metadata[Object.keys(metadata)[0]].body ? metadata[Object.keys(metadata)[0]].body.position[0][0] : 0 const bodyStartPosition = (matchPosition - (BODY_LENGTH / 2) > 0) ? matchPosition - (BODY_LENGTH / 2) : 0 - $searchResultPage.append('' + result.title + '') + $searchResultPage.append('' + result.title + '') - $searchResultPage.append('
' + result.body.substr(bodyStartPosition, BODY_LENGTH) + '
') + $searchResultPage.append('
' + result.content_html.substr(bodyStartPosition, BODY_LENGTH) + '
') $searchResults.append($searchResultPage) // Highlight keyword diff --git a/layouts/_default/item.json.json b/layouts/_default/item.json.json new file mode 100644 index 0000000..251761f --- /dev/null +++ b/layouts/_default/item.json.json @@ -0,0 +1,8 @@ +{ + "id": "{{ .Permalink }}", + "url": "{{ .Permalink }}", + "title": {{ .Title | jsonify }}, + "content_html": {{ .Content | jsonify }}, + "date_published": "{{ .Date.Format "2006.01.02" }}", + "tags": {{ .Params.tags | jsonify }} +} \ No newline at end of file diff --git a/layouts/_default/list.atom b/layouts/_default/list.atom.atom similarity index 100% rename from layouts/_default/list.atom rename to layouts/_default/list.atom.atom diff --git a/layouts/_default/list.feedjson.json b/layouts/_default/list.feedjson.json deleted file mode 100644 index 62a1faf..0000000 --- a/layouts/_default/list.feedjson.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "https://jsonfeed.org/version/1.1", - "title": "{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} | {{ end }}{{ .Site.Title }}{{ end }}", - "home_page_url": "{{ .Site.BaseURL }}", - "feed_url": "{{ .Permalink }}", - "description": "{{ .Description }}", - "items": [{{ range $index, $page := .Pages }}{{ if ne $index 0 }},{{ end }} - { - "author": { - {{with $.Site.Author.name }}"name": "{{ . }}",{{ end }} - "url": "{{ .Site.BaseURL }}" - }, - "id": "{{ $page.Permalink }}", - "content_html": {{ $page.Content | jsonify }}, - "date_published": {{ $page.Date.Format "2006.01.02" | jsonify }}, - "url": "{{ $page.Permalink }}", - "title": {{ $page.Title | jsonify }}, - "tags": {{ $page.Params.tags | jsonify }} - } -{{ end }}] -} - diff --git a/layouts/_default/list.json b/layouts/_default/list.json deleted file mode 100644 index 0f88195..0000000 --- a/layouts/_default/list.json +++ /dev/null @@ -1,10 +0,0 @@ -[{{ range $index, $page := .Pages }}{{ if ne $index 0 }},{{ end }} - { - "ref": "{{ $page.Permalink }}", - "title": {{ $page.Title | jsonify }}, - "section": "{{ $page.Section }}", - "tags": {{ $page.Params.tags | jsonify }}, - "date" : {{ $page.Date.Format "2006.01.02" | jsonify }}, - "body": {{ $page.Plain | jsonify }} - } -{{ end }}] \ No newline at end of file diff --git a/layouts/_default/list.json.json b/layouts/_default/list.json.json new file mode 100644 index 0000000..5863dcb --- /dev/null +++ b/layouts/_default/list.json.json @@ -0,0 +1,20 @@ +{ + "version": "https://jsonfeed.org/version/1.1", + "title": "{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} | {{ end }}{{ .Site.Title }}{{ end }}", + "home_page_url": "{{ .Site.BaseURL }}", + "feed_url": "{{ .Permalink }}", + "description": "{{ .Description }}", + "icon": "{{ .Site.BaseURL }}img/{{ .Site.Params.avatar }}", + "language": "en-US", + "authors": [ + {{with $.Site.Author.name }} + { "name": "{{ . }}" } + {{ end }} + ], + "items": [ + {{ range $index, $page := .Pages }}{{ if ne $index 0 }},{{ end }} + {{ .Render "item" }} + {{ end }} + ] +} + diff --git a/layouts/_default/single.json.json b/layouts/_default/single.json.json new file mode 100644 index 0000000..9811ca8 --- /dev/null +++ b/layouts/_default/single.json.json @@ -0,0 +1 @@ +{{ .Render "item" }} \ No newline at end of file