默认是标题搜索
config.yml
search:
provider: default # "default" (default), false, "google", "custom"
可以修改为google search全文搜索
config.yml
search.google.custom_search_engine_id
需要在https://cse.google.com/
申请
search:
provider: google # "default" (default), false, "google", "custom"
## Google Custom Search Engine
google:
custom_search_engine_id: d5660e0d5c21e3ddf # Google Custom Search Engine ID
但是google搜索容易被墙, 而且google收录需要时间
自定义全文搜索
config.yml
search:
provider: custom # "default" (default), false, "google", "custom"
在以下目录下_includes/search-providers/custom
,
新建search.js
window.simpleJekyllSearch = SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/assets/search.json?v={{ "now" | date: "%s"}}',
noResultsText: 'No results found',
limit: 10,
searchResultTemplate: '<li class="search-result__item"><a href="{url}" class="button">{title}</a></li>'
})
新建search.html
<div class="search search--dark">
<div class="main">
<div class="search__header">{{ _locale_search }}</div>
<div class="search-bar">
<div class="search-box js-search-box">
<div class="search-box__icon-search"><i class="fas fa-search"></i></div>
<input type="text" id="search-input"/>
<div class="search-box__icon-clear js-icon-clear">
<a><i class="fas fa-times"></i></a>
</div>
</div>
<button class="button button--theme-dark button--pill search__cancel js-search-toggle">
{{ _locale_cancel }}</button>
</div>
<div class="search-result js-search-result">
<ul id="results-container"></ul>
</div>
</div>
</div>
<script src="https://unpkg.com/simple-jekyll-search@latest/dest/simple-jekyll-search.min.js"></script>
<script>{%- include search-providers/custom/search.js -%}</script>
在assets
目录新建search.json
---
layout: none
---
[
{% for post in site.posts %}
{
"title" : "{{ post.title | escape }}",
"category" : "{{ post.category }}",
"tags" : "{{ post.tags | join: ', ' }}",
"url" : "{{ site.baseurl }}{{ post.url }}",
"date" : "{{ post.date }}",
"content": {{ post.content | jsonify }}
} {% unless forloop.last %},{% endunless %}
{% endfor %}
]
即可使用Simple-Jekyll-Search
提供的全文搜索功能
还可以参考码志使用方式
jekyll中使用{% %}被转义的问题
{% raw %}
{% comment %} 这里是各种包含奇怪花括号 {{0}} 的地方 {% endcomment %}
{% endraw %}
使用以下方式展示{% raw %}
{% raw %}{%{% endraw %} raw %}
{% raw %}{%{% endraw %} endraw %}
或者
{% assign openTag = '{%' %}
{{ openTag }} raw %}
content # 代码块
{{ openTag }} endraw %}
参考