ChrAlpha / hexo-theme-cards

Another Simple & Swift theme for Hexo
https://theme-cards.ichr.me
GNU General Public License v3.0
421 stars 47 forks source link

关于search功能的配置 #91

Closed majikoo1028 closed 3 years ago

majikoo1028 commented 3 years ago

search功能应该咋配置,我search功能置true后只能打开search页面,搜索站内内容的时候没有显示搜索结果

ChrAlpha commented 3 years ago

如果搜索了不存在的内容自然是不会有结果的,你可以点击以下两个链接对比下

https://blog.ichr.me/search/?s=hexo

https://blog.ichr.me/search/?s=blablabla

关于无结果的反馈正在考虑中

majikoo1028 commented 3 years ago

内容存在我是可以肯定地,我感觉应该是哪的配置出了问题,我看博主你的就有结果反馈

majikoo1028 commented 3 years ago

这是我博客,博主有空可以去看看https://unbelievable.cool/,搜索用不了有点苦恼...

ChrAlpha commented 3 years ago

image

这里出错了,能否提供主题目录下 layout/_plugins/search/local-search/source.ejs 文件及主题配置文件中的 search.pathvendors.local_search 两项配置以供排错?

majikoo1028 commented 3 years ago

这是source.ejs

<div id="search-card">
    <form class="search-form" autocomplete="off">
        <div class="search-input">
            <input maxlength="80" type="search" class="search-input" id="search-input" name="s" placeholder="<%= __('search.placeholder') %>" required>
        </div>
        <div class="search-button">
            <button class="search-button " type="submit"><%= __('search.main') %></button>
        </div>
    </form>
</div>
<div id="search-result"></div>
<script>var searchDataFile = "<%= url_for(theme.search.path) %>";</script>
<script defer src="<%= url_for(theme.vendors.local_search || 'js/local-search.js') %>"></script>

这是另外两个的内容

# 站内搜索插件
search:
  enable: true
  path: \search\
  field: All  # Page | Post | All

local_search: 
    enable: true
ChrAlpha commented 3 years ago

主题配置文件中相关配置改为:

search:
  enable: true
  path: /search.json
  field: All  # Page | Post | All

local_search: js/local-search.js

search.path 必须为 JSON 文件,vendors.local_search 是存放静态资源的地址而非开关,不需要也更不能填 enable: true。参见 主题文档

majikoo1028 commented 3 years ago

解决了!万分感谢!