Skip to content

Commit

Permalink
Merge pull request #21 from pjlamb12/filename-config
Browse files Browse the repository at this point in the history
Filename Set from Config
  • Loading branch information
marcjulian authored Dec 2, 2020
2 parents e00bc68 + 24449b4 commit 520be1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 5 additions & 1 deletion plugins/rss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The rss feed is available at:
- your-domain.de/feed.atom
- your-domain.de/feed.xml

To change the filename of the feed, use the `filename` attribute in your rss.config.json file, as seen below. The default value is feed, but you can change it to whatever you'd like.

> **Breaking Change** introduced in Version 1.0.0 with changing the plugin type from `render` to `routeDiscoveryDone`. This has the major benefit of only generating the RSS Feed once per run instead of after each page render.
## 📦 Installation
Expand Down Expand Up @@ -53,9 +55,11 @@ Create a `rss.config.json` in your root with the following properties:
"favicon": "https://you-domain.com/favicon.png",
"copyright": "2020 your-domain.com",
"generator": "Page description",
"filename": "feed",
"feedLinks": {
"atom": "https://your-domain.com/feed.atom",
"json": "https://your-domain.com/feed.json",
"atom": "https://your-domain.com/feed.atom"
"xml": "https://your-domain.com/feed.xml"
},
"outDir": "./dist/static",
"categories": ["Categories", "of", "your", "choice"],
Expand Down
13 changes: 7 additions & 6 deletions plugins/rss/src/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { log, logError, yellow } = require('@scullyio/scully');
const configFile = readFileSync(`${process.cwd()}/rss.config.json`, 'utf8');
const config = JSON.parse(configFile.toString());
const blogPostRouteSlug = config.blogPostRouteSlug || '/blog';
const filename = config.filename || 'feed';
const feed = new Feed(config);

config.categories.forEach((cat) => {
Expand Down Expand Up @@ -42,12 +43,12 @@ const rssPlugin = (routes) => {
feed.addItem(item);
});
try {
writeFileSync(join(config.outDir || '', 'feed.xml'), feed.rss2());
log(`✅ Created ${yellow(config.outDir + '/feed.xml')}`);
writeFileSync(join(config.outDir || '', 'feed.atom'), feed.atom1());
log(`✅ Created ${yellow(config.outDir + '/feed.atom')}`);
writeFileSync(join(config.outDir || '', 'feed.json'), feed.json1());
log(`✅ Created ${yellow(config.outDir + '/feed.json')}`);
writeFileSync(join(config.outDir || '', `${filename}.xml`), feed.rss2());
log(`✅ Created ${yellow(config.outDir + `/${filename}.xml`)}`);
writeFileSync(join(config.outDir || '', `${filename}.atom`), feed.atom1());
log(`✅ Created ${yellow(config.outDir + `/${filename}.atom`)}`);
writeFileSync(join(config.outDir || '', `${filename}.json`), feed.json1());
log(`✅ Created ${yellow(config.outDir + `/${filename}.json`)}`);
} catch (error) {
logError('❌ Failed to create RSS feed. Error:', error);
throw error;
Expand Down
4 changes: 3 additions & 1 deletion rss.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"favicon": "https://notiz.dev/favicon.png",
"copyright": "2020 notiz.dev",
"generator": "Weeklyish Articles about Web Development",
"filename": "feed",
"feedLinks": {
"atom": "https://notiz.dev/feed.atom",
"json": "https://notiz.dev/feed.json",
"atom": "https://notiz.dev/feed.atom"
"xml": "https://notiz.dev/feed.xml"
},
"outDir": "./dist/static",
"categories": ["Web Development", "Blog", "Angular", "node"]
Expand Down

0 comments on commit 520be1a

Please sign in to comment.