定制文章内容xml模板
This commit is contained in:
parent
2b635d6783
commit
da0530d37a
@ -101,7 +101,7 @@ ICP: 鲁ICP备19028444号
|
||||
# 站点地图
|
||||
sitemap:
|
||||
path: sitemap.xml
|
||||
template: ./sitemap_template.xml
|
||||
template: ./templates/sitemap.xml
|
||||
baidusitemap:
|
||||
path: baidusitemap.xml
|
||||
|
||||
@ -125,9 +125,3 @@ jsonContent:
|
||||
excerpt: false
|
||||
categories: true
|
||||
tags: true
|
||||
|
||||
# hexo-generator-search
|
||||
search:
|
||||
path: search.xml
|
||||
field: post
|
||||
content: true
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
"hexo-generator-feed": "^1.2.2",
|
||||
"hexo-generator-index": "^0.2.1",
|
||||
"hexo-generator-json-content": "^4.1.3",
|
||||
"hexo-generator-search": "^2.4.0",
|
||||
"hexo-generator-sitemap": "^1.2.0",
|
||||
"hexo-generator-tag": "^0.2.0",
|
||||
"hexo-renderer-ejs": "^0.3.1",
|
||||
@ -31,6 +30,7 @@
|
||||
"gulp-htmlclean": "^2.7.22",
|
||||
"gulp-htmlmin": "^5.0.1",
|
||||
"gulp-plumber": "^1.2.1",
|
||||
"nunjucks": "^3.2.0",
|
||||
"optimist": "^0.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
23
scripts/generator.js
Normal file
23
scripts/generator.js
Normal file
@ -0,0 +1,23 @@
|
||||
const nunjucks = require('nunjucks')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const env = new nunjucks.Environment()
|
||||
env.addFilter('noControlChars', function(str) {
|
||||
return str && str.replace(/[\x00-\x1F\x7F]/g, '')
|
||||
})
|
||||
|
||||
const searchTmplSrc = path.join(__dirname, '../templates/articles.xml')
|
||||
|
||||
hexo.extend.generator.register('xml', function(locals){
|
||||
const searchTmpl = nunjucks.compile(fs.readFileSync(searchTmplSrc, 'utf8'), env)
|
||||
const posts = locals.posts.sort('-date');
|
||||
const xmlData = searchTmpl.render({
|
||||
posts: posts,
|
||||
root: this.config.root
|
||||
})
|
||||
return {
|
||||
path: 'articles.xml',
|
||||
data: xmlData
|
||||
}
|
||||
})
|
||||
30
templates/articles.xml
Normal file
30
templates/articles.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<search>
|
||||
{% for post in posts.toArray() %}
|
||||
{% if post.indexing == undefined or post.indexing %}
|
||||
<entry>
|
||||
<title>{{ post.title }}</title>
|
||||
<link href="{{ root + post.path }}"/>
|
||||
<path>{{ post.path }}</path>
|
||||
{% if post.categories and post.categories.length>0 %}
|
||||
<categories>
|
||||
{% for cate in post.categories.toArray() %}
|
||||
<category> {{ cate.name }} </category>
|
||||
{% endfor %}
|
||||
</categories>
|
||||
{% endif %}
|
||||
{% if post.tags and post.tags.length>0 %}
|
||||
<tags>
|
||||
{% for tag in post.tags.toArray() %}
|
||||
<tag> {{ tag.name }} </tag>
|
||||
{% endfor %}
|
||||
</tags>
|
||||
{% endif %}
|
||||
{% if post.date %}
|
||||
<date>{{ +post.date }}</date>
|
||||
{% endif %}
|
||||
<content type="html"><![CDATA[{{ post.content | noControlChars | safe }}]]></content>
|
||||
</entry>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</search>
|
||||
10
yarn.lock
10
yarn.lock
@ -1514,14 +1514,6 @@ hexo-generator-json-content@^4.1.3:
|
||||
keyword-extractor latest
|
||||
moment latest
|
||||
|
||||
hexo-generator-search@^2.4.0:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/hexo-generator-search/-/hexo-generator-search-2.4.0.tgz#f5abbbbbe35299f52c2554bb89845d0a4fab6c9b"
|
||||
integrity sha512-470q6Cpu6xHIPMXN+rQjCQkn/ii4e8XJRBXCmKs+B1jGQNrT7K3geqfyd5pqGiGi6bh5yY+mNqwGw5r2sZZtzA==
|
||||
dependencies:
|
||||
nunjucks "^3.0.1"
|
||||
utils-merge "^1.0.0"
|
||||
|
||||
hexo-generator-sitemap@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/hexo-generator-sitemap/-/hexo-generator-sitemap-1.2.0.tgz#3018f8d7d1e2e42b3f71a65a7316ffcf583bc3f3"
|
||||
@ -2481,7 +2473,7 @@ nunjucks@^2.3.0:
|
||||
chokidar "^1.6.0"
|
||||
yargs "^3.32.0"
|
||||
|
||||
nunjucks@^3.0.0, nunjucks@^3.0.1, nunjucks@^3.1.2:
|
||||
nunjucks@^3.0.0, nunjucks@^3.1.2, nunjucks@^3.2.0:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/nunjucks/-/nunjucks-3.2.0.tgz#53e95f43c9555e822e8950008a201b1002d49933"
|
||||
dependencies:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user