GithubHelp home page GithubHelp logo

supercatreal / gridea-search Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kytrun/gridea-search

0.0 1.0 0.0 32 KB

Gridea 模糊搜索插件。Fuzzy search plugin for Gridea.

License: MIT License

JavaScript 12.51% HTML 19.45% CSS 68.03%

gridea-search's Introduction

Gridea 静态站点客户端-文章搜索主题插件

预览:https://tangkaichuan.cn,或者下载此项目将 /example 目录置于 Gridea 的 themes 路径,自行运行 Gridea.

特点:

  • 本地缓存索引,加快搜索速度

  • 独立搜索结果页面,可高度复用 post-list 模板

  • 延用官方 API,无附加学习成本

  • 自定义

快速开始:

1. 以官方 主题开发样板 为例,在其基础上新增文件:

 ├── assets
 │   └── media
 │       └── gridea-search
 │           └── result-template.ejs - 搜索结果列表模板
 └── templates
     ├── api-content.ejs - 输出文章内容的 api
     ├── api-info.ejs - 输出整站配置信息的 api,不含文章内容
     └── search.ejs - 搜索页面

2. 修改以下文件

(1) ./templates/includes/header.ejs

公共模板,在适当位置添加搜索框供其他页面引用:

<form id="gridea-search-form" data-update="<%=site.utils.now%>" action="/search/">
  <input name="q" />
</form>

现有部分不可修改,可以添加 class 或 style 等其他属性。

  • 搜索页面模板:search.ejs 中必须包含搜索表单 "gridea-search-form"。如果 search.ejs 包含了公共模板如 header.ejs,则无需额外添加。

(2) ./templates/search.ejs

搜索页面,可基于其他页面修改。

(3) ./assets/media/gridea-search/result-template.ejs

搜索结果列表模板,在浏览器端解析,基本复用 ./templates/includes/post-list.ejs,但修改了摘要内容 <%- post.abstract %><%- post.searchedPreview %>,用于含关键词的搜索结果预览。

  • 搜索结果列表暂无分页功能,请勿使用 pagination 字段。

自定义:

1. 显示搜索中和无搜索结果

<p class="searching">搜索中......</p>
<p class="no-result" style="display:none">未搜索到相关文章</p>
  • 不强制使用 <p> 标签,可以用 <div> 等添加动画或图片。

2. 搜索输入框

<form id="gridea-search-form" data-update="<%=site.utils.now%>" action="/search/">
  <input name="q" />
</form>
  • 保留已有属性如 class、id 等,可新增属性。

3. 关键词高亮

<style>
   .searched-keyword {
     /*Your own CSS for <span> tag here*/
    }
</style>

其他:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.