-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d468679
commit e005f07
Showing
8 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module.exports = function(site) { | ||
const RSS = require('rss'); | ||
const fs = require('fs-extra'); | ||
const { BUILD } = require('../utils/constants'); | ||
|
||
try { | ||
let message = 'Generating RSS Feeds.'; | ||
site.logger.await(message); | ||
|
||
let { rss, url, author } = site.getConfig(); | ||
if (!rss) { | ||
site.logger.success(message); | ||
return; | ||
} | ||
|
||
let tags = [...new Set(site.getTags())]; | ||
let posts = site.getPosts(); | ||
|
||
let options = Object.assign({ | ||
categories: tags, | ||
pubDate: new Date() | ||
}, rss); | ||
|
||
let feed = new RSS(options); | ||
|
||
for (let post of posts) { | ||
feed.item({ | ||
title: post.title, | ||
description: post.description, | ||
url: `${url}${post.path}`, | ||
categories: post.tags, | ||
author: post.author || author, | ||
date: post.date | ||
}); | ||
} | ||
|
||
fs.writeFileSync(`${BUILD}/rss.xml`, feed.xml({ indent: true })); | ||
|
||
site.logger.success(message); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require('path'); | ||
|
||
module.exports = function(post, url, skipDirsInPostUrls) { | ||
if (url) { | ||
return url; | ||
} | ||
|
||
let parsedPath = path.parse(post); | ||
let postPath = skipDirsInPostUrls | ||
? parsedPath.name | ||
: path.join(parsedPath.dir, parsedPath.name); | ||
|
||
return postPath; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters