diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py
index 17a12a17..d612f9ed 100644
--- a/app/blueprints/packages/packages.py
+++ b/app/blueprints/packages/packages.py
@@ -33,6 +33,7 @@ from wtforms.validators import *
from wtforms.ext.sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField
from sqlalchemy import or_, func
from sqlalchemy.orm import joinedload, subqueryload
+from urllib.parse import quote as urlescape
from celery import uuid
@@ -182,6 +183,24 @@ def view(package):
threads=threads.all(), has_review=has_review)
+@bp.route("/packages///shields//")
+@is_package_page
+def shield(package, type):
+ if type == "title":
+ url = "https://img.shields.io/badge/ContentDB-{}-{}" \
+ .format(urlescape(package.title), urlescape("#375a7f"))
+ elif type == "downloads":
+ #api_url = abs_url_for("api.package", author=package.author.username, name=package.name)
+ api_url = "https://content.minetest.net" + url_for("api.package", author=package.author.username, name=package.name)
+ url = "https://img.shields.io/badge/dynamic/json?color={}&label=ContentDB&query=downloads&suffix=+downloads&url={}" \
+ .format(urlescape("#375a7f"), urlescape(api_url))
+ else:
+ abort(404)
+
+ return redirect(url)
+
+
+
@bp.route("/packages///download/")
@is_package_page
def download(package):
diff --git a/app/models.py b/app/models.py
index f7845735..4aa18f06 100644
--- a/app/models.py
+++ b/app/models.py
@@ -658,6 +658,15 @@ class Package(db.Model):
return url_for("packages.view",
author=self.author.username, name=self.name)
+ def getShieldURL(self, type):
+ from app.utils import abs_url_for
+ return abs_url_for("packages.shield",
+ author=self.author.username, name=self.name, type=type)
+
+ def makeShield(self, type):
+ return "[![ContentDB]({})]({})" \
+ .format(self.getShieldURL(type), self.getDetailsURL(True))
+
def getEditURL(self):
return url_for("packages.create_edit",
author=self.author.username, name=self.name)
diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html
index 560ee827..c03611a9 100644
--- a/app/templates/packages/view.html
+++ b/app/templates/packages/view.html
@@ -530,5 +530,25 @@
{% endfor %}
{% endif %}
+
+ {% if package.checkPerm(current_user, "EDIT_PACKAGE") %}
+ Badges
+
+
+ {{ package.makeShield("title") | markdown }}
+
+
+
+
{{ package.makeShield("title") }}
+
+
+
+ {{ package.makeShield("downloads") | markdown }}
+
+
+
+
{{ package.makeShield("downloads") }}
+
+ {% endif %}
{% endblock %}