当前位置:网站首页>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 .
边栏推荐
- No super high-rise buildings | new regulations: what information does it reveal that no new buildings above 500 meters should be built?
- Deluxe H5 Tetris game source code
- Meituan Er Mian: why does redis have sentinels?
- Spiral matrix
- There are two Kafka topics that need to write data intact to MySQL King through Flink. Scheme 1: write two f's
- 学术界爆火的类脑智能,啥时候能落地?来听行业大咖怎么说丨量子位·对撞派 x 时识科技...
- (Reprinted) plantuml Quick Guide
- [Err] 1055 - Expression#2 of select list is not in GROUP BY clause and contains nonaggregated column
- Openstack dashboard configuring public network access
- Prescan quick start to proficient in lecture 17, speed curve editor
猜你喜欢

解决EMC、EMI传导干扰的八大方法

Chairman tree review

机器学习如何做到疫情可视化——疫情数据分析与预测实战
![[Qt5] QT small software release](/img/83/9867bd4513caadac6a056c801abe48.png)
[Qt5] QT small software release

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

Recommend a fully open source, feature rich, beautiful interface mall system

二维数组及操作
![[Qt5] a method of multi window parameter transmission (using custom signal slot) and case code download](/img/6d/870add6179f0e3a2f9b719f79594f3.png)
[Qt5] a method of multi window parameter transmission (using custom signal slot) and case code download

竞赛:糖尿病遗传风险检测挑战赛(科大讯飞)

网口网络水晶头RJ45、POE接口定义线序
随机推荐
[Qt5] QT small software release
Es6: template string
Allure use
Can a flinksql script write insert statements for two tables?
What if you are prompted that your connection to this website is not a private connection?
【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
sparksql 与flinksql 建表 与 连表记录
单片机IO口控制12V电压通断,MOS和三极管电路
Matlab (3) matlab program flow control statement
Matlab file path
[reprint] man Rsync translation (Chinese Manual of Rsync command)
49-OpenCv深入分析轮廓
ASP. Net core foundation V
‘全局事件总线’&‘消息订阅与发布’
Can the variable modified by final be modified
Characteristics of EMC EMI beads
How to write a JMeter script common to the test team
CI框架如何集成Smarty模板
PostgreSQL is the world's most advanced open source relational database
ASP. Net core foundation IV