commit 6df4e561eb1280bac4ddec89891a9851245604f4
parent 22145a7abd5859e92c5b9967e8d71d8495209e46
Author: Natalie Pendragon <natpen@natpen.net>
Date: Thu, 3 Sep 2020 08:00:33 -0400
[serve] Add newest hosts route
Diffstat:
4 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/serve/models.py b/serve/models.py
@@ -194,6 +194,20 @@ OR p.content_type IN ('application/atom+xml', 'application/rss+xml')
return feeds_query.execute()
+ def get_newest_hosts(self):
+ newest_hosts_query = Page.raw("""SELECT p.domain, MIN(c.timestamp) AS first_seen
+FROM page as p
+JOIN indexable_crawl AS ic
+ON ic.page_id == p.id
+JOIN crawl AS c
+ON c.page_id == p.id
+GROUP BY p.domain
+ORDER BY first_seen DESC
+LIMIT 10
+""")
+ return newest_hosts_query.execute()
+
+
def get_search_suggestions(self, query):
suggestions = []
corrector = self.searcher.corrector("content")
diff --git a/serve/templates/known_hosts.gmi b/serve/templates/known_hosts.gmi
@@ -5,6 +5,8 @@
Below are the hosts, or servers, in Geminispace, of which GUS is aware. Note that this list is auto-generated from the index, so if your host is not showing up here, it also won't have its content represented in GUS search results! If your server is missing, please use the link at the bottom of this page to submit a crawl request of your Gemini URL, after which your server should start showing up.
+=> /newest-hosts Show me the newest 10 hosts!
+
{% for host in known_hosts %}
{{ "=> gemini://{} {}".format(host, host) }}
{% endfor %}
diff --git a/serve/templates/newest_hosts.gmi b/serve/templates/newest_hosts.gmi
@@ -0,0 +1,12 @@
+{% include 'fragments/header.gmi' %}
+
+
+## Newest Gemini Hosts
+
+Here are the ten most recently discovered Gemini hosts by GUS. Welcome to Geminispace!
+
+{% for host in newest_hosts %}
+{{ "=> {} {}: {}".format(host.domain, host.first_seen[:10], host.domain) }}
+{% endfor %}
+
+{% include 'fragments/footer.gmi' %}
diff --git a/serve/views.py b/serve/views.py
@@ -79,6 +79,14 @@ def known_hosts(request):
return Response(Status.SUCCESS, "text/gemini", body)
+@app.route("/newest-hosts", strict_trailing_slash=False)
+def newest_hosts(request):
+ body = render_template("newest_hosts.gmi",
+ newest_hosts=gus.get_newest_hosts(),
+ index_modification_time=gus.statistics["index_modification_time"])
+ return Response(Status.SUCCESS, "text/gemini", body)
+
+
@app.route("/known-feeds", strict_trailing_slash=False)
def known_feeds(request):
body = render_template("known_feeds.gmi",