Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add preserve comment option for gulp uglify - bring up search.json generateor - init search page template - some small style changes
- Loading branch information
Showing
15 changed files
with
243 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
archive: 归档 | ||
category: 分类 | ||
search: 搜索 | ||
search_placeholder: 请输入关键字.... | ||
tag: 标签 | ||
nav: | ||
prev_page: 上一页 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div class="container"> | ||
<%- partial('_partial/header', {}, {cache: true}) %> | ||
<div class="main-container"> | ||
<!-- # Input # --> | ||
<div id="search-input"> | ||
<form class="input-group" autocomplete="off"> | ||
<input maxlength="80" type="search" id="search-field" name="s" class="form-input input-lg" placeholder="<%= __('search_placeholder') %>" required> | ||
<button class="btn btn-primary input-group-btn btn-lg"><%= __('search') %></button> | ||
</form> | ||
</div> | ||
<!-- # Description & Output # --> | ||
<div id="search-output"> | ||
<!-- Import Description from markdown --> | ||
<%- page.content %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
String.prototype.queryUrl = function (e) { | ||
var t = this.replace(/^[^?=]*\?/ig, "").split("#")[0], | ||
n = {}; | ||
return t.replace(/(^|&)([^&=]+)=([^&]*)/g, function (e, t, r, i) { | ||
try { | ||
r = decodeURIComponent(r) | ||
} catch (s) { } | ||
try { | ||
i = decodeURIComponent(i) | ||
} catch (s) { } | ||
r in n ? n[r] instanceof Array ? n[r].push(i) : n[r] = [n[r], i] : n[r] = /\[\]$/.test(r) ? [i] : i | ||
}), e ? n[e] : n | ||
}; | ||
var searchQuery = location.search.queryUrl(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<% var res = new Array() -%> | ||
<% var index = 0 -%> | ||
<% if(posts){ -%> | ||
<% posts.each(function(post) { -%> | ||
<% 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) { -%> | ||
<% temp_post.content = post.content.replace(new RegExp('<pre(.*?)\<\/pre\>','gs'),'').replace(new RegExp('<[^>]*>','g'),'').replace(new RegExp('\n','g'),'').replace(new RegExp('<[^>]*>','g'),'') -%> | ||
<% } -%> | ||
<% if (post.tags && post.tags.length > 0) { -%> | ||
<% var tags = new Array() -%> | ||
<% var tag_index = 0 -%> | ||
<% post.tags.each(function (tag) { -%> | ||
<% tags[tag_index] = tag.name; -%> | ||
<% tag_index += 1 -%> | ||
<% }); -%> | ||
<% temp_post.tags = tags -%> | ||
<% } -%> | ||
<% if (post.categories && post.categories.length > 0) { -%> | ||
<% var categories = new Array() -%> | ||
<% var cate_index = 0 -%> | ||
<% post.categories.each(function (cate) { -%> | ||
<% categories[cate_index] = cate.name; -%> | ||
<% cate_index += 1 -%> | ||
<% }); -%> | ||
<% temp_post.categories = categories -%> | ||
<% } -%> | ||
<% res[index] = temp_post; -%> | ||
<% index += 1; -%> | ||
<% }); -%> | ||
<% } -%> | ||
<% if(pages){ -%> | ||
<% pages.each(function(page){ -%> | ||
<% var temp_page = new Object() -%> | ||
<% if (page.title) { -%> | ||
<% temp_page.title = page.title -%> | ||
<% } -%> | ||
<% if (page.path) { -%> | ||
<% temp_page.url = config.root + page.path -%> | ||
<% } -%> | ||
<% if (page._content) { -%> | ||
<% temp_page.content = page.content.replace(new RegExp('<pre(.*?)\<\/pre\>','gs'),'').replace(new RegExp('<[^>]*>','g'),'').replace(new RegExp('\n','g'),'').replace(new RegExp('<[^>]*>','g'),'') -%> | ||
<% } -%> | ||
<% if (page.tags && page.tags.length > 0) { -%> | ||
<% var tags = new Array() -%> | ||
<% var tag_index = 0 -%> | ||
<% page.tags.each(function (tag) { -%> | ||
<% tags[tag_index] = tag.name; -%> | ||
<% tag_index += 1 -%> | ||
<% }); -%> | ||
<% temp_page.tags = tags -%> | ||
<% } -%> | ||
<% if (page.categories && page.categories.length > 0) { -%> | ||
<% var categories = new Array() -%> | ||
<% var cate_index = 0 -%> | ||
<% page.categories.each(function (cate) { -%> | ||
<% categories[cate_index] = cate.name; -%> | ||
<% cate_index += 1 -%> | ||
<% }); -%> | ||
<% temp_page.categories = categories -%> | ||
<% } -%> | ||
<% res[index] = temp_page; -%> | ||
<% index += 1; -%> | ||
<% }); -%> | ||
<% } -%> | ||
<%- stringify(res) -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var ejs = require('ejs'); | ||
var pathFn = require('path'); | ||
var fs = require('fs'); | ||
var stringify = require('json-stringify-safe'); | ||
|
||
var searchTmplSrc = pathFn.join(__dirname, '../../layout/_plugin/search/search-json.ejs'); | ||
var searchTmpl = ejs.compile(fs.readFileSync(searchTmplSrc, 'utf8')); | ||
|
||
module.exports = function (locals) { | ||
var config = this.config; | ||
var searchConfig = config.search; | ||
var template = searchTmpl; | ||
var searchfield = searchConfig.field; | ||
|
||
var posts, pages; | ||
|
||
if (searchfield.trim() != '') { | ||
searchfield = searchfield.trim(); | ||
if (searchfield == 'post') { | ||
posts = locals.posts.sort('-date'); | ||
} else if (searchfield == 'page') { | ||
pages = locals.pages; | ||
} else { | ||
posts = locals.posts.sort('-date'); | ||
pages = locals.pages; | ||
} | ||
} else { | ||
posts = locals.posts.sort('-date'); | ||
} | ||
|
||
var json = template({ | ||
config: config, | ||
posts: posts, | ||
pages: pages, | ||
stringify: stringify, | ||
feed_url: config.root + searchConfig.path, | ||
}); | ||
|
||
return { | ||
path: searchConfig.path, | ||
data: json | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* hexo-generator-search | ||
* author: PaicHyperionDev | ||
* license: MIT | ||
*/ | ||
|
||
var merge = require('utils-merge'); | ||
var pathFn = require('path'); | ||
|
||
var config = hexo.config.search = merge({ | ||
path: 'search.json', | ||
field: 'post' | ||
}, hexo.config.search); | ||
|
||
// Set default search path | ||
if (!config.path) { | ||
config.path = 'search.json'; | ||
} | ||
|
||
// Add extension name if don't have | ||
if (!pathFn.extname(config.path)) { | ||
config.path += '.json'; | ||
} | ||
|
||
if (pathFn.extname(config.path) == '.json') { | ||
hexo.extend.generator.register('json', require('./json_generator')); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/*! | ||
* Hexo Theme Suka | local-search.js | ||
* Author: SukkaW | ||
* Link: https://github.com/SukkaW/hexo-theme-suka | ||
* License: GPL-3.0 | ||
*/ |
Oops, something went wrong.