From 610accc58075da0cc61d75173396ec9e51538240 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 3 Mar 2021 14:48:58 -0500 Subject: [PATCH] Add list of popular tags to project index --- hubsrht/blueprints/public.py | 13 ++++++++++++- hubsrht/templates/project-index.html | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hubsrht/blueprints/public.py b/hubsrht/blueprints/public.py index adaecef..9a9892b 100644 --- a/hubsrht/blueprints/public.py +++ b/hubsrht/blueprints/public.py @@ -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(): diff --git a/hubsrht/templates/project-index.html b/hubsrht/templates/project-index.html index 32e17ee..515bb61 100644 --- a/hubsrht/templates/project-index.html +++ b/hubsrht/templates/project-index.html @@ -111,6 +111,18 @@ class="btn btn-default btn-block" >More featured projects {{icon('caret-right')}} +

Popular tags

+
+ {% for tag in tags %} +
+ #{{tag[1]}}: + {{tag[0]}} project{% if tag[0] > 1 %}s{% endif %} +
+ {% endfor %} +