当前位置:网站首页>Blog Building 9: add search function to Hugo
Blog Building 9: add search function to Hugo
2022-07-28 08:35:00 【King who personally patrols the mountain】
Blog building is gradually improved , Blog content is also gradually increasing , Adding search function can easily retrieve content , Review the knowledge , Consider the past you shall know the future .
Realization hugo Blog content retrieval uses algolia service , First , Modify the blog root directory config.toml file ( Instead of , Otherwise, we can't generate .josn file ), Add the following ( Paste to the end ):
[outputs]
home = ["HTML","RSS","TXT","Algolia"]
section = ["HTML"]
taxonomy = ["HTML"]
term = ["HTML"]
[outputFormats.Algolia]
mediaType = "application/json"
baseName = "algolia"
isPlainText = true
In the blog root /layouts establish _default Folder , Create in this folder list.algolia.json file , use nop++ Or other software to open the file and add the following :
[
{
{- range $index, $entry := .Site.RegularPages }}
{
{- if $index }}, {
{ end }}
{
"objectID": {
{ .File.TranslationBaseName }},
"url": {
{ .Permalink | jsonify }},
"title": {
{ .Title | jsonify }},
"summary": {
{ .Summary | jsonify }},
"content": {
{ .Plain | jsonify }},
"pubDate": {
{ .PublishDate | jsonify }}
}
{
{- end }}
]
register algolia
Follow the registration guidance process, and then open the settings , See the picture below .
Here we store what we need API Keys
Copy the key at the red line of the upper picture , Modify the configuration file in the theme , as follows :
# Search config
# Search configuration
[params.search]
enable = true
# type of search engine ["lunr", "algolia"]
# The type of search engine ["lunr", "algolia"]
type = "algolia"
# max index length of the chunked content
# The longest index length of article content
contentLength = 4000
# placeholder of the search bar
# Space occupying prompt of search box
placeholder = "So once "
# max number of results length
# Maximum number of results
maxResultLength = 10
# snippet length of the result
# Result content fragment length
snippetLength = 30
# HTML tag name of the highlight part in results
# In the highlighted part of the search results HTML label
highlightTag = "em"
# whether to use the absolute URL based on the baseURL in search index
# Whether to use in the search index based on baseURL The absolute path of
absoluteURL = false
[params.search.algolia]
index = "blog"
appID = "xxx" # Your key
searchKey = "xxx" # Your key
Enter cmd command :
hugo
Then in public Generate under folder algolia.json file , We need to submit this document to algolia, See the picture below .

So far, the preliminary search function has been provided ( See the picture below ), It can meet the needs of daily use , in addition algolia The free version is available every month 10000 Search experience . But every time you update the blog content, you need to submit it manually algolia.json, To search for new content , You can also set automatic submission , You can search relevant settings by yourself .
边栏推荐
- Viewing vantage's self drive from the "three good" kitchen electricity standard and the value proposition of "serious life"
- 机器学习如何做到疫情可视化——疫情数据分析与预测实战
- Technology sharing | common proxy tools for interface testing
- 百度智能云九州区县大脑,描绘城乡新蓝图!
- QT 怎么删除布局里的所有控件?
- Es6: template string
- 豪华版h5俄罗斯方块小游戏源码
- ‘全局事件总线’&‘消息订阅与发布’
- Melt cloud x chat, create a "stress free social" habitat with sound
- What if you are prompted that your connection to this website is not a private connection?
猜你喜欢

机器学习如何做到疫情可视化——疫情数据分析与预测实战

sql server时间字段排序

Five screens, VR, projection, "Wei Xiaoli" rolled up on the intelligent cockpit

网口网络水晶头RJ45、POE接口定义线序

二维数组及操作

CarSim simulation quick start (XII) - Driver Model (2)

Understand the propagation process of EMI electromagnetic interference through five diagrams - the influence of square wave steepness on high-frequency components, the spectrum graph from time sequenc

GBASE亮相联通云巡展(四川站) 以专业赋能云生态

Tell you step by step what you need to do to apply for PMP? What should I do?

Matlab file path
随机推荐
Deep browser rendering principles
[Qt5] small software with 5 people randomly selected from the bid evaluation expert base
Window 2 - > toolbar (28-1)
How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)
sql server时间字段排序
Enum class
优炫数据库导入和导出方法
uniapp的swiper动态设置current值不生效解决办法
机器学习如何做到疫情可视化——疫情数据分析与预测实战
半桥BUCK电路—记录篇
SQL function
pyspark更改列顺序存入iceberg数据库
Prescan quick start to master the road elements of lecture 15
MCU IO port controls 12V voltage on and off, MOS and triode circuit
(Reprinted) plantuml Quick Guide
ASP. Net core foundation IV
学术界爆火的类脑智能,啥时候能落地?来听行业大咖怎么说丨量子位·对撞派 x 时识科技...
VK1620温控仪/智能电表LED数显驱动芯片3/4线接口内置 RC振荡器,提供技术支持
OSPF comprehensive experiment (7.12)
2018年1月西邻雪山自驾游攻略