From 06d197c3b4e36ff824041c6d77cefd4d65e679d3 Mon Sep 17 00:00:00 2001 From: gautamkrishnar Date: Sat, 6 Nov 2021 19:15:34 +0530 Subject: [PATCH] added categories support, fixes: #105 --- README.md | 2 +- blog-post-workflow.js | 5 ++++- test/Readme.categories.md.snap | 6 ++++++ test/test.js | 10 ++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100755 test/Readme.categories.md.snap diff --git a/README.md b/README.md index fd80259..c53e492 100644 --- a/README.md +++ b/README.md @@ -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 (``), 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.

**Supported variables** | 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.

**Supported variables** | 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 | diff --git a/blog-post-workflow.js b/blog-post-workflow.js index b99556d..f4bd781 100644 --- a/blog-post-workflow.js +++ b/blog-post-workflow.js @@ -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) { @@ -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 diff --git a/test/Readme.categories.md.snap b/test/Readme.categories.md.snap new file mode 100755 index 0000000..f5f8920 --- /dev/null +++ b/test/Readme.categories.md.snap @@ -0,0 +1,6 @@ +# Readme test +Post list example: +chrome, firefox, devtools, webdevtrick, chrome, privacy, httpsmicrosoft, student, partner, mspnumpy, python, introductionintroductionsduckduckgo, searching, tips, privacy + +# Other contents +Test content diff --git a/test/test.js b/test/test.js index 0559cd9..a7bfef9 100644 --- a/test/test.js +++ b/test/test.js @@ -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); + }); });