diff options
-rw-r--r-- | _config.yml | 14 | ||||
-rw-r--r-- | layout/post.ejs | 4 | ||||
-rw-r--r-- | scripts/feed.js | 62 |
3 files changed, 75 insertions, 5 deletions
diff --git a/_config.yml b/_config.yml index 13eea1f..1015b30 100644 --- a/_config.yml +++ b/_config.yml @@ -2,6 +2,7 @@ logo: false timeformat: "MMM, D YYYY" podcast: true lazyload: true +copyright: 'All rights reserved.' highlight: enable: true lightmode: 'atom-one-light' @@ -9,7 +10,14 @@ highlight: navbar: - ['mailto:[email protected]', 'fa fa-paper-plane'] - ['https://github.com/guiqiqi/chromate', 'fa fa-github'] - - ['/feed', 'fa fa-rss'] + - ['/feed/', 'fa fa-rss'] menubar: - - ['/about', '关于'] - - ['/archives', '归档']
\ No newline at end of file + - ['/about/', '关于'] + - ['/archives/', '归档'] +rss: + enable: true + path: '/feed/' + config: + email: '[email protected]' + category: Education + explicit: No
\ No newline at end of file diff --git a/layout/post.ejs b/layout/post.ejs index fa1940a..008b20a 100644 --- a/layout/post.ejs +++ b/layout/post.ejs @@ -24,9 +24,9 @@ container: () => document.querySelector('.post-podcast-player'), audio: { title: "<%= page.title %>", - artist: "<%= page.podcast.author %>", + artist: "<%= page.podcast.authors %>", cover: "<%= page.podcast.cover %>", - src: "<%= page.podcast.media %>" + src: "<%= page.podcast.media.url %>" }, fixed: { type: "auto", diff --git a/scripts/feed.js b/scripts/feed.js new file mode 100644 index 0000000..f60ed90 --- /dev/null +++ b/scripts/feed.js @@ -0,0 +1,62 @@ +'use strict'; + +const xml = require("xml"); +const podcast = require("podcast"); + +hexo.extend.generator.register("feed", (locals) => { + + // Load config + const config = hexo.config; + const theme = hexo.theme.config; + const urler = hexo.extend.helper.get("url_for").bind(hexo); + const strip = hexo.extend.helper.get("strip_html").bind(hexo); + if (!theme.rss || !theme.rss.enable) return; + + // Render for site config + const feed = new podcast({ + title: config.title, + description: config.description, + copyright: theme.copyright, + language: config.language.slice(0, 2), + siteUrl: config.url, + imageUrl: theme.logo, + itunesSubtitle: config.subtitle, + itunesSummary: config.description, + itunesAuthor: config.author, + itunesExplicit: theme.rss.config.explicit, + itunesCategory: theme.rss.config.category, + itunesOwner: { + name: config.author, + email: theme.rss.config.email + } + }); + + // Rendor for podcasts + locals.posts.sort('date', -1).each(function (post) { + if (!post.podcast) return; + feed.addItem({ + title: post.title, + description: post.excerpt, + url: config.url + urler(post.path), + guid: config.url + urler(post.path), + author: post.podcast.authors.join(', '), + date: post.date, + enclosure: { + url: post.podcast.media.url, + type: post.podcast.media.type, + size: post.podcast.media.size + }, + itunesAuthor: post.podcast.authors.join(', '), + itunesExplicit: theme.rss.config.explicit, + itunesSubtitle: post.podcast.subtitle, + itunesSummary: strip(post.excerpt), + itunesCategory: theme.rss.config.category, + itunesDuration: post.podcast.duration + }); + }); + + return { + path: theme.rss.path, + data: feed.buildXml() + }; +}); |