Skip to content

Commit

Permalink
Add a front matter setting to exclude indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Dec 22, 2018
1 parent 4396778 commit ecf4038
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 4 additions & 2 deletions lib/json_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion templates/search.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<search>
{% if posts %}
{% for post in posts.toArray() %}
{% for post in posts.toArray() %}
{% if post.indexing == undefined or post.indexing %}
<entry>
<title>{{ post.title }}</title>
<link href="{{ (url + post.path) | uriencode }}"/>
Expand All @@ -24,10 +25,12 @@
</tags>
{% endif %}
</entry>
{% endif %}
{% endfor %}
{% endif %}
{% if pages %}
{% for page in pages.toArray() %}
{% if post.indexing == undefined or post.indexing %}
<entry>
<title>{{ page.title }}</title>
<link href="{{ (url + page.path) | uriencode }}"/>
Expand All @@ -36,6 +39,7 @@
<content type="html"><![CDATA[{{ page.content | noControlChars | safe }}]]></content>
{% endif %}
</entry>
{% endif %}
{% endfor %}
{% endif %}
</search>

1 comment on commit ecf4038

@wzpan
Copy link
Owner Author

@wzpan wzpan commented on ecf4038 Dec 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed #49.

Please sign in to comment.