Skip to content

Commit

Permalink
feat: add table template
Browse files Browse the repository at this point in the history
  • Loading branch information
huantt committed Sep 13, 2023
1 parent 87dbac0 commit 4d198f1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Update articles
uses: huantt/article-listing@v1.0.0
uses: huantt/article-listing@v1.1.0
with:
username: jacktt
limit: 5
Expand Down
5 changes: 5 additions & 0 deletions README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ jobs:
**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 }}*
Binary file added data/images/default-thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions data/template.md.tpl

This file was deleted.

5 changes: 4 additions & 1 deletion handler/collector/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import _ "embed"
//go:embed templates/list.tpl
var articleListTemplate string

//go:embed templates/table.tpl
var articleTableTemplate string

var templates = []string{
articleListTemplate,
articleListTemplate, articleTableTemplate,
}
14 changes: 14 additions & 0 deletions handler/collector/templates/table.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- define "article-table"}}
<table>
{{- range $i, $article := .}}
<tr>
<td width="300px"><img src="{{- if ne $article.Thumbnail ""}}{{ $article.Thumbnail }}{{- else}}{{`data/images/default-thumbnail.png`}}{{- end}}" alt="thumbnail"></td>
<td>
<a href="{{ $article.Url }}">{{ truncateByWords $article.Title 10 }}</a>
<div>{{ $article.Description }}</div>
<div><i>{{ formatDate $article.CreatedAt }}</i></div>
</td>
</tr>
{{- end}}
</table>
{{- end}}

0 comments on commit 4d198f1

Please sign in to comment.