2.0.0 • Published 6 years ago

hugo-lunr-zh v2.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

Hugo lunr zh

Generate lunr.js index file for hugo static site with Chinese support.

Install

globally:

npm install -g hugo-lunr-zh

or as a dev dependence:

npm install -D hugo-lunr-zh

Usage

your can use it in command line:

hugo-lunr-zh  -o docs/lunr.json --matter-delims --- --matter-type yaml

or run it in file:

const lunr = require("hugo-lunr-zh");
lunr({
  output: "docs/index.json"
}).then(() => {
  console.log("done");
});

after generating the index file, you need extend the lunr object with a new trimmer on the browser side:

lunr.zh = function() {
  this.pipeline.reset();
  this.pipeline.add(lunr.zh.trimmer, lunr.stopWordFilter, lunr.stemmer);
};

lunr.zh.trimmer = function(token) {
  return token.update(str => {
    if (/[\u4E00-\u9FA5\uF900-\uFA2D]/.test(str)) return str;
    return str.replace(/^\W+/, "").replace(/\W+$/, "");
  });
};
 
lunr.Pipeline.registerFunction(lunr.zh.trimmer, "trimmer-zh");
 
//...
const index = lunr(function() {
  this.use(lunr.zh);
  //...
});

Output Format

[
  {
    uri: "contextPath/pagename",
    tags: "the tags list",
    oriTitle: "the original post title for display",
    title: "segmented post title, Chinese keywords are seperated by spaces",
    content: "segmented post content, Chinese keywords are seperated by spaces"
  }
];

Options

the default:

{
  contextPath: "/posts",
  dir: "content/posts",
  output: "public/index.json",
  matterType: "toml",
  matterDelims: "+++",
  skipDraft: true,
  extensions: ".md",
  jiebaConf: {}
}

contextPath -c

the context path of the uri link

dir -d

the directory of your posts. note: it can't search recursively.

output -o

the output filepath, eg: your_publishDir/index.json

skipDraft -s

if skip the drafts?

matterType --matter-type

specify the type of front matter. avaliable values: toml, yaml, json

matterDelims --matter-delims

specify the delims type of front matter. default is +++

extensions --ext

the accepted extensions , multi extensions should be separated by a comma, eg: .md,.html

jiebaConf --jieba

the nodejieba configuration object, the object should be stringify. more info: https://github.com/yanyiwu/nodejieba

Issues

please submit your issues to https://github.com/stkevintan/hugo-lunr-zh/issues

2.0.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago