Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre and post template options #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ You can provide a [Mustache](https://github.com/janl/mustache.js) template to us
template: "> {{ excerpt }}\n\n[Read more!]({{ url }})"
```

#### `pre_template` (default: ``)

Any additional pre template to use before add the template. This could be used to open table header for instance.

#### `post_template` (default: ``)

Any additional post template to use after add the template.

### Example RSS feed:

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ inputs:
max:
default: 5
description: The maximum number of RSS feed items to show.
pre_template:
default: ''
description: Any additional text or tag goes here.
template:
default: '* [{{ title }}]({{ link }})'
description: The template to use for each item in the RSS feed. These are joined by a new line.
post_template:
default: ''
description: Any additional text or tag goes here.
github_token:
default: ${{ github.token }}
runs:
Expand Down
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ interface Inputs {
'feed-url': string
'readme-section': string
max: string
pre_template: string
template: string
post_template: string
[key: string]: string
}

Expand All @@ -21,13 +23,27 @@ Toolkit.run<Inputs>(async tools => {
throw new Error('feed.items was not found!')
}

let strings: Array<string> = []

if (tools.inputs.pre_template) {
strings.push(tools.inputs.pre_template)
}

// Create our new list
const newString = feed.items
.slice(0, parseInt(tools.inputs.max, 10))
.map(item => mustache.render(tools.inputs.template, item)).join('\n')

strings.push(newString)

if (tools.inputs.post_template) {
strings.push(tools.inputs.post_template)
}

const finalString = strings.join('\n')

// Update the section of our README
await ReadmeBox.updateSection(newString, {
await ReadmeBox.updateSection(finalString, {
...tools.context.repo,
token: tools.token,
section: tools.inputs['readme-section']
Expand Down