Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 97d3fcc

Browse files
authored
Merge pull request #4 from eddiejaoude/issue-2
Custom html cell
2 parents 05f60b0 + a550333 commit 97d3fcc

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,31 @@ This GitHub Action creates a table in your `README.md`
66

77
### `github-token` [REQUIRED]
88

9-
This can be achieved with
9+
This is available in your GitHub Action
1010

1111
```yaml
1212
with:
1313
github-token: ${{ secrets.GITHUB_TOKEN }}
1414
```
1515
16+
### `html-cell` [REQUIRED]
17+
18+
This is the html table cell content with `object-field-names`
19+
20+
```yaml
21+
with:
22+
html-cell: '<td>{{ firstname }} {{ lastname }}</td>'
23+
```
24+
25+
### `object-field-names` [REQUIRED]
26+
27+
This is json, and contains a list of the names of the fields in your json file data object
28+
29+
```yaml
30+
with:
31+
object-field-names: '[ "firstname", "lastname" ]'
32+
```
33+
1634
### `columns` [OPTIONAL]
1735

1836
**defaults to `2`**

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ inputs:
99
description: 'json file to load'
1010
required: true
1111
default: 'data.json'
12-
github-token: # id of input
12+
github-token:
1313
description: 'github token'
1414
required: true
15+
html-cell:
16+
description: 'html for the table cell'
17+
required: true
18+
object-field-names:
19+
description: 'array of object field names from your json objects'
20+
required: true
1521
runs:
1622
using: 'node12'
1723
main: 'index.js'

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ const path = require('path');
55
const readmeBox = require('readme-box').ReadmeBox;
66
const chunk = require('chunk');
77

8-
const generateCell = (user) => {
9-
return `<td align="center">
10-
<p><a href="https://github.com/${user.githubUsername}">${user.name}</a></p>
11-
<img src="${user.imageUrl}" />
12-
<p><a href="https://github.com/EddieJaoudeCommunity/awesome-github-profiles/issues/${user.issueNumber}">(:100: give your vote)</a></p>
13-
</td>`;
8+
const generateCell = (cell) => {
9+
const objectFieldNames = JSON.parse(core.getInput('object-field-names'));
10+
let htmlCell = core.getInput('html-cell');
11+
12+
objectFieldNames.forEach((name) => {
13+
htmlCell = htmlCell.replace(new RegExp(`{{ ${name} }}`), cell[name]);
14+
});
15+
console.log(objectFieldNames);
16+
console.log(htmlCell);
17+
return htmlCell;
1418
}
1519

1620
const generateRow = (columns, row) => {
17-
const cells = row.map((user) => generateCell(user));
21+
const cells = row.map((cell) => generateCell(cell));
1822

1923
if (cells.length < columns) {
2024
cells.push('<td></td>'.repeat(columns - cells.length));

0 commit comments

Comments
 (0)