From a459e49fa0a35d8f62740fcaa089ad6b950b4b42 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sun, 19 Nov 2023 14:27:47 +0100 Subject: [PATCH] Extract titles from gemtext and use them as GeminiItem.name if that's missing. --- av98.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/av98.py b/av98.py index 470a14d..12aa825 100755 --- a/av98.py +++ b/av98.py @@ -699,6 +699,7 @@ you'll be able to transparently follow links to Gopherspace!""") """ self.index = [] preformatted = False + title = "" with open(self.active_raw_file, "r") as fp: body = fp.read() @@ -732,6 +733,8 @@ you'll be able to transparently follow links to Gopherspace!""") elif line.startswith("#"): line = line[1:].lstrip("\t ") fp.write("\x1b[1m\x1b[4m" + line + "\x1b[0m""\n") + if not title: + title = line else: fp.write(textwrap.fill(line, self.options["width"]) + "\n") @@ -739,6 +742,12 @@ you'll be able to transparently follow links to Gopherspace!""") self.page_index = 0 self.index_index = -1 + # If the supplied GI didn't have a name (e.g. we arrived at it from a + # manually entered URL, not a link), use the title inferred from the + # first top level header + if not menu_gi.name: + menu_gi.name = title + def _format_geminiitem(self, index, gi, url=False): """ Render a link line.