Add list of popular tags to project index

This commit is contained in:
Drew DeVault 2021-03-03 14:48:58 -05:00
parent 27b0dba424
commit 610accc580
2 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,7 @@
from sqlalchemy.sql import operators
from flask import Blueprint, render_template, request, session
from hubsrht.types import Project, Feature, Event, EventType, Visibility, User
from srht.database import db
from srht.flask import paginate_query
from srht.oauth import current_user, loginrequired
from srht.search import search_by
@ -72,9 +73,19 @@ def project_index():
.order_by(Feature.created.desc())
.limit(5)).all()
tags = db.engine.execute("""
SELECT count(*) count, unnest(tags) tag
FROM project
GROUP BY tag
ORDER BY count DESC
LIMIT 12;
""")
tags = [(row[0], row[1]) for row in tags]
return render_template("project-index.html", projects=projects,
search=search, features=features, sort=sort, **pagination,
search_keys=["sort"], search_error=search_error)
search_keys=["sort"], search_error=search_error,
tags=tags)
@public.route("/projects/featured")
def featured_projects():

View File

@ -111,6 +111,18 @@
class="btn btn-default btn-block"
>More featured projects {{icon('caret-right')}}</a>
</div>
<h3>Popular tags</h3>
<div class="row">
{% for tag in tags %}
<div class="col-md-4">
<a
href="{{url_for("public.project_index",
search=((search or "").strip() + " #"+tag[1]).lstrip())}}"
>#{{tag[1]}}</a>:
{{tag[0]}} project{% if tag[0] > 1 %}s{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
</div>