Initial website
This commit is contained in:
15
themes/hueman/scripts/excerpt.js
Normal file
15
themes/hueman/scripts/excerpt.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Excerpt Helper
|
||||
* @description Get the excerpt from a post
|
||||
* @example
|
||||
* <%- excerpt(post) %>
|
||||
*/
|
||||
hexo.extend.helper.register('excerpt', function (post) {
|
||||
var excerpt;
|
||||
if (post.excerpt) {
|
||||
excerpt = post.excerpt.replace(/\<[^\>]+\>/g, '');
|
||||
} else {
|
||||
excerpt = post.content.replace(/\<[^\>]+\>/g, '').substring(0, 200);
|
||||
}
|
||||
return excerpt;
|
||||
});
|
39
themes/hueman/scripts/meta.js
Normal file
39
themes/hueman/scripts/meta.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Meta Helper
|
||||
* @description Generate meta tags for HTML header
|
||||
* @example
|
||||
* <%- meta(post) %>
|
||||
*/
|
||||
function trim (str) {
|
||||
return str.trim().replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1');
|
||||
}
|
||||
|
||||
function split (str, sep) {
|
||||
var result = [];
|
||||
var matched = null;
|
||||
while (matched = sep.exec(str)) {
|
||||
result.push(matched[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
hexo.extend.helper.register('meta', function (post) {
|
||||
var metas = post.meta || [];
|
||||
var output = '';
|
||||
var metaDOMArray = metas.map(function (meta) {
|
||||
var entities = split(meta, /(?:[^\\;]+|\\.)+/g);
|
||||
var entityArray = entities.map(function (entity) {
|
||||
var keyValue = split(entity, /(?:[^\\=]+|\\.)+/g);
|
||||
if (keyValue.length < 2) {
|
||||
return null;
|
||||
}
|
||||
var key = trim(keyValue[0]);
|
||||
var value = trim(keyValue[1]);
|
||||
return key + '="' + value + '"';
|
||||
}).filter(function (entity) {
|
||||
return entity;
|
||||
});
|
||||
return '<meta ' + entityArray.join(' ') + ' />';
|
||||
});
|
||||
return metaDOMArray.join('\n');
|
||||
});
|
17
themes/hueman/scripts/thumbnail.js
Normal file
17
themes/hueman/scripts/thumbnail.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Thumbnail Helper
|
||||
* @description Get the thumbnail url from a post
|
||||
* @example
|
||||
* <%- thumbnail(post) %>
|
||||
*/
|
||||
hexo.extend.helper.register('thumbnail', function (post) {
|
||||
var url = post.thumbnail || '';
|
||||
if (!url) {
|
||||
var imgPattern = /\<img\s.*?\s?src\s*=\s*['|"]?([^\s'"]+).*?\>/ig;
|
||||
var result = imgPattern.exec(post.content);
|
||||
if (result && result.length > 1) {
|
||||
url = result[1];
|
||||
}
|
||||
}
|
||||
return url;
|
||||
});
|
Reference in New Issue
Block a user