From 4868ad66a1e2b1442b5c64ce94250e9b18889f2f Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 1 Nov 2023 23:31:25 +1100 Subject: Add an example to download google docs as odt --- url-rewrite.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/url-rewrite.el b/url-rewrite.el index 8fd2028..e3d2f2b 100644 --- a/url-rewrite.el +++ b/url-rewrite.el @@ -129,6 +129,13 @@ QUERIES-TO-REMOVE is a regexp." "Replace host in URLOBJ with NEW-HOST in place." (setf (url-host urlobj) new-host)) +(defun url-rw-replace-path-regexp (urlobj regexp rep) + "Replace REGEXP in the path of URLOBJ with REP in place." + (pcase-let ((`(,path . ,query) (url-path-and-query urlobj))) + (setf (url-filename urlobj) + (concat (replace-regexp-in-string regexp rep path) + (when query (concat "?" query)))))) + (defun url-rw-replace-path (urlobj new-path) "Replace the path of URLOBJ with NEW-PATH in place." (pcase-let ((`(_ . ,query) (url-path-and-query urlobj))) @@ -229,6 +236,12 @@ has exceeded `url-rw-max-rewrites', stop." :match (concat url-rw-www-re (rx "google.com/search?q=")) :actions ((replace-host "html.duckduckgo.com") (replace-path "/html"))) + (:name google-docs-odt + :description "Download Google docs document as odt." + :match (concat url-rw-www-re (rx "docs.google.com/document/d/")) + :actions ((replace-path-regexp "\\(/document/d/.*?\\)/.*" + "\\1/export") + (put-query "format" "odt"))) (:name reddit-to-old :description "Reddit to old Reddit" :match (concat url-rw-www-re (rx "reddit.com")) -- cgit v1.2.3