Skip to content

Commit

Permalink
added categories support, fixes: #105
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamkrishnar committed Nov 6, 2021
1 parent f111054 commit 06d197c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This workflow has additional options that you can use to customize it for your u
| `comment_tag_name` | `BLOG-POST-LIST` | Allows you to override the default comment tag name (`<!-- BLOG-POST-LIST:START --><!-- BLOG-POST-LIST:END -->`), if you want to show multiple instances of the action on the same repo, see advanced usage for more info | No |
| `disable_sort` | `false` | Disables the sorting of the list based on publish date | No |
| `feed_names` | `""` | Comma-separated list of RSS feed names, this is intended to be used with `template` option. eg: `Blog,Dev.to` | No |
| `template` | `default` | Allows you to change the structure of the posts list by using different variables. By default this workflow uses markdown list format to render the posts, you can override this behavior using this option. Eg: `[$title]($url) ` will give you a space-separated list of posts.<br/><br/>**Supported variables** <ul><li>`$title`: Title of the post</li><li>`$url`: URL of the post</li><li>`$description`: Description of the post</li><li>`$newline`: Inserts a newline</li><li>`$date`: Inserts the post date based on the `date_format` specified</li><li>`$randomEmoji`: Allow you to use random emojis in the post, pass emojis as the parameter to chose one of it randomly in each post item. Eg: `$randomEmoji(💯,🔥,💫,🚀,🌮)`. See the [issue comment](https://github.com/gautamkrishnar/blog-post-workflow/issues/29#issuecomment-699622596) for more details</li><li>`$emojiKey`: You can use this argument to show emojis on each of your post item sequentially in the order you specify. Example: `$emojiKey(💯,🔥,💫)`. See the [issue comment](https://github.com/gautamkrishnar/blog-post-workflow/issues/29#issuecomment-699622596) for more details</li><li>`$counter`: You can use this argument to show a serial number on each of your post items.</li><li>`$feedName`: You can use this argument to show a string that represents your website name, use feed_names argument to specify it for each feed item. Eg: `feed_list: "https://dev.to/feed/gautamkrishnar,https://www.gautamkrishnar.com/feed/"`, `feed_names: "Dev.to,Personal Website"`</li></ul> | No |
| `template` | `default` | Allows you to change the structure of the posts list by using different variables. By default this workflow uses markdown list format to render the posts, you can override this behavior using this option. Eg: `[$title]($url) ` will give you a space-separated list of posts.<br/><br/>**Supported variables** <ul><li>`$title`: Title of the post</li><li>`$url`: URL of the post</li><li>`$description`: Description of the post</li><li>`$newline`: Inserts a newline</li><li>`$date`: Inserts the post date based on the `date_format` specified</li><li>`$randomEmoji`: Allow you to use random emojis in the post, pass emojis as the parameter to chose one of it randomly in each post item. Eg: `$randomEmoji(💯,🔥,💫,🚀,🌮)`. See the [issue comment](https://github.com/gautamkrishnar/blog-post-workflow/issues/29#issuecomment-699622596) for more details</li><li>`$emojiKey`: You can use this argument to show emojis on each of your post item sequentially in the order you specify. Example: `$emojiKey(💯,🔥,💫)`. See the [issue comment](https://github.com/gautamkrishnar/blog-post-workflow/issues/29#issuecomment-699622596) for more details</li><li>`$counter`: You can use this argument to show a serial number on each of your post items.</li><li>`$feedName`: You can use this argument to show a string that represents your website name, use feed_names argument to specify it for each feed item. Eg: `feed_list: "https://dev.to/feed/gautamkrishnar,https://www.gautamkrishnar.com/feed/"`, `feed_names: "Dev.to,Personal Website"`</li><li>`$categories`: You can use this to show a comma separated list of post categories if available. See https://git.io/JXeUG</li></ul> | No |
| `date_format` | `UTC:ddd mmm dd yyyy h:MM TT` | Allows you to change the format of the date or time displayed when using the $date in the template option. This uses NPM dateformat library, please read the library [documentation](https://www.npmjs.com/package/dateformat#named-formats) for the supported formats | No |
| `user_agent` | `rss-parser` | Allows you to customize the user agent used by the RSS feed crawler | No |
| `accept_header` | `application/rss+xml` | Allows you to customize the accept header of the http requests | No |
Expand Down
5 changes: 4 additions & 1 deletion blog-post-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ feedList.forEach((siteUrl) => {
Object.assign(customTags, {[tag]: item[tag]});
}
});
const categories = item.categories ? item.categories : [];
let post = {
title: item.title.trim(),
url: item.link.trim(),
description: item.content ? item.content : '',
...customTags
...customTags,
categories
};

if (ENABLE_SORT) {
Expand Down Expand Up @@ -239,6 +241,7 @@ Promise.allSettled(promiseArray).then((results) => {
.replace(/\$date\b/g, date)
.replace(/\$counter\b/g, (index + 1).toString())
.replace(/\$feedName\b/g, cur.feedName ? cur.feedName : '')
.replace(/\$categories\b/g, cur.categories ? cur.categories.join(', ') : '')
.replace(/\$newline/g, '\n');

// Setting Custom tags to the template
Expand Down
6 changes: 6 additions & 0 deletions test/Readme.categories.md.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Readme test
Post list example:
<!-- BLOG-POST-LIST:START -->chrome, firefox, devtools, webdevtrick, chrome, privacy, httpsmicrosoft, student, partner, mspnumpy, python, introductionintroductionsduckduckgo, searching, tips, privacy<!-- BLOG-POST-LIST:END -->

# Other contents
Test content
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,14 @@ describe('Blog post workflow tests', function () {
};
await runAndCompareSnap('Readme.feedNames.md', envObj);
});

it('Generated readme with categories names should match the snapshot',async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080',
INPUT_TEMPLATE: '$categories',
};
await runAndCompareSnap('Readme.categories.md', envObj);
});
});

0 comments on commit 06d197c

Please sign in to comment.