commit a975ff45981f8d5cda29daa9f278bc4bcfc9207d
parent 5ad2a1e64d4b4dd19d4dd878446996d53826affb
Author: Natalie Pendragon <natpen@natpen.net>
Date: Sat, 4 Jul 2020 06:43:27 -0400
Improve discovery of backlinks
Specifically, make sure the query picks up backlinks pointing to both
the slashed and slashless version of the URL in question.
Diffstat:
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/gus/build_index.py b/gus/build_index.py
@@ -108,10 +108,17 @@ def create_index(index_dir):
def index_page(page):
- backlinks = (Page
- .select()
- .join(Link, on=Link.from_page)
- .where(Link.to_page == page))
+ print(page.url)
+ url = page.url.rstrip("/")
+ from_page = Page.alias()
+ to_page = Page.alias()
+ backlinks = (Link
+ .select(from_page)
+ .join(from_page, on=(from_page.id == Link.from_page_id))
+ .join(to_page, on=(to_page.id == Link.to_page_id))
+ .where(to_page.url << [url, f"{url}/"])
+ .dicts())
+
document = {
"url_id": page.url,
"url": page.url,
@@ -123,7 +130,7 @@ def index_page(page):
"lang": page.lang,
"size": page.size,
"indexed_at": page.indexed_at,
- "backlinks": " ".join([b.url for b in backlinks]),
+ "backlinks": " ".join([b["url"] for b in backlinks]),
"prompt": page.prompt,
"content": page.content,
}
diff --git a/serve/templates/news.gmi b/serve/templates/news.gmi
@@ -3,7 +3,7 @@
## News
-### 2020-06-30
+### 2020-07-03
Added support for viewing backlinks to pages. You can find this functionality on search result pages when in verbose mode. If GUS knows of pages linking to a given result (a.k.a., a "backlink"), it will add an option to view those backlinks. This comes on the heels of some interesting discussion regarding tracking replies in Geminispace, and could open the door to some novel functionality built on top of this feature - e.g. the ability to "subscribe" to updates to your own posts, and if a new backlink is discovered, it could notify you somehow. Alternatively, since the URL structure to reach a given page's backlinks page is predictable, one could also simply place a link on content pages to their corresponding GUS backlinks page, which readers could navigate to after reading, to find related content to read. As always, documentation for this new feature can be found on the about page. A number of small changes to verbose mode also went out with this release - in particular, there is now a button on search result pages to toggle verbose mode, so you don't need to muck around with the URL manually to toggle it, and verbose mode is now sticky between search result pages when using the previous/first/next page links at the bottom.
### 2020-06-12