-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
feed.js
78 lines (63 loc) · 2.11 KB
/
feed.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const Feed = require('feed');
const chalk = require('chalk');
const CWD = process.cwd();
const siteConfig = require(CWD + '/siteConfig.js');
const blogFolder = path.resolve('../blog/');
const blogRootURL = siteConfig.url + siteConfig.baseUrl + 'blog';
const siteImageURL =
siteConfig.url + siteConfig.baseUrl + siteConfig.headerIcon;
const utils = require('../core/utils');
const renderMarkdown = require('../core/renderMarkdown.js');
/****************************************************************************/
let readMetadata;
let Metadata;
readMetadata = require('./readMetadata.js');
readMetadata.generateMetadataDocs();
Metadata = require('../core/metadata.js');
/****************************************************************************/
module.exports = function(type) {
console.log('feed.js triggered...');
type = type || 'rss';
readMetadata.generateMetadataBlog();
const MetadataBlog = require('../core/MetadataBlog.js');
const feed = new Feed({
title: siteConfig.title + ' Blog',
description:
'The best place to stay up-to-date with the latest ' +
siteConfig.title +
' news and events.',
id: blogRootURL,
link: blogRootURL,
image: siteImageURL,
copyright: siteConfig.copyright,
updated: new Date(MetadataBlog[0].date),
});
MetadataBlog.forEach(post => {
const url = blogRootURL + '/' + post.path;
const content = utils.blogPostHasTruncateMarker(post.content)
? utils.extractBlogPostBeforeTruncate(post.content)
: utils.extractBlogPostSummary(post.content.trim());
feed.addItem({
title: post.title,
link: url,
author: [
{
name: post.author,
link: post.authorURL,
},
],
date: new Date(post.date),
description: renderMarkdown(content),
});
});
return type === 'rss' ? feed.rss2() : feed.atom1();
};