show top links
change
commit 51b234493d1249e6a29150c871efc74006ad79c3
author Alpha Chen <alpha@kejadlen.dev>
date
parent 55688b8e
diff --git a/go_ji/__init__.py b/go_ji/__init__.py
index b177989..5979752 100644
--- a/go_ji/__init__.py
+++ b/go_ji/__init__.py
@@ -79,7 +79,10 @@ def create_app(config_override: dict[str, Any] = {}) -> Flask:
 
     @app.route("/")
     def index() -> str:
-        return render_template("index.html", name=g.user.login)
+        top_shorts = db_session.scalars(
+            select(Short).order_by(Short.clicks.desc()).limit(10)
+        ).all()
+        return render_template("index.html", name=g.user.login, top_shorts=top_shorts)
 
     @app.route("/links", methods=["POST"])
     def create_link() -> Response:
diff --git a/go_ji/templates/index.html b/go_ji/templates/index.html
index cc38e0e..3c1cde8 100644
--- a/go_ji/templates/index.html
+++ b/go_ji/templates/index.html
@@ -14,5 +14,14 @@
       <input type="text" id="url" name="url" />
       <input type="submit" value="Create Link">
     </form>
+    <table>
+      <tr><th>short</th><th>clicks</th></tr>
+      {% for short in top_shorts %}
+      <tr>
+        <td>{{ short.slug }}</td>
+        <td>{{ short.clicks }}</td>
+      </tr>
+      {% endfor %}
+    </table>
   </body>
 </html>