-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.md.template
73 lines (58 loc) · 2.2 KB
/
README.md.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## About
Collect your latest articles from sources such as [dev.to](https://dev.to), and then update the `README.md`.
## Use GitHub Action to update your README
**Step 1:** In your repository, create a file named `README.md.template`.
**Step 2:** Write anything you want within the `README.md.template` file.
**Step 3:** Embed one of the following entities within your `README.md.template`:
- **Article listing:**
```shell
{{`{{`}} template "article-list" .Articles {{`}}`}}
```
- **Article table:**
```shell
{{`{{`}} template "article-table" .Articles {{`}}`}}
```
If you are familiar with Go templates, you have access to the `root` variable, which includes the following fields:
- `Articles`: An array of Article. You can view the Article struct definition in [model/article.go](model/article.go).
- `Time`: Updated Time
- `Author`: Author of articles
**Step 4**: Register Github Action
- Create a file `.github/workflows/update-articles.yml` in your repository.
```yml
name: "Cronjob"
on:
schedule:
- cron: '15 0 * * *'
jobs:
update-articles:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Generate README
uses: huantt/[email protected]
with:
username: YOUR_USERNAME_ON_DEV_TO
template-file: 'README.md.template'
out-file: 'README.md'
limit: 5
- name: Commit
run: |
if git diff --exit-code; then
echo "No changes to commit."
exit 0
else
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "update"
git push origin main
fi
```
**Step 5**: Commit your change, then Github actions will run as your specified cron to update Articles into your README.md file
## Below is my recent articles {{ .Author }} collected from dev.to
### Table
{{ template "article-table" .Articles }}
### List
{{ template "article-list" .Articles }}
*Updated at: {{ formatTime .Time }}*