Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Sep 2, 2020
1 parent 97d816d commit d8d0cac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
16 changes: 15 additions & 1 deletion lib/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFeedItems = void 0;
exports.sortItems = exports.getFeedItems = void 0;
const rss_parser_1 = __importDefault(require("rss-parser"));
const parser = new rss_parser_1.default({
timeout: 5000
Expand All @@ -27,3 +27,17 @@ function getFeedItems(url) {
});
}
exports.getFeedItems = getFeedItems;
function sortItems(items) {
const mapped = items.map((v, i) => {
if (!v.isoDate) {
throw new Error('cannot perform sort without `date` in your feed');
}
return {
index: i,
date: new Date(v.isoDate)
};
});
mapped.sort((a, b) => b.date.getTime() - a.date.getTime());
return mapped.map((v) => items[v.index]);
}
exports.sortItems = sortItems;
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function run() {
core.error('file is missing.');
return;
}
const sort = core.getInput('sort').toLowerCase() === 'true';
const maxEntry = parseInt(core.getInput('max_entry')) || 5;
const format = process.env['INPUT_FORMAT'] || '- ${monthshort} ${02day} - [${title}](${url})';
const startFlag = core.getInput('start_flag') || '<!-- feed start -->';
Expand Down Expand Up @@ -72,6 +73,15 @@ function run() {
core.error(`failed to get feed: ${e.message}`);
return;
}
if (sort) {
try {
allItems = feed_1.sortItems(allItems);
}
catch (e) {
core.error(`failed to sort feed items: ${e.message}`);
return;
}
}
const items = allItems.slice(0, maxEntry);
const newLines = format_1.formatFeeds(items, format, startFlag, endFlag);
const fnewLines = newLines.join('\n');
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "actions-readme-feed",
"version": "1.1.0",
"version": "1.2.0",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit d8d0cac

Please sign in to comment.