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"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<feed xmlns="https://www.w3.org/2005/Atom">
|
||||
<title>{{ config.title }}</title>
|
||||
{% if icon %}<icon>{{ icon }}</icon>{% endif %}
|
||||
{% if config.subtitle %}<subtitle>{{ config.subtitle }}</subtitle>{% endif %}
|
||||
<link href="{{ feed_url | uriencode }}" rel="self"/>
|
||||
{% if config.feed.hub %}<link href="{{ config.feed.hub | uriencode }}" rel="hub"/>{% endif %}
|
||||
<link href="{{ url }}"/>
|
||||
<updated>{{ posts.first().date | date }}</updated>
|
||||
<id>{{ url }}</id>
|
||||
<link href="{{ url | uriencode }}"/>
|
||||
<updated>{{ posts.first().updated.toISOString() }}</updated>
|
||||
<id>{{ url | uriencode }}</id>
|
||||
{% if config.author %}
|
||||
<author>
|
||||
<name>{{ config.author }}</name>
|
||||
{% if config.email %}<email>{{ config.email }}</email>{% endif %}
|
||||
</author>
|
||||
{% endif %}
|
||||
<generator uri="http://hexo.io/">Hexo</generator>
|
||||
<generator uri="https://hexo.io/">Hexo</generator>
|
||||
{% for post in posts.toArray() %}
|
||||
<entry>
|
||||
<title>{{ post.title }}</title>
|
||||
<link href="{{ url }}{{ post.path | uriencode }}"/>
|
||||
<id>{{ url }}{{ post.path }}</id>
|
||||
<published>{{ post.date | date }}</published>
|
||||
<link href="{{ post.permalink }}"/>
|
||||
<id>{{ post.permalink }}</id>
|
||||
<published>{{ post.date.toISOString() }}</published>
|
||||
<updated>{% if post.lastUpdated %}{{ post.lastUpdated | date }}{% else %}{{ post.date | date }}{% endif %}</updated>
|
||||
{% 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 %}
|
||||
<summary type="html">
|
||||
{% if post.description %}
|
||||
|
@ -47,13 +47,10 @@
|
|||
{% endif %}
|
||||
</summary>
|
||||
{% if post.image %}
|
||||
<content src="{{ url }}{{ post.image | uriencode }}" type="image" />
|
||||
<content src="{{ url + post.image | uriencode }}" type="image" />
|
||||
{% endif %}
|
||||
{% for category in post.categories.toArray() %}
|
||||
<category term="{{ category.name }}" scheme="{{ url }}{{ category.path | uriencode }}"/>
|
||||
{% endfor %}
|
||||
{% 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 %}
|
||||
</entry>
|
||||
{% endfor %}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
const nunjucks = require('nunjucks')
|
||||
const env = new nunjucks.Environment()
|
||||
const pathFn = require('path')
|
||||
const fs = require('fs')
|
||||
const { join } = require('path')
|
||||
const { readFileSync } = require('fs')
|
||||
const moment = require('moment')
|
||||
|
||||
env.addFilter('uriencode', str => {
|
||||
|
@ -18,8 +18,8 @@ env.addFilter('date', str => {
|
|||
return moment(str).format('YYYY-MM-DD[T00:00:00.000Z]')
|
||||
})
|
||||
|
||||
const atomTmplSrc = pathFn.join(__dirname, './.atom.xml')
|
||||
const atomTmpl = nunjucks.compile(fs.readFileSync(atomTmplSrc, 'utf8'), env)
|
||||
const atomTmplSrc = join(__dirname, './.atom.xml')
|
||||
const atomTmpl = nunjucks.compile(readFileSync(atomTmplSrc, 'utf8'), env)
|
||||
|
||||
module.exports = function (locals) {
|
||||
const config = this.config
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* to use post.lastUpdated and remove timezone
|
||||
*/
|
||||
|
||||
const pathFn = require('path')
|
||||
const { extname } = require('path')
|
||||
|
||||
const config = hexo.config.feed = Object.assign({
|
||||
type: 'atom',
|
||||
|
@ -25,7 +25,7 @@ if (!config.path) {
|
|||
}
|
||||
|
||||
// Add extension name if don't have
|
||||
if (!pathFn.extname(config.path)) {
|
||||
if (!extname(config.path)) {
|
||||
config.path += '.xml'
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue