Skip to content

Commit 8aa4262

Browse files
authored
Merge pull request #3632 from fenilgandhi/master
Add support for different badge styles
2 parents 17c5b2f + 0af69a4 commit 8aa4262

18 files changed

+57
-10
lines changed

docs/badges.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,30 @@ Here are a few examples:
1919
You can see it in action in the `Read the Docs README`_.
2020
They will link back to your project's documentation page on Read the Docs.
2121

22+
Style
23+
-----
24+
25+
Now you can pass the ``style`` GET argument,
26+
to get custom styled badges same as you would for shields.io.
27+
If no argument is passed, ``flat`` is used as default.
28+
29+
STYLE | BADGE
30+
------------ | -------------
31+
flat | ![Flat Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=flat)
32+
flat-square | ![Flat-Square Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=flat-square)
33+
for-the-badge | ![ Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=for-the-badge)
34+
plastic | ![Plastic Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=plastic)
35+
social | ![Social Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=social)
36+
37+
2238
Project Pages
2339
-------------
2440

2541
You will now see badges embedded in your `project page`_.
2642
The default badge will be pointed at the *default version* you have specified for your project.
2743
The badge URLs look like this::
2844

29-
https://readthedocs.org/projects/pip/badge/?version=latest
45+
https://readthedocs.org/projects/pip/badge/?version=latest&style=plastic
3046

3147
You can replace the version argument with any version that you want to show a badge for.
3248
If you click on the badge icon,
@@ -47,4 +63,4 @@ since it will stay up to date with your Read the Docs project::
4763
.. |red| image:: https://media.readthedocs.org/static/projects/badges/failing.svg
4864
.. |yellow| image:: https://media.readthedocs.org/static/projects/badges/unknown.svg
4965
.. |nbsp| unicode:: 0xA0
50-
:trim:
66+
:trim:
Lines changed: 1 addition & 0 deletions
Loading
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

readthedocs/projects/views/public.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ def get_context_data(self, **kwargs):
112112
@never_cache
113113
def project_badge(request, project_slug):
114114
"""Return a sweet badge for the project."""
115-
badge_path = 'projects/badges/%s.svg'
115+
style = request.GET.get('style', 'flat')
116+
if style not in ("flat", "plastic", "flat-square", "for-the-badge", "social"):
117+
style = "flat"
118+
badge_path = 'projects/badges/%s-' + style + '.svg'
116119
version_slug = request.GET.get('version', LATEST)
117120
try:
118121
version = Version.objects.public(request.user).get(

0 commit comments

Comments
 (0)