Skip to content

Commit 0921465

Browse files
committed
Add view button and more fields
Add view button type Add icon, text and aria-label customizations
1 parent e8357b4 commit 0921465

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This selects the type of button to display.
3131
- `template`
3232
- `issue`
3333
- `download`
34+
- `view`
3435

3536
#### `user`
3637

@@ -50,20 +51,23 @@ The GitHub repo for the button link.
5051

5152
- Type: `string`, `true` to enable
5253
- Usage: `optional` for `follow`, `watch`, `star`, `fork`, `issue`
54+
- Default: `false`
5355

5456
Attach the applicable number to the button for the specified type.
5557

5658
#### `dark`
5759

5860
- Type: `string`, `true` to enable
5961
- Usage: `optional`
62+
- Default: `false`
6063

6164
Use the dark button theme if enabled, otherwise light theme.
6265

6366
#### `large`
6467

6568
- Type: `string`, `true` to enable
6669
- Usage: `optional`
70+
- Default: `false`
6771

6872
Use a larger button if enabled.
6973

@@ -74,6 +78,46 @@ Use a larger button if enabled.
7478

7579
Specify a branch other than master for the download.
7680

81+
#### `icon`
82+
- Type: `string`
83+
- Usage: `optional`
84+
85+
Override the default icon for a button type. Valid icons are
86+
- `mark-github`
87+
- `heart`
88+
- `eye`
89+
- `star`
90+
- `repo-forked`
91+
- `repo-template`
92+
- `issue-opened`
93+
- `download`
94+
95+
#### `text`
96+
- Type: `string`
97+
- Usage: `optional`
98+
99+
Override the default button text for a button type.
100+
101+
#### `aria_label`
102+
- Type: `string`
103+
- Usage: `optional`
104+
105+
Override the default aria-label for a button type.
106+
107+
## Defaults
108+
109+
| button | icon | text | path https://github.com | aria-label |
110+
| -------- | ------------- | ----------------- | ----------------------------------- | ----------------------------------------- |
111+
| follow | mark-github | Follow @`user` | /`user` | Follow @`user` on GitHub |
112+
| sponsor | heart | Sponsor | /sponsors/`user` | Sponsor @`user` on GitHub |
113+
| watch | eye | Watch | /`user`/`repo`/subscription | Watch `user`/`repo` on GitHub |
114+
| star | star | Star | /`user`/`repo` | Star `user`/`repo` on GitHub |
115+
| fork | repo-forked | Fork | /`user`/`repo`/fork | Fork `user`/`repo` on GitHub |
116+
| template | repo-template | Use this template | /`user`/`repo`/generate | Use this template `user`/`repo` on GitHub |
117+
| issue | issue-opened | Issue | /`user`/`repo`/issues | Issue `user`/`repo` on GitHub |
118+
| download | download | Download | /`user`/`repo`/archive/`branch`.zip | Download `user`/`repo` on GitHub |
119+
| view | mark-github | `repo` | /`user`/`repo` | View `user`/`repo` on GitHub |
120+
77121
## Examples
78122

79123
Follow button and Follow button with followers count:
@@ -119,6 +163,7 @@ All buttons:
119163
{{< github_button button="template" user="statropy" repo="github-button-hugo-shortcode" >}}
120164
{{< github_button button="issue" user="statropy" repo="github-button-hugo-shortcode" count="true" >}}
121165
{{< github_button button="download" user="statropy" repo="github-button-hugo-shortcode" >}}
166+
{{< github_button button="view" user="statropy" repo="github-button-hugo-shortcode" >}}
122167
```
123168

124169
## Install

layouts/shortcodes/github_button.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{ $aria_label = printf "Follow @%s on GitHub" (.Get "user") }}
1010
{{ $button_text = printf "Follow @%s" (.Get "user") }}
1111
{{else if eq $button "sponsor"}}
12-
{{ $href = printf "sponsors/%s/" (.Get "user")}}
12+
{{ $href = printf "sponsors/%s" (.Get "user")}}
1313
{{ $data_icon = "heart" }}
1414
{{ $aria_label = printf "Sponsor @%s on GitHub" (.Get "user") }}
1515
{{ $button_text = "Sponsor" }}
@@ -44,8 +44,25 @@
4444
{{ $data_icon = "download" }}
4545
{{ $aria_label = printf "Download %s/%s on GitHub" (.Get "user") (.Get "repo")}}
4646
{{ $button_text = "Download" }}
47+
{{else if eq $button "view"}}
48+
{{ $href = printf "%s/%s" (.Get "user") (.Get "repo")}}
49+
{{ $data_icon = "mark-github" }}
50+
{{ $aria_label = printf "View %s/%s on GitHub" (.Get "user") (.Get "repo")}}
51+
{{ $button_text = .Get "repo" }}
4752
{{end}}
4853

54+
{{ with .Get "text" }}
55+
{{ $button_text = . }}
56+
{{ end }}
57+
58+
{{ with .Get "icon" }}
59+
{{ $data_icon = . }}
60+
{{ end }}
61+
62+
{{ with .Get "aria_label" }}
63+
{{ $aria_label = . }}
64+
{{ end }}
65+
4966
<a
5067
class="github-button"
5168
href="https://github.com/{{$href}}"

0 commit comments

Comments
 (0)