diff --git a/README.md b/README.md index 291e53a..ea0f11e 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,23 @@ search: * **all** - will covers all the posts and pages of your blog. - **content** - whether contains the whole content of each article. If `false`, the generated results only cover title and other meta info without mainbody. By default is `true`. +## Exclude indexing + +To exclude a certain post or page from being indexed, you can simply insert `indexing: false` setting at the top of its front-matter, *e.g.*: + +``` +title: "Code Highlight" +date: "2014-03-15 20:17:16" +tags: highlight +categories: Demo +description: "A collection of Hello World applications from helloworld.org." +toc: true +indexing: false +--- +``` + +Then the generated result will not contain this post or page. + ## FAQ ### What's this plugin supposed to do? diff --git a/lib/json_generator.js b/lib/json_generator.js index c1f1c7d..950c63d 100644 --- a/lib/json_generator.js +++ b/lib/json_generator.js @@ -27,7 +27,8 @@ module.exports = function(locals){ var index = 0 if(posts){ - posts.each(function(post) { + posts.each(function(post) { + if (post.indexing != undefined && !post.indexing) return; var temp_post = new Object() if (post.title) { temp_post.title = post.title @@ -57,7 +58,8 @@ module.exports = function(locals){ }); } if(pages){ - pages.each(function(page){ + pages.each(function(page){ + if (page.indexing != undefined && !page.indexing) return; var temp_page = new Object() if (page.title) { temp_page.title = page.title diff --git a/templates/search.xml b/templates/search.xml index 2b44053..07c626a 100644 --- a/templates/search.xml +++ b/templates/search.xml @@ -1,7 +1,8 @@ {% if posts %} - {% for post in posts.toArray() %} + {% for post in posts.toArray() %} + {% if post.indexing == undefined or post.indexing %} {{ post.title }} @@ -24,10 +25,12 @@ {% endif %} + {% endif %} {% endfor %} {% endif %} {% if pages %} {% for page in pages.toArray() %} + {% if post.indexing == undefined or post.indexing %} {{ page.title }} @@ -36,6 +39,7 @@ {% endif %} + {% endif %} {% endfor %} {% endif %}