mirror of https://gitlab.com/curben/blog
fix(feed): compatibility with hexo 4
- permalink variable is now encoded by default - es6-fy - remove categories list
This commit is contained in:
parent
c61fdab84f
commit
8c8c334eaa
|
@ -1,29 +1,29 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
<feed xmlns="https://www.w3.org/2005/Atom">
|
||||||
<title>{{ config.title }}</title>
|
<title>{{ config.title }}</title>
|
||||||
{% if icon %}<icon>{{ icon }}</icon>{% endif %}
|
{% if icon %}<icon>{{ icon }}</icon>{% endif %}
|
||||||
{% if config.subtitle %}<subtitle>{{ config.subtitle }}</subtitle>{% endif %}
|
{% if config.subtitle %}<subtitle>{{ config.subtitle }}</subtitle>{% endif %}
|
||||||
<link href="{{ feed_url | uriencode }}" rel="self"/>
|
<link href="{{ feed_url | uriencode }}" rel="self"/>
|
||||||
{% if config.feed.hub %}<link href="{{ config.feed.hub | uriencode }}" rel="hub"/>{% endif %}
|
{% if config.feed.hub %}<link href="{{ config.feed.hub | uriencode }}" rel="hub"/>{% endif %}
|
||||||
<link href="{{ url }}"/>
|
<link href="{{ url | uriencode }}"/>
|
||||||
<updated>{{ posts.first().date | date }}</updated>
|
<updated>{{ posts.first().updated.toISOString() }}</updated>
|
||||||
<id>{{ url }}</id>
|
<id>{{ url | uriencode }}</id>
|
||||||
{% if config.author %}
|
{% if config.author %}
|
||||||
<author>
|
<author>
|
||||||
<name>{{ config.author }}</name>
|
<name>{{ config.author }}</name>
|
||||||
{% if config.email %}<email>{{ config.email }}</email>{% endif %}
|
{% if config.email %}<email>{{ config.email }}</email>{% endif %}
|
||||||
</author>
|
</author>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<generator uri="http://hexo.io/">Hexo</generator>
|
<generator uri="https://hexo.io/">Hexo</generator>
|
||||||
{% for post in posts.toArray() %}
|
{% for post in posts.toArray() %}
|
||||||
<entry>
|
<entry>
|
||||||
<title>{{ post.title }}</title>
|
<title>{{ post.title }}</title>
|
||||||
<link href="{{ url }}{{ post.path | uriencode }}"/>
|
<link href="{{ post.permalink }}"/>
|
||||||
<id>{{ url }}{{ post.path }}</id>
|
<id>{{ post.permalink }}</id>
|
||||||
<published>{{ post.date | date }}</published>
|
<published>{{ post.date.toISOString() }}</published>
|
||||||
<updated>{% if post.lastUpdated %}{{ post.lastUpdated | date }}{% else %}{{ post.date | date }}{% endif %}</updated>
|
<updated>{% if post.lastUpdated %}{{ post.lastUpdated | date }}{% else %}{{ post.date | date }}{% endif %}</updated>
|
||||||
{% if config.feed.content and post.content %}
|
{% if config.feed.content and post.content %}
|
||||||
<content type="html"><![CDATA[{{ post.more | noControlChars | safe }}]]></content>
|
<content type="html"><![CDATA[{{ post.content | noControlChars | safe }}]]></content>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<summary type="html">
|
<summary type="html">
|
||||||
{% if post.description %}
|
{% if post.description %}
|
||||||
|
@ -47,13 +47,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</summary>
|
</summary>
|
||||||
{% if post.image %}
|
{% if post.image %}
|
||||||
<content src="{{ url }}{{ post.image | uriencode }}" type="image" />
|
<content src="{{ url + post.image | uriencode }}" type="image" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for category in post.categories.toArray() %}
|
|
||||||
<category term="{{ category.name }}" scheme="{{ url }}{{ category.path | uriencode }}"/>
|
|
||||||
{% endfor %}
|
|
||||||
{% for tag in post.tags.toArray() %}
|
{% for tag in post.tags.toArray() %}
|
||||||
<category term="{{ tag.name }}" scheme="{{ url }}{{ tag.path | uriencode }}"/>
|
<category term="{{ tag.name }}" scheme="{{ url + tag.path | uriencode }}"/>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</entry>
|
</entry>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
const nunjucks = require('nunjucks')
|
const nunjucks = require('nunjucks')
|
||||||
const env = new nunjucks.Environment()
|
const env = new nunjucks.Environment()
|
||||||
const pathFn = require('path')
|
const { join } = require('path')
|
||||||
const fs = require('fs')
|
const { readFileSync } = require('fs')
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
|
|
||||||
env.addFilter('uriencode', str => {
|
env.addFilter('uriencode', str => {
|
||||||
|
@ -18,8 +18,8 @@ env.addFilter('date', str => {
|
||||||
return moment(str).format('YYYY-MM-DD[T00:00:00.000Z]')
|
return moment(str).format('YYYY-MM-DD[T00:00:00.000Z]')
|
||||||
})
|
})
|
||||||
|
|
||||||
const atomTmplSrc = pathFn.join(__dirname, './.atom.xml')
|
const atomTmplSrc = join(__dirname, './.atom.xml')
|
||||||
const atomTmpl = nunjucks.compile(fs.readFileSync(atomTmplSrc, 'utf8'), env)
|
const atomTmpl = nunjucks.compile(readFileSync(atomTmplSrc, 'utf8'), env)
|
||||||
|
|
||||||
module.exports = function (locals) {
|
module.exports = function (locals) {
|
||||||
const config = this.config
|
const config = this.config
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* to use post.lastUpdated and remove timezone
|
* to use post.lastUpdated and remove timezone
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const pathFn = require('path')
|
const { extname } = require('path')
|
||||||
|
|
||||||
const config = hexo.config.feed = Object.assign({
|
const config = hexo.config.feed = Object.assign({
|
||||||
type: 'atom',
|
type: 'atom',
|
||||||
|
@ -25,7 +25,7 @@ if (!config.path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add extension name if don't have
|
// Add extension name if don't have
|
||||||
if (!pathFn.extname(config.path)) {
|
if (!extname(config.path)) {
|
||||||
config.path += '.xml'
|
config.path += '.xml'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue