search engine changed to fuse.js, chinese, korean search support

This commit is contained in:
zzossig 2019-12-09 23:00:51 +09:00
parent aa71808f20
commit 586dffdef5
16 changed files with 121 additions and 250 deletions

View File

@ -225,7 +225,7 @@ enableThemeChange = true # site color theme
# body
enableBreadcrumb = true # breadcrumb for list, single page
enablePhotoSwipe = true # image viewer for gallery, single page
enableSearch = true # site search with lunr
enableSearch = true # site search with fuse
enableGoToTop = true # scroll to top
enableWhoami = true # at the end of single page
summaryShape = "classic" # card, classic, compact
@ -251,7 +251,6 @@ enableSidebarCategories = true
enableToc = true # single page table of contents
enableTocSwitch = true # single page table of contents visibility switch
itemsPerCategory = 5 # maximum number of posts shown in the sidebar.
searchLanguages = ['en'] # lunr multilanguage search. https://github.com/MihaiValentin/lunr-languages
# footer
showPoweredBy = true # show footer text: Powered by Hugo and Zzo theme

View File

@ -34,7 +34,7 @@ Thank you for click me!. Zzo theme is a blog theme powered by Hugo with free(alw
* Multilingual (i18n)
* Responsive design
* RSS and JSON feeds with full content
* Search with Lunr
* Search with Fuse
* Gallery with Masonry, Photoswipe
* Fast code highlighting
@ -220,7 +220,7 @@ enableThemeChange = true # site color theme
# body
enableBreadcrumb = true # breadcrumb for list, single page
enablePhotoSwipe = true # image viewer for gallery, single page
enableSearch = true # site search with lunr
enableSearch = true # site search with Fuse
enableGoToTop = true # scroll to top
enableWhoami = true # at the end of single page
summaryShape = "classic" # card, classic, compact
@ -246,7 +246,6 @@ enableSidebarCategories = true
enableToc = true # single page table of contents
enableTocSwitch = true # single page table of contents visibility switch
itemsPerCategory = 5 # maximum number of posts shown in the sidebar.
searchLanguages = ['en'] # lunr multilanguage search. https://github.com/MihaiValentin/lunr-languages
# footer
showPoweredBy = true # show footer text: Powered by Hugo and Zzo theme

13
assets/js/fuse.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

5
assets/js/require.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -224,6 +224,7 @@
&--desc {
font-size: 0.9rem;
@include truncate(960px);
@include themify($themes) {
color: themed('search-color');
opacity: 0.65;

View File

@ -112,117 +112,3 @@
[reveal.plugin.highlight]
sri = "sha256-ZksQEvQYWeyyAZ67Oi6Ob1eLnb1IpmIV+IGstqKyxgw="
url = "https://cdn.jsdelivr.net/npm/reveal.js@3.8.0/plugin/highlight/highlight.js"
# lunr languages
[js.stemmer]
code = "stemmer"
sri = "sha256-LnITYFhGoYAU7HUJEMsYqKTGC7IyABA7P62e8nsQxwU="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.stemmer.support.min.js"
[js.multi_language]
code = "multiLanguage"
sri = "sha256-l2H0da5582Qg/3FN+ZUO+yZO/8+SMO/VW1EaDeiZ6Xk="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.multi.min.js"
[lunr.ar]
code = "ar"
sri = "sha256-OQf/d8ARJV1yW5ij9fwh2nKphCnG3T/b1HCwqX/6oyQ="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.ar.min.js"
[lunr.da]
code = "da"
sri = "sha256-KhJzQEjq504KBeXBCP3yTCtx382NpxIzbKnj0nq5KVY="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.da.min.js"
[lunr.de]
code = "de"
sri = "sha256-vKp8XBm8cwwFu5HiKuDjhuGsSgWAxCt9lPm4dXqtras="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.de.min.js"
[lunr.du]
code = "du"
sri = "sha256-RS2gT+RJucZcYThP7FgtxjgkvU5Vn64sOSaneQto6XY="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.du.min.js"
[lunr.es]
code = "es"
sri = "sha256-3sTskL1vR4yj5lY2qOP+31ErI9AaUaAdfngi9n67qvg="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.es.min.js"
[lunr.fi]
code = "fi"
sri = "sha256-aBVB/PWxmHrYsAdm6cBjiez5nD166Bf6iR+SP2kbhmg="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.fi.min.js"
[lunr.fr]
code = "fr"
sri = "sha256-TdVqolUedwrSbvS4UJLNMUR2ceDoSzlRQnhUf1QXc3c="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.fr.min.js"
[lunr.hu]
code = "hu"
sri = "sha256-h2yWm79KK4Rzj04KFJIu4zHLfCGTpiH2Xbf4Nv3TOjg="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.hu.min.js"
[lunr.it]
code = "it"
sri = "sha256-AKUHPfLpIuX97RxaTUARrsAkcqudkYKnxlCNYLYlxFM="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.it.min.js"
[lunr.ja]
code = "ja"
sri = "sha256-xP3tMI9jNoGm7VO2wQ2MpZFv39UPa4LskU1yW+DLi9Y="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.ja.min.js"
[lunr.jp]
code = "jp"
sri = "sha256-BBFO3DbcEU7c5a+7PH95X0XHfYZzwe3NylZ13atdUZk="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.jp.min.js"
[lunr.nl]
code = "nl"
sri = "sha256-OZ7ybWHtLVgG9Y6nI9+soJ9KfJtR4xW90XSCyOMBOj4="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.nl.min.js"
[lunr.no]
code = "no"
sri = "sha256-V/nbkpD57TYIB1X1PuNCoE9VpZVOSt2RXRwwGjdGRXM="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.no.min.js"
[lunr.pt]
code = "pt"
sri = "sha256-OiXSq6ojBjzxP8VsGa5MxQUMtiFRFenQj0pvS3h4AGc="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.pt.min.js"
[lunr.ro]
code = "ro"
sri = "sha256-z6JqjqQpPYHoVHuiMh1wOg/piB8HIfyl8zo/gL8Vbuk="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.ro.min.js"
[lunr.ru]
code = "ru"
sri = "sha256-UO88D6tKPy0mDolzxjNjqg3PArVZ6p0R1fArYZdYXBc="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.ru.min.js"
[lunr.sv]
code = "sv"
sri = "sha256-lCsWW8yCGOMkb8RzWvmxwvZlFDZtAAC+BRvxu4ltQT4="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.sv.min.js"
[lunr.tr]
code = "tr"
sri = "sha256-6L9XsQM7i9kuoEqUxTMBWqGn8KjWgwGUuXTpTh5Kyjw="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.tr.min.js"
[lunr.vi]
code = "vi"
sri = "sha256-LjnD/XMF9uZvwEJHlqdpbLjjbcD1w6g+obxE3+P+y1Y="
url = "https://cdn.jsdelivr.net/npm/lunr-languages@1.4.0/min/lunr.vi.min.js"

View File

@ -1,28 +1,48 @@
baseURL = "http://example.org/"
title = "Hugo Zzo Theme"
baseURL = ""
theme = "zzo"
defaultContentLanguage = "en"
defaultContentLanguage = "ko"
defaultContentLanguageInSubdir = true
hasCJKLanguage = true
summaryLength = 70
copyright = "©{year}, All Rights Reserved"
copyright = "©{year}, ZZOSSIG All Rights Reserved"
timeout = 10000
enableEmoji = true
paginate = 13
rssLimit = 100
pygmentsOptions = "linenos=table"
pygmentsUseClasses = true
googleAnalytics = ""
[markup]
[markup.goldmark]
[markup.goldmark.extensions]
definitionList = true
footnote = true
linkify = true
strikethrough = true
table = true
taskList = true
typographer = true
[markup.goldmark.parser]
attribute = true
autoHeadingID = true
[markup.goldmark.renderer]
hardWraps = true
unsafe = true
xHTML = true
[markup.highlight]
codeFences = true
hl_Lines = ""
lineNoStart = 1
lineNos = true
lineNumbersInTable = true
noClasses = false
tabWidth = 4
[markup.tableOfContents]
endLevel = 3
startLevel = 2
[outputs]
home = ["HTML", "RSS", "JSON", "WEBMANIFEST"]

View File

@ -1,9 +1,9 @@
[en]
title = "Hugo Zzo Theme"
languageName = "English"
[ko]
title = "쪼식이 블로그"
languageName = "한국어"
weight = 1
[ko]
title = "Hugo Zzo Theme"
languageName = "한국어"
[en]
title = "Zzossig's Blog"
languageName = "English"
weight = 2

View File

@ -10,12 +10,6 @@
url = "archive"
weight = 2
[[main]]
identifier = "pt"
name = "pt"
url = "pt"
weight = 3
[[main]]
identifier = "gallery"
name = "gallery"

View File

@ -0,0 +1,34 @@
[[main]]
identifier = "about"
name = "어바웃"
url = "about"
weight = 1
[[main]]
identifier = "archive"
name = "아카이브"
url = "archive"
weight = 2
[[main]]
identifier = "gallery"
name = "갤러리"
url = "gallery"
weight = 3
[[main]]
parent = "gallery"
name = "fiverr"
url = "gallery/mine"
[[main]]
identifier = "posts"
name = "포스트"
url = "posts"
weight = 4
[[main]]
identifier = "notes"
name = "노트"
url = "notes"
weight = 5

View File

@ -1,5 +1,5 @@
logoText = "Zzo"
description = "The Zzo theme for Hugo example site."
logoText = ""
description = "쪼식이 블로그"
custom_css = []
custom_js = []
@ -18,12 +18,12 @@ archivePaginate = 13
paginateWindow = 1
# whoami
myname = "zzossig"
myname = "최성환"
email = "zzossig@gmail.com"
whoami = "Web Developer"
useGravatar = false
whoami = "성장중인 프로그래머"
useGravatar = true
location = "Seoul, Korea"
organization = "Hugo"
organization = ""
link = "https://github.com/zzossig/hugo-theme-zzo"
# sidebar
@ -35,7 +35,6 @@ enableSidebarCategories = true
enableToc = true
enableTocSwitch = true
itemsPerCategory = 5
searchLanguages = ['en']
# footer
showPoweredBy = true
@ -43,7 +42,7 @@ showFeedLinks = true
showSocialLinks = true
enableLangChange = true
enableThemeChange = true
themeOptions = ["dark", "light", "hacker", "solarized", "custom"]
themeOptions = ["light", "dark", "hacker", "solarized", "custom"]
# service
baiduAnalytics = ""
@ -100,11 +99,11 @@ commento = false
dataAttrs = "" # "data-isso='https://isso.example.com' data-isso-require-author='true'"
[socialOptions]
email = "mailto:your@email.com"
facebook = "http://example.org/"
twitter = "http://example.org/"
email = "mailto:zzossig@gmail.com"
facebook = ""
twitter = "https://twitter.com/zzossig"
github = "https://github.com/zzossig/hugo-theme-zzo"
stack-overflow = ""
stack-overflow = "https://stackoverflow.com/users/11747951/zzossig"
instagram = ""
google-plus = ""
youtube = ""

View File

@ -8,52 +8,40 @@
{{ end }}
{{ end }}
{{ $fuse := resources.Get "js/fuse.min.js" | resources.Fingerprint }}
<script defer src="{{ $fuse.RelPermalink }}"></script>
<script>
// search
var runSearch = function() {
{{ $searchLanguages := .Site.Params.searchLanguages }}
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
{{ if .Site.IsMultiLingual }}
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
{{ else }}
var baseurl = "{{.Site.BaseURL}}";
{{ end }}
if (!searchLanguages) {
searchLanguages = ['en'];
}
var lunrIndex = null;
var pagesIndex = null;
var searchResults = null;
var searchMenu = null;
var fuse = null;
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function initLunr() {
function initFuse() {
if (!endsWith(baseurl, "/")) {
baseurl = baseurl + '/';
};
$.getJSON(baseurl + "index.json")
$.ajax({
type: "GET",
url: baseurl + "index.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
})
.done(function (index) {
pagesIndex = index;
lunrIndex = lunr(function () {
this.use(lunr.multiLanguage(...searchLanguages));
this.ref('uri');
this.field('title');
this.field('description');
this.field('content');
//this.field('tags');
//this.field('series');
//this.field('categories');
var that = this;
index.forEach(function (page) {
that.add(page);
});
fuse = new Fuse(index, {
keys: ['title', 'description', 'content']
});
})
.fail(function (jqxhr, textStatus, error) {
@ -62,14 +50,6 @@
});
}
function search(query) {
return lunrIndex.search(query).map(function (result) {
return pagesIndex.filter(function (page) {
return page.uri === result.ref;
})[0];
});
}
function renderSearchResults(results) {
searchResults = document.getElementById('search-results');
searchMenu = document.getElementById('search-menu');
@ -123,7 +103,7 @@
searchResults.appendChild(content);
}
initLunr();
initFuse();
$("#search").on('input', function (e) {
if (!e.target.value) {
@ -135,7 +115,7 @@
return null;
}
var results = search(e.target.value);
var results = fuse.search(e.target.value);
renderSearchResults(results);
});
@ -156,7 +136,7 @@
$('#search-results').attr('class', 'dropdown');
return null;
}
var results = search(e.target.value);
var results = fuse.search(e.target.value);
renderSearchResults(results);
});
@ -186,7 +166,7 @@
return null;
}
var results = search(e.target.value);
var results = fuse.search(e.target.value);
renderSearchResultsMobile(results);
});
}

View File

@ -11,20 +11,4 @@
</div>
</div>
{{ $lunr := resources.Get "js/lunr.min.js" | resources.Fingerprint }}
<script defer src="{{ $lunr.RelPermalink }}"></script>
{{ $stemmer := .Site.Data.lib.js.stemmer }}
<script defer src="{{ $stemmer.url }}" integrity="{{ $stemmer.sri }}" crossorigin="anonymous"></script>
{{ $multi := .Site.Data.lib.js.multi_language }}
<script defer src="{{ $multi.url }}" integrity="{{ $multi.sri }}" crossorigin="anonymous"></script>
{{ $searchLanguages := .Site.Params.searchLanguages }}
{{ range .Site.Data.lib.lunr }}
{{ if in $searchLanguages .code }}
<script defer src="{{ .url }}" integrity="{{ .sri }}" crossorigin="anonymous"></script>
{{ end }}
{{ end }}
{{ end }}