Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from wzpan:master #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ search:
path: search.xml
field: post
content: true
template: ./search.xml
```

- **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.
Expand All @@ -32,6 +33,7 @@ search:
* **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`.
- **template** (Optional) - path to a custom XML template

## Exclude indexing

Expand Down
8 changes: 2 additions & 6 deletions lib/json_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ module.exports = function(locals){
posts.each(function(post) {
if (post.indexing != undefined && !post.indexing) return;
var temp_post = new Object()
if (post.title) {
temp_post.title = post.title
}
temp_post.title = post.title || 'No Title'
if (post.path) {
temp_post.url = config.root + post.path
}
Expand Down Expand Up @@ -61,9 +59,7 @@ module.exports = function(locals){
pages.each(function(page){
if (page.indexing != undefined && !page.indexing) return;
var temp_page = new Object()
if (page.title) {
temp_page.title = page.title
}
temp_post.title = post.title || 'No Title'
if (page.path) {
temp_page.url = config.root + page.path
}
Expand Down
11 changes: 6 additions & 5 deletions lib/xml_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ env.addFilter('noControlChars', function(str) {
return str && str.replace(/[\x00-\x1F\x7F]/g, '');
});

var searchTmplSrc = pathFn.join(__dirname, '../templates/search.xml');
var searchTmpl = nunjucks.compile(fs.readFileSync(searchTmplSrc, 'utf8'), env);

module.exports = function(locals){
var config = this.config;
var searchConfig = config.search;

var searchTmplSrc = searchConfig.template || pathFn.join(__dirname, '../templates/search.xml');
var searchTmpl = nunjucks.compile(fs.readFileSync(searchTmplSrc, 'utf8'), env);

var template = searchTmpl;
var searchfield = searchConfig.field;
var content = searchConfig.content;
Expand All @@ -40,8 +41,8 @@ module.exports = function(locals){
}

var rootURL;
if (config.root == "/" || config.root == null){
rootURL = "";
if (config.root == null){
rootURL = "/";
}else{
rootURL = 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.4.1",
"version": "2.4.3",
"description": "Seach generator plugin for Hexo",
"main": "index",
"directories": {
Expand Down
6 changes: 5 additions & 1 deletion templates/search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
{% for post in posts.toArray() %}
{% if post.indexing == undefined or post.indexing %}
<entry>
<title>{{ post.title }}</title>
{% if post.title %}
<title>{{ post.title }}</title>
{% else %}
<title>No Title</title>
{% endif %}
<link href="{{ (url + post.path) | uriencode }}"/>
<url>{{ (url + post.path) | uriencode }}</url>
{% if content %}
Expand Down