Ihor Radchenko <[email protected]> writes:

> LGTM.
> I tried to use the new code, and noticed that stackoverflow links are still
> left intact.

Thanks, I forgot about stackoverflow. Added in the attached patch. We now
replace the following four services, is that right?

- reddit
- github
- youtube
- stackoverflow

Worg also links to various tweets (org-quotes.org), but always includes the
full tweet text so I'm not sure if a redirect would add too much here.

Note three things about the SO redirection to AnonymousOverflow:

1. The current top listed instance is down, I created an issue at
   https://github.com/httpjamesm/AnonymousOverflow/issues/185 to keep the
   instance list up-to-date.

2. The script only converts stackoverflow.com/questions/question_id links.
   Worg links to stackoverflow with the following pages:
   stackoverflow.com/questions/question_id/...;
   stackoverflow.com/questions/tagged/org-mode;
   stackoverflow.com/tags/org-mode/info; stackoverflow.com/help/;
   stackoverflow.com/users/...;

   and of these, only the "basic question" type is supported by
   AnonymousOverflow.

3. The script ignores *.stackexchange.com. Adding this is not too much effort,
   but these links do not exist in Worg so I've ignored it (for now?).

> Also, looks like gothub instances are not up-to-date.
> Reported https://codeberg.org/LibRedirect/instances/issues/40, but we
> may need some way to check that things are working, so that we have
> heads up and report to libredirect as needed. Maybe some additional
> check that an URL is live at the time is publishing.

I believe that LibRedirect considers it not their responsibility to check
whether instances are working, see
https://github.com/libredirect/instances/issues/56 and
https://libredirect.github.io/faq.html#where_the_hell_are_those_instances_coming_from.

Nonetheless, creating an issue is a good idea, because the gothub list of
instances at
https://codeberg.org/gothub/gothub-instances/src/branch/master/instances.json
differs in content, so the LibRedirect script does seems to fail.

> This is a fine approach.
> Another way is sending patch + a diff.
> Or just a diff followed by full patch after discussion finishes.
> Or creating a branch on public repo or in worg itself and working from there.

OK, I've attached a patch that includes only my change, is that sufficient?

Best,
Rens

>From 59b1ea363ba0a361ebea2ec541d5814689f9df65 Mon Sep 17 00:00:00 2001
From: Rens Oliemans <[email protected]>
Date: Sun, 17 May 2026 18:16:44 +0200
Subject: [PATCH] Add StackOverflow -> AnonymousOverflow redirect

---
 worg-urls-rewrite.el | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/worg-urls-rewrite.el b/worg-urls-rewrite.el
index 3ac09e1d..52b9a6c1 100644
--- a/worg-urls-rewrite.el
+++ b/worg-urls-rewrite.el
@@ -38,7 +38,8 @@
   "Contents of libredirect data, obtained from `worg-urls-libredirect-url'.")
 
 (defcustom worg-urls-free-alternatives '((youtube . invidious)
-					 (github . gothub))
+					 (github . gothub)
+					 (stackoverflow . anonymousOverflow))
   "Alist of alternative frontends to websites containing non-free JS.
 The CDR corresponds to a symbol that is known by libredirect, see
 https://codeberg.org/LibRedirect/instances.";)
@@ -105,10 +106,10 @@ links."
 
 (defun worg-urls-add-alternative-links (&optional _)
   "Add alternative links for websites containing non-free JS.
-For each link that has an alternative (currently YouTube and GitHub), we
-insert a link to the free alternative, and change the link text of the
-original link to to =(original URL)=.  We also redirect reddit links to
-old.reddit.com.
+For each link that has an alternative (currently YouTube, GitHub
+and StackOverflow), we insert a link to the free alternative, and
+change the link text of the original link to to =(original URL)=.
+We also redirect reddit links to old.reddit.com.
 
 See https://list.orgmode.org/orgmode/87pl9szmy6.fsf@localhost/";
   (unless worg-urls-libredirect-data
@@ -133,7 +134,8 @@ See https://list.orgmode.org/orgmode/87pl9szmy6.fsf@localhost/";
 			(when (string-match
 			       (rx (or "reddit.com"
 				       "github.com"
-				       "youtube.com"))
+				       "youtube.com"
+				       "stackoverflow.com"))
 			       description)
 			  (error
 			   (concat "Link description \"%s\" in %s:%s refers"
@@ -179,6 +181,8 @@ See https://list.orgmode.org/orgmode/87pl9szmy6.fsf@localhost/";
 We redirect the following links:
 - reddit.com -> old.reddit.com
 - (youtube.com|youtu.be) -> alternative from libredirect
+- stackoverflow.com/questions/question_id/... -> alternative from
+  libredirect
 - github.com -> alternative from libredirect"
   (pcase path
     ;; See https://docs.invidious.io/redirector/
@@ -241,6 +245,17 @@ We redirect the following links:
 	       (id (match-string 2 path))
 	       (host (worg-urls--first-link-of-data worg-urls-libredirect-data 'github)))
 	 (concat host "/gist/" user "/" id)))
+    ;; redirect stackoverflow to anonymousOverflow. anonymousOverflow
+    ;; only supports links of the /questions/question_id format,
+    ;; /tags/..., /questions/tagged/..., /users/..., etc are not
+    ;; supported.
+    ((rx "//" (? "www\.")
+	 "stackoverflow.com"
+	 "/questions/"
+	 (group (+ digit) (+ not-newline)))
+     (let ((question-id (match-string 1 path))
+	   (host (worg-urls--first-link-of-data worg-urls-libredirect-data 'stackoverflow)))
+       (concat host "/questions/" question-id)))
     ;; redirect reddit.com to old.reddit.com
     ((rx "//" (? "www\.")
 	 "reddit.com"
-- 
2.43.0

Reply via email to