Skip to content

Commit b466eef

Browse files
authored
Merge pull request #11 from twang2218/fix-issue-6-button-width
Fix #6 Reduce the button width and add cutomize option
2 parents e93b703 + 665de0e commit b466eef

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ Plugin Config
2323
"types": [
2424
"star",
2525
"watch"
26-
]
26+
],
27+
"size": "large"
2728
}
2829
}
2930
}
3031
```
3132

33+
The default size of `large` is `150 x 30`, and `small` is `100 x 20`, however, you can specify the size you want by using `width` and `height`. Such as:
34+
35+
```json
36+
"size": "small"
37+
"width": 90,
38+
"height": 21
39+
```
3240

3341
## Example
3442

@@ -44,4 +52,4 @@ Plugin Config
4452

4553
## License
4654

47-
MIT
55+
MIT

src/plugin.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ require(['gitbook'], function (gitbook) {
1010
repo,
1111
type,
1212
size,
13+
width,
14+
height,
1315
count
1416
}) {
15-
var width = size === "large" ? "170" : "160";
16-
var height = size === "large" ? "30" : "20";
1717
var extraParam = type === "watch" ? "&v=2" : "";
1818
return `<a class="btn pull-right hidden-mobile" aria-label="github">
1919
<iframe style="display:inline-block;vertical-align:middle;" src="https://ghbtns.com/github-btn.html?user=${user}&repo=${repo}&type=${type}&count=${count}&size=${size}${extraParam}" frameborder="0" scrolling="0" width="${width}px" height="${height}px"></iframe>
@@ -26,6 +26,8 @@ require(['gitbook'], function (gitbook) {
2626
repo,
2727
types,
2828
size,
29+
width,
30+
height,
2931
count
3032
}) {
3133
types.reverse().forEach(type => {
@@ -34,6 +36,8 @@ require(['gitbook'], function (gitbook) {
3436
repo,
3537
type,
3638
size,
39+
width,
40+
height,
3741
count
3842
});
3943
addBeforeHeader(elementString);
@@ -49,12 +53,16 @@ require(['gitbook'], function (gitbook) {
4953
}
5054
var types = config.types || ["star", "watch"];
5155
var size = config.size || "large";
56+
var width = config.width || (size === "large" ? "150" : "100");
57+
var height = config.height || (size === "large" ? "30" : "20");
5258
var count = typeof config.count === "undefined" ? "true" : "false";
5359
insertGitHubLink({
5460
user,
5561
repo,
5662
types,
5763
size,
64+
width,
65+
height,
5866
count
5967
});
6068
}

0 commit comments

Comments
 (0)