Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
gautamkrishnar committed Aug 7, 2020
2 parents 5ae6524 + 525a384 commit 566f510
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This workflow has additional options that you can use to customize it for your u
| `gh_token` | your github token with repo scope | Use this to configure the token of the user that commits the workflow result to GitHub | No |
| `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 list based on publish date | No |
| `template` | `default` | Allows you to change the structure of the posts list by using the `$title`, `$url` and `$newline` variables. By default this workflow uses markdown list format to render the posts, you can override this behaviour using this option. Eg: `[$title]($url) ` will give you a space separated list of posts | No |
| `commit_message` | `Updated with the latest blog posts` | Allows you to customize the commit message | No |
| `committer_username` | `blog-post-bot` | Allows you to customize the committer username | No |
| `committer_email` | `blog-post-bot@example.com` | Allows you to customize the committer email | No |
Expand Down Expand Up @@ -98,8 +99,8 @@ Following are the list of some popular blogging platforms and their RSS feed url
| [Drupal](https://www.drupal.org/) | `https://www.example.com/rss.xml` | Replace wih your own blog url | https://www.arsenal.com/rss.xml |
| [Youtube Playlists](https://www.youtube.com) | `https://www.youtube.com/feeds/videos.xml?playlist_id=playlistId` | Replace `playlistId` with your own Youtube playlist id | https://www.youtube.com/feeds/videos.xml?playlist_id=PLJNqgDLpd5E69Kc664st4j7727sbzyx0X |
| [Youtube Channel Video list](https://www.youtube.com) | `https://www.youtube.com/feeds/videos.xml?channel_id=channelId` | Replace `channelId` with your own Youtube channel id | https://www.youtube.com/feeds/videos.xml?channel_id=UCDCHcqyeQgJ-jVSd6VJkbCw |
|[Anchor.fm Podcasts](https://anchor.fm/) | `https://anchor.fm/s/podcastId/podcast/rss` | You can get the rss feed url of a podcast by following [these](https://help.anchor.fm/hc/en-us/articles/360027712351-Locating-your-Anchor-RSS-feed) instructions | https://anchor.fm/s/1e784a38/podcast/rss |
|[Hashnode](https://hashnode.com/) | `https://@username.hashnode.dev/rss.xml` | Replace @username with your hasnode username | https://polilluminato.hashnode.dev/rss.xml |
| [Anchor.fm Podcasts](https://anchor.fm/) | `https://anchor.fm/s/podcastId/podcast/rss` | You can get the rss feed url of a podcast by following [these](https://help.anchor.fm/hc/en-us/articles/360027712351-Locating-your-Anchor-RSS-feed) instructions | https://anchor.fm/s/1e784a38/podcast/rss |
| [Hashnode](https://hashnode.com/) | `https://@username.hashnode.dev/rss.xml` | Replace @username with your hasnode username | https://polilluminato.hashnode.dev/rss.xml |

### Examples
* [My own GitHub profile readme](https://github.com/gautamkrishnar) - [YML File](https://github.com/gautamkrishnar/gautamkrishnar/blob/master/.github/workflows/blog-post-workflow.yml)
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: "Disables the sorting of list based on publish date"
default: "false"
required: false
template:
description: "Template to use while creating the list of posts. It can contain $title,$url and $newline as variables"
default: "default"
required: false
comment_tag_name:
description: "Override the default comment tag name, if you want to show multiple instances of the action on the same repo"
required: false
Expand Down
15 changes: 11 additions & 4 deletions blog-post-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const buildReadme = (previousContent, newContent) => {
}
return [
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length),
'\n',
newContent,
'\n',
previousContent.slice(startOfClosingTagIndex),
].join('');
};
Expand Down Expand Up @@ -175,9 +173,18 @@ Promise.allSettled(promiseArray).then((results) => {
if (postsArray.length > 0) {
try {
const readmeData = fs.readFileSync(README_FILE_PATH, "utf8");

const template = core.getInput('template');
const postListMarkdown = postsArray.reduce((acc, cur, index) => {
return acc + `- [${cur.title}](${cur.url})` + ((index === (postsArray.length - 1)) ? '' : '\n');
if (template === "default") {
// Default template: - [$title]($url)
return acc + `\n- [${cur.title}](${cur.url})` + (((index + 1) === postsArray.length) ? '\n' : '');
} else {
// Building with custom template
return acc + template
.replace(/\$title/g, cur.title)
.replace(/\$url/g, cur.url)
.replace(/\$newline/g, "\n");
}
}, '');
const newReadme = buildReadme(readmeData, postListMarkdown);
// if there's change in readme file update it
Expand Down
2 changes: 1 addition & 1 deletion dist/blog-post-workflow.js

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "blog-post-workflow",
"version": "1.0.8",
"version": "1.0.9",
"description": "Allows you to show your latest blog posts on your github profile or project readme",
"main": "blog-post-workflow.js",
"scripts": {
"start": "node blog-post-workflow.js",
"local-run": "node test.js",
"test-run": "npm run local-run && diff test/Readme.md test/Readme.md.snap",
"start-test": "node test.js",
"local-run": "start-server-and-test start-server http://localhost:8080 start-test",
"test-run": "npm run start-test && diff test/Readme.md test/Readme.md.snap",
"start-server": "node test/test-server.js",
"test": "npm run lint && start-server-and-test start-server http://localhost:8080 test-run",
"lint": "jshint --exclude='node_modules/' *.js",
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fs.writeFile(path.join(__dirname, 'test', 'Readme.md'), template, () => {
process.env.INPUT_MAX_POST_COUNT = "5";
process.env.INPUT_FEED_LIST = "http://localhost:8080";
process.env.INPUT_README_PATH = path.join(__dirname, 'test', 'Readme.md');
process.env.INPUT_DISABLE_SORT = "false";
process.env.INPUT_TEMPLATE = "default";
process.env.TEST_MODE = "true";
require('./blog-post-workflow');
});
Expand Down

0 comments on commit 566f510

Please sign in to comment.