-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
54 lines (45 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const title = require('get-md-title');
const desc = require('get-md-desc');
const RSS = require('rss');
const write = require('fs').writeFileSync;
const path = require('path');
const parse = require('url').parse;
// Define variables
let site, feed;
module.exports = {
website: {
assets: './assets',
js: [ 'plugin.js' ],
},
hooks: {
// Get and init RSS configuration
init() {
site = this.config.get('pluginsConfig.rss');
feed = new RSS(site);
},
// Collect all pages
['page:before'](page) {
// If README.md, then change it to root
const url = site.site_url +
( page.path === 'README.md'
? ''
: page.path.replace(/.md$/, '.html'));
const pageTitle = title(page.content);
const pageDescription = desc(page.content);
feed.item({
title: pageTitle ? pageTitle.text : '',
description: pageDescription ? pageDescription.text : '',
url: url,
author: site.author,
});
return page;
},
// Generate XML and write to file
finish() {
const xml = feed.xml({ indent: true });
const feedpath = path.basename(parse(site.feed_url).pathname);
return write(path.resolve(this.options.output, feedpath), xml, 'utf-8');
},
}
};