geminispace.info

gemini search engine
git clone https://git.clttr.info/geminispace.info.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 6ddea2105baef4bf391c30b3cdd33e729d2fe99e
parent c67268608f93486bba5ff7ce135549b73e98f5a7
Author: Natalie Pendragon <natpen@natpen.net>
Date:   Fri,  4 Sep 2020 08:21:41 -0400

[serve] Add dynamic quotes to footer

Diffstat:
Mserve/constants.py | 31+++++++++++++++++++++++++++++++
Mserve/templates/fragments/footer.gmi | 2+-
Mserve/views.py | 50++++++++++++++++++++++++++++++++++----------------
3 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/serve/constants.py b/serve/constants.py @@ -2,3 +2,34 @@ INDEX_DIR = "index" SEED_REQUEST_FILE = "seed-requests.txt" STATISTICS_FILE = "statistics.csv" DB_FILENAME = "gus.sqlite" + +QUOTE_BANK = [ + { + "quote": "Isn’t it enough to see that a garden is beautiful without having to believe that there are fairies at the bottom of it too?", + "author": "Douglas Adams", + }, + { + "quote": "The ships hung in the sky in much the same way that bricks don’t.", + "author": "Douglas Adams", + }, + { + "quote": "I went to the doctor and all he did was suck blood from my neck. Do not go see Dr. Acula.", + "author": "Mitch Hedberg", + }, + { + "quote": "I'm sick of people saying that age is a number... when it is clearly a word.", + "author": "Mitch Hedberg", + }, + { + "quote": "Some people think this is paranoia, but it isn't. Paranoids only think everyone is out to get them. Wizards know it.", + "author": "Terry Pratchett", + }, + { + "quote": "If it looks like a duck and sounds like a duck, it could be a really ugly swan.", + "author": "Timothy Radman", + }, + { + "quote": "If I cease searching, then, woe is me, I am lost. That is how I look at it - keep going, keep going come what may.", + "author": "Vincent Van Gogh", + }, +] diff --git a/serve/templates/fragments/footer.gmi b/serve/templates/fragments/footer.gmi @@ -1,4 +1,4 @@ -> “If I cease searching, then, woe is me, I am lost. That is how I look at it - keep going, keep going come what may.” --- Vincent Van Gogh +> "{{ quote["quote"] }}" --- {{ quote["author"] }} => /add-seed See any missing results? Let GUS know your Gemini URL exists. diff --git a/serve/views.py b/serve/views.py @@ -1,11 +1,13 @@ import math import os +import random from datetime import datetime from urllib.parse import quote, unquote import jinja2 from jetforce import Request, Response, Status, JetforceApplication +from . import constants from .models import compute_verbose, compute_requested_results_page, GUS, process_seed_request TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), "templates") @@ -58,7 +60,8 @@ def add_seed(request): def statistics(request): body = render_template("statistics.gmi", statistics=gus.statistics, - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @@ -66,7 +69,8 @@ def statistics(request): def statistics(request): body = render_template("statistics_historical_overall.gmi", statistics_historical_overall=gus.statistics_historical_overall, - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @@ -75,7 +79,8 @@ def known_hosts(request): body = render_template("known_hosts.gmi", # TODO: remove this `sorted` after the next index generation known_hosts=sorted(gus.statistics["domains"]), - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @@ -83,7 +88,8 @@ def known_hosts(request): def newest_hosts(request): body = render_template("newest_hosts.gmi", newest_hosts=gus.get_newest_hosts(), - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @@ -91,7 +97,8 @@ def newest_hosts(request): def newest_pages(request): body = render_template("newest_pages.gmi", newest_pages=gus.get_newest_pages(), - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @@ -99,49 +106,56 @@ def newest_pages(request): def known_feeds(request): body = render_template("known_feeds.gmi", known_feeds=gus.get_feeds(), - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @app.route("", strict_trailing_slash=False) def index(request): body = render_template("index.gmi", - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @app.route("/about", strict_trailing_slash=False) def index(request): body = render_template("about.gmi", - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @app.route("/documentation/searching", strict_trailing_slash=False) def documentation_searching(request): body = render_template("documentation/searching.gmi", - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @app.route("/documentation/indexing", strict_trailing_slash=False) def documentation_indexing(request): body = render_template("documentation/indexing.gmi", - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @app.route("/documentation/backlinks", strict_trailing_slash=False) def documentation_backlinks(request): body = render_template("documentation/backlinks.gmi", - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @app.route("/news", strict_trailing_slash=False) def index(request): body = render_template("news.gmi", - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) @@ -165,13 +179,15 @@ def search(request): results=results, current_page=current_page, num_pages=num_pages, - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) else: search_suggestions = gus.get_search_suggestions(request.query) body = render_template("search_suggestions.gmi", query=request.query, search_suggestions=search_suggestions, - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) else: return Response(Status.INPUT, "Search query") @@ -186,7 +202,8 @@ def backlinks(request): url=url, internal_backlinks=internal_backlinks, external_backlinks=external_backlinks, - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body) else: return Response(Status.INPUT, "Gemini URL") @@ -199,5 +216,6 @@ def threads(request): body = render_template("threads.gmi", threads=threads, sort=sort, - index_modification_time=gus.statistics["index_modification_time"]) + index_modification_time=gus.statistics["index_modification_time"], + quote=random.choice(constants.QUOTE_BANK)) return Response(Status.SUCCESS, "text/gemini", body)