mirror of https://git.sr.ht/~sircmpwn/hub.sr.ht
Add list of popular tags to project index
This commit is contained in:
parent
27b0dba424
commit
610accc580
|
@ -1,6 +1,7 @@
|
||||||
from sqlalchemy.sql import operators
|
from sqlalchemy.sql import operators
|
||||||
from flask import Blueprint, render_template, request, session
|
from flask import Blueprint, render_template, request, session
|
||||||
from hubsrht.types import Project, Feature, Event, EventType, Visibility, User
|
from hubsrht.types import Project, Feature, Event, EventType, Visibility, User
|
||||||
|
from srht.database import db
|
||||||
from srht.flask import paginate_query
|
from srht.flask import paginate_query
|
||||||
from srht.oauth import current_user, loginrequired
|
from srht.oauth import current_user, loginrequired
|
||||||
from srht.search import search_by
|
from srht.search import search_by
|
||||||
|
@ -72,9 +73,19 @@ def project_index():
|
||||||
.order_by(Feature.created.desc())
|
.order_by(Feature.created.desc())
|
||||||
.limit(5)).all()
|
.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,
|
return render_template("project-index.html", projects=projects,
|
||||||
search=search, features=features, sort=sort, **pagination,
|
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")
|
@public.route("/projects/featured")
|
||||||
def featured_projects():
|
def featured_projects():
|
||||||
|
|
|
@ -111,6 +111,18 @@
|
||||||
class="btn btn-default btn-block"
|
class="btn btn-default btn-block"
|
||||||
>More featured projects {{icon('caret-right')}}</a>
|
>More featured projects {{icon('caret-right')}}</a>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue