Skip to content

Commit

Permalink
support 2 more parameter to customize badge color: left_color and rig…
Browse files Browse the repository at this point in the history
…ht_color
  • Loading branch information
jwenjian committed Sep 3, 2021
1 parent 933e04a commit d6eabbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 10 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ def visitor_svg() -> Response:
if not latest_count:
return invalid_count_resp("Count API Failed")

svg = badge(left_text="visitors", right_text=str(latest_count))
# get left color and right color
left_color = "#595959"
if request.args.get("left_color") is not None:
left_color = request.args.get("left_color")

right_color = "#1283c3"
if request.args.get("right_color") is not None:
right_color = request.args.get("right_color")

svg = badge(left_text="visitors", right_text=str(latest_count), left_color=str(left_color), right_color=str(right_color))

expiry_time = datetime.datetime.utcnow() - datetime.timedelta(minutes=10)

Expand Down
11 changes: 9 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ <h2>Docs</h2>
</p>
<pre>
<code lang="markdown">
![visitors](https://visitor-badge.glitch.me/badge?page_id=page.id)
![visitors](https://visitor-badge.glitch.me/badge?page_id=page.id&left_color=red&right_color=green)
</code>
</pre>
<p>In which, the url parameter
<p>In which, </p>
<p>The url parameter
<mark>page_id</mark>
is <b>REQUIRED</b>, please use the unique string to best represent your page.
</p>

<p id="page_id_rule">I recommend you to follow <code>page_id</code> rules below:</p>
<ol>
<li>For README.md file, use <i>${your.username}.${your.repo.id}</i>, <code>https://visitor-badge.glitch.me/badge?page_id=jwenjian.visitor-badge</code>
Expand All @@ -81,6 +83,11 @@ <h2>Docs</h2>
</li>
</ol>
<p>or any other markdown content, please give an unique string to distinguish</p>

<p>The url parameter <mark>left_color</mark> and <mark>right_color</mark> is optional, you can customize the badge color by passing the two parameters.</p>

<p>The values supports color names(like green) and RGB in hex string starts with a hashtag(like #66ccff)
</p>
</article>
<hr>
<div id="faq">
Expand Down

0 comments on commit d6eabbb

Please sign in to comment.