mirror of
https://github.com/Luzifer/badge-gen.git
synced 2024-12-20 16:41:16 +00:00
Added color, README and Dockerfile
This commit is contained in:
parent
633d1c18ff
commit
77b5d97a19
4 changed files with 50 additions and 3 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
FROM gliderlabs/alpine:3.1
|
||||||
|
|
||||||
|
MAINTAINER Knut Ahlers <knut@ahlers.me>
|
||||||
|
|
||||||
|
RUN apk --update add wget && \
|
||||||
|
wget --no-check-certificate https://gobuilder.me/get/github.com/Luzifer/badge-gen/badge-gen_master_linux-386.zip && \
|
||||||
|
unzip badge-gen_master_linux-386.zip
|
||||||
|
|
||||||
|
ENV PORT 3000
|
||||||
|
EXPOSE 3000
|
||||||
|
ENTRYPOINT ["/badge-gen/badge-gen"]
|
30
README.md
Normal file
30
README.md
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Luzifer / badge-gen
|
||||||
|
|
||||||
|
Ever ran into this scenario? You wanted to add a link to something to your GitHub project using a nice button like the Godoc or the Travis-CI button but you was not able to find a button for this having the text you wanted? I did. I wanted to add a button "API Documentation" to one of my projects and did not find any button with that caption. So I wrote it myself.
|
||||||
|
|
||||||
|
And I wasn't myself if I would allow me to do the same work twice or more often so I wrote a small webserver able to generate those buttons with a customizable text in SVG (I did not care about older browser since long ago)…
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Using my version
|
||||||
|
|
||||||
|
Simple use this URL:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://badge.luzifer.io/v1/badge?title=API&text=Documentation&color=4c1
|
||||||
|
```
|
||||||
|
|
||||||
|
![YourTitle](http://badge.luzifer.io/v1/badge?title=API&text=Documentation&color=4c1)]
|
||||||
|
|
||||||
|
Parameters `title` and `text` are free-text strings while `color` has to be 3- or 6-letter hex notation for colors like that one you use in CSS.
|
||||||
|
|
||||||
|
To embed them into Markdown pages like this `README.md`:
|
||||||
|
|
||||||
|
```
|
||||||
|
![YourTitle](http://badge.luzifer.io/v1/badge?title=API&text=Documentation&color=4c1)]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using your own hosted version
|
||||||
|
|
||||||
|
- There is a [Docker container](https://registry.hub.docker.com/u/luzifer/bage-gen/) for it. Just start it and use your own URL
|
||||||
|
- You also can download the binary from [GoBuilder.me](https://gobuilder.me/github.com/Luzifer/badge-gen) and use that one
|
|
@ -9,7 +9,7 @@
|
||||||
</mask>
|
</mask>
|
||||||
<g mask="url(#a)">
|
<g mask="url(#a)">
|
||||||
<path fill="#555" d="M0 0 h{{ .TitleWidth }} v20 H0 z" />
|
<path fill="#555" d="M0 0 h{{ .TitleWidth }} v20 H0 z" />
|
||||||
<path fill="#4c1" d="M{{ .TitleWidth }} 0 H{{ .Width }} v20 H{{ .TitleWidth }} z" />
|
<path fill="#{{ .Color }}" d="M{{ .TitleWidth }} 0 H{{ .Width }} v20 H{{ .TitleWidth }} z" />
|
||||||
<path fill="url(#b)" d="M0 0 h{{ .Width }} v20 H0 z" />
|
<path fill="url(#b)" d="M0 0 h{{ .Width }} v20 H0 z" />
|
||||||
</g>
|
</g>
|
||||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||||
|
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1.1 KiB |
10
main.go
10
main.go
|
@ -31,20 +31,25 @@ func main() {
|
||||||
func generateBadge(res http.ResponseWriter, r *http.Request) {
|
func generateBadge(res http.ResponseWriter, r *http.Request) {
|
||||||
title := r.URL.Query().Get("title")
|
title := r.URL.Query().Get("title")
|
||||||
text := r.URL.Query().Get("text")
|
text := r.URL.Query().Get("text")
|
||||||
|
color := r.URL.Query().Get("color")
|
||||||
|
|
||||||
if title == "" || text == "" {
|
if title == "" || text == "" {
|
||||||
http.Error(res, "You must specify parameters 'title' and 'text'.", http.StatusInternalServerError)
|
http.Error(res, "You must specify parameters 'title' and 'text'.", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
badge := createBadge(title, text)
|
if color == "" {
|
||||||
|
color = "4c1"
|
||||||
|
}
|
||||||
|
|
||||||
|
badge := createBadge(title, text, color)
|
||||||
|
|
||||||
res.Header().Add("Content-Type", "image/svg+xml")
|
res.Header().Add("Content-Type", "image/svg+xml")
|
||||||
res.Header().Add("Cache-Control", "public, max-age=31536000")
|
res.Header().Add("Cache-Control", "public, max-age=31536000")
|
||||||
res.Write(badge)
|
res.Write(badge)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createBadge(title, text string) []byte {
|
func createBadge(title, text, color string) []byte {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
bufw := bufio.NewWriter(&buf)
|
bufw := bufio.NewWriter(&buf)
|
||||||
|
|
||||||
|
@ -63,6 +68,7 @@ func createBadge(title, text string) []byte {
|
||||||
"Text": text,
|
"Text": text,
|
||||||
"TitleAnchor": titleW/2 + xSpacing,
|
"TitleAnchor": titleW/2 + xSpacing,
|
||||||
"TextAnchor": titleW + textW/2 + 3*xSpacing,
|
"TextAnchor": titleW + textW/2 + 3*xSpacing,
|
||||||
|
"Color": color,
|
||||||
})
|
})
|
||||||
|
|
||||||
bufw.Flush()
|
bufw.Flush()
|
||||||
|
|
Loading…
Reference in a new issue