Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dgrigg/hugo-lunr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: gwleclerc/lunr-hugo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 16, 2016

  1. feat: add yaml support

    Leclerc Gwendal committed Apr 16, 2016
    Copy the full SHA
    fd6f802 View commit details

Commits on Jul 6, 2016

  1. feat: change version to 0.1.0

    Leclerc Gwendal committed Jul 6, 2016
    Copy the full SHA
    1946a4f View commit details
  2. feat: modify readme + license to change repository name

    Leclerc Gwendal committed Jul 6, 2016
    Copy the full SHA
    d63d25d View commit details
  3. chore: bump to 0.1.1

    Leclerc Gwendal committed Jul 6, 2016
    Copy the full SHA
    6a34b5d View commit details
  4. chore: bump to 0.1.2

    Leclerc Gwendal committed Jul 6, 2016
    Copy the full SHA
    4010489 View commit details
Showing with 49 additions and 20 deletions.
  1. +13 −0 LICENSE.md
  2. +14 −12 README.md
  3. +17 −1 lib/index.js
  4. +5 −7 package.json
13 changes: 13 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (C) 2016 dgrigg

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# hugo-lunr
# lunr-hugo
## Generate lunr.js index files from Hugo static sites
A simple way to add site search to your static [Hugo](https://gohugo.io/) site using [Lunr.js](http://lunrjs.com/).

## Installation

Install the hugo-lunr utility via [npm](http://npmjs.org/):
Install the lunr-hugo utility via [npm](http://npmjs.org/):

```
$ npm install hugo-lunr
$ npm install lunr-hugo
```

## Options
By default hugo-lunr will read the `content` directory of you and output the lunr index to `public/lunr.json`. If you are using the command line implementation you can pass an input directory `-i` and and output path/file `-o`.
By default lunr-hugo will read the `content` directory of you and output the lunr index to `public/lunr.json`. If you are using the command line implementation you can pass an input directory `-i` and and output path/file `-o`.


## How to use hugo-lunr CLI
The easiest way to use hugo-lunr is via npm scripts:
## How to use lunr-hugo CLI
The easiest way to use lunr-hugo is via npm scripts:
```
"scripts": {
"index": "hugo-lunr"
"index": "lunr-hugo"
},
```

or to pass arguments for input and output:

```
"scripts": {
"index": "hugo-lunr -i \"content/subdir/**\" -o public/my-index.json"
"index": "lunr-hugo -i \"content/subdir/**\" -o public/my-index.json"
},
```

@@ -35,20 +35,22 @@ Which can be executed from a terminal prompt
$ npm run index
```

## How to use hugo-lunr API
## How to use lunr-hugo API
```javascript
var hugolunr = require('hugo-lunr');
var hugolunr = require('lunr-hugo');
new hugolunr().index();
```

or to set input/output paths

```javascript
var hugolunr = require('hugo-lunr');
var hugolunr = require('lunr-hugo');
var h = new hugolunr();
h.setInput('content/faq/**');
h.setOutput('public/faq.json');
h.index();
```


# License
This project is a fork from https://github.com/dgrigg/hugo-lunr
It is under ISC License. Check LICENSE.md for more information.
18 changes: 17 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ function HugoLunr(input, output){
//defaults
this.input = 'content/**';
this.output = 'public/lunr.json';
this.delims = '+++'
this.lang = 'toml'

if(process.argv.indexOf("-o") != -1){ //does output flag exist?
this.setOutput(process.argv[process.argv.indexOf("-o") + 1]); //grab the next item
@@ -30,6 +32,10 @@ function HugoLunr(input, output){
this.setInput(process.argv[process.argv.indexOf("-i") + 1]); //grab the next item
}

if(process.argv.indexOf("-l") != -1){ //does lang flag exist?
this.setFrontMatter(process.argv[process.argv.indexOf("-l") + 1]); //grab the next item
}

this.baseDir = path.dirname(this.input);
}

@@ -41,6 +47,16 @@ HugoLunr.prototype.setOutput = function(output) {
this.output = output;
}

HugoLunr.prototype.setFrontMatter = function(frontMatter) {
if (frontMatter === "yaml") {
this.delims = '---'
this.lang = 'yaml'
} else {
this.delims = '+++'
this.lang = 'toml'
}
}

HugoLunr.prototype.index = function(input, output){
var self = this;

@@ -76,7 +92,7 @@ HugoLunr.prototype.readDirectory = function(path){
HugoLunr.prototype.readFile = function(filePath){
var self = this;
var ext = path.extname(filePath);
var meta = matter.read(filePath, {delims: '+++', lang:'toml'});
var meta = matter.read(filePath, {delims: self.delims, lang: self.lang});
if (meta.data.draft === true){
return;
}
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "hugo-lunr",
"version": "0.0.3",
"name": "lunr-hugo",
"version": "0.1.2",
"description": "create lunr index file for hugo static site search",
"repository": {
"type": "git",
"url": "git+https://github.com/dgrigg/hugo-lunr.git"
"url": "git+https://github.com/gwleclerc/hugo-lunr.git"
},
"homepage": "https://github.com/dgrigg/hugo-lunr",
"homepage": "https://github.com/gwleclerc/hugo-lunr",
"main": "lib/index.js",
"bin": {
"hugo-lunr": "bin/index.js"
"lunr-hugo": "bin/index.js"
},
"scripts": {
"test": "bin/index.js ",
@@ -26,5 +26,3 @@
"toml": "^2.3.0"
}
}