hexo-function

Hexo 功能启用

  • 原文地址:
  • 原文作者:
  • 本文永久链接:
特别说明

当前文章内容迁移中,如有问题,请提交 issues 谢谢~~

搜索功能

var stripe_code_line_num = function(str) { // 去除代码
    return str.replace(/<figure class="highlight.*?<\/figure>/ig, '');
&#125;
var stripe = function (str) &#123; // 去除html标签
    return str.replace(/(<([^>]+)>)/ig, '');
&#125;
var minify = function (str) &#123; // 压缩成一行
    return str.trim().replace(/\n/g, ' ').replace(/\s+/g, ' ');
&#125;

module.exports = function(locals) &#123;
  var config = this.config;
  var database = require('./database')(locals, config);
  database.forEach( function(element, index) &#123;
    element.content = minify(stripe(stripe_code_line_num(element.content)));
  &#125;);
  var xml = searchTmpl.render(&#123;
    articles: database,
    config  : config.search
  &#125;);
  return &#123;
    path: config.search.path,
    data: xml
  &#125;;
&#125;;
Prev:
hexo-rss
Next:
hexo-seo 优化
Contents of this article
Contents of this article