Skip to content

Commit

Permalink
Add content option for #46.
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Sep 14, 2018
1 parent 4d9fb16 commit debd8e5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ You can configure this plugin in your root `_config.yml`.
search:
path: search.xml
field: post
content: true
```
- **path** - file path. By default is `search.xml` . If the file extension is `.json`, the output format will be JSON. Otherwise XML format file will be exported.
- **field** - the search scope you want to search, you can chose:
* **post** (Default) - will only covers all the posts of your blog.
* **page** - will only covers all the pages of your blog.
* **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`.

## FAQ

Expand Down
7 changes: 4 additions & 3 deletions lib/json_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function(locals){
var config = this.config;
var searchConfig = config.search;
var searchfield = searchConfig.field;
var content = searchConfig.content;

var posts, pages;

Expand All @@ -30,11 +31,11 @@ module.exports = function(locals){
var temp_post = new Object()
if (post.title) {
temp_post.title = post.title
}
}
if (post.path) {
temp_post.url = config.root + post.path
}
if (post._content) {
if (content != false && post._content) {
temp_post.content = post._content
}
if (post.tags && post.tags.length > 0) {
Expand Down Expand Up @@ -66,7 +67,7 @@ module.exports = function(locals){
if (page.path) {
temp_page.url = config.root + page.path
}
if (page._content) {
if (content != false && page._content) {
temp_page.content = page._content
}
if (page.tags && page.tags.length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions lib/xml_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module.exports = function(locals){
var searchConfig = config.search;
var template = searchTmpl;
var searchfield = searchConfig.field;
var content = searchConfig.content;
if (content == undefined) content=true;

var posts, pages;

Expand All @@ -41,6 +43,7 @@ module.exports = function(locals){
config: config,
posts: posts,
pages: pages,
content: content,
url: config.root
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-generator-search",
"version": "2.2.5",
"version": "2.3.0",
"description": "Seach generator plugin for Hexo",
"main": "index",
"directories": {
Expand Down
8 changes: 6 additions & 2 deletions templates/search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<title>{{ post.title }}</title>
<link href="{{ (url + post.path) | uriencode }}"/>
<url>{{ (url + post.path) | uriencode }}</url>
<content type="html"><![CDATA[{{ post.content | noControlChars | safe }}]]></content>
{% if content %}
<content type="html"><![CDATA[{{ post.content | noControlChars | safe }}]]></content>
{% endif %}
{% if post.categories and post.categories.length>0 %}
<categories>
{% for cate in post.categories.toArray() %}
Expand All @@ -30,7 +32,9 @@
<title>{{ page.title }}</title>
<link href="{{ (url + page.path) | uriencode }}"/>
<url>{{ (url + page.path) | uriencode }}</url>
<content type="html"><![CDATA[{{ page.content | noControlChars | safe }}]]></content>
{% if content %}
<content type="html"><![CDATA[{{ page.content | noControlChars | safe }}]]></content>
{% endif %}
</entry>
{% endfor %}
{% endif %}
Expand Down

0 comments on commit debd8e5

Please sign in to comment.