diff --git a/README.md b/README.md index 2738389..3c503f0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ $ npm install hugo-lunr ``` ## 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 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`. Optionally, you can exclude future ports not marked as draft with the option `-f false`. ## How to use hugo-lunr CLI @@ -48,6 +48,7 @@ var hugolunr = require('hugo-lunr'); var h = new hugolunr(); h.setInput('content/faq/**'); h.setOutput('public/faq.json'); +h.setIncludeFuture(false); // Optional. Default true. h.index(); ``` diff --git a/lib/index.js b/lib/index.js index eaf7f44..8b8f1b4 100755 --- a/lib/index.js +++ b/lib/index.js @@ -22,14 +22,20 @@ function HugoLunr(input, output){ this.input = 'content/**'; this.output = 'public/lunr.json'; - if(process.argv.indexOf("-o") != -1){ //does output flag exist? + if (process.argv.indexOf("-o") != -1){ //does output flag exist? this.setOutput(process.argv[process.argv.indexOf("-o") + 1]); //grab the next item } - if(process.argv.indexOf("-i") != -1){ //does input flag exist? + if (process.argv.indexOf("-i") != -1){ //does input flag exist? this.setInput(process.argv[process.argv.indexOf("-i") + 1]); //grab the next item } + var includeFuture = true; + if (process.argv.indexOf("-f") != -1){ //does input flag exist? + includeFuture = process.argv[process.argv.indexOf("-i") + 1] == "true"; + } + this.setIncludeFuture(includeFuture); + this.baseDir = path.dirname(this.input); } @@ -41,6 +47,10 @@ HugoLunr.prototype.setOutput = function(output) { this.output = output; } +HugoLunr.prototype.setIncludeFuture = function(includeFuture) { + this.includeFuture = includeFuture; +} + HugoLunr.prototype.index = function(input, output){ var self = this; @@ -81,6 +91,14 @@ HugoLunr.prototype.readFile = function(filePath){ return; } + if (!self.includeFuture && meta.data.date !== undefined) { + var contentDate = new Date(meta.data.date) + var currentDate = new Date(); + if (contentDate > currentDate) { + return; + } + } + if (ext == '.md'){ var plainText = removeMd(meta.content); } else { diff --git a/package.json b/package.json index 9262462..25a5f17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hugo-lunr", - "version": "0.0.3", + "version": "0.0.4", "description": "create lunr index file for hugo static site search", "repository": { "type": "git", @@ -12,9 +12,9 @@ "hugo-lunr": "bin/index.js" }, "scripts": { - "test": "bin/index.js ", - "test-args": "bin/index.js -i \"content/**\" -o public/output.json", - "test-api": "bin/api.js" + "test": "node bin/index.js", + "test-args": "node bin/index.js -i \"content/**\" -o public/output.json", + "test-api": "node bin/api.js" }, "author": "Derrick Grigg (http://dgrigg.com)", "license": "ISC", @@ -26,5 +26,3 @@ "toml": "^2.3.0" } } - -