Browse Source

org-protocol: Sources with date URL are supported

lisp/org-protocol.el (org-protocol-project-alist): Date-URL is added
as example.
(org-protocol-open-source): First match is processed in rewrite.

testing/lisp/test-org-protocol.el (test-org-protocol/org-protocol-open-source):
Configuration displaying a date-style URL is added.

TINYCHANGE
Mario Martelli 2 years ago
parent
commit
37bba84a5e
2 changed files with 20 additions and 4 deletions
  1. 14 3
      lisp/org-protocol.el
  2. 6 1
      testing/lisp/test-org-protocol.el

+ 14 - 3
lisp/org-protocol.el

@@ -194,7 +194,14 @@ Example:
           :working-suffix \".org\"
           :base-url \"http://localhost/org/\"
           :working-directory \"/home/user/org/\"
-          :rewrites ((\"org/?$\" . \"index.php\")))))
+          :rewrites ((\"org/?$\" . \"index.php\")))
+         (\"Hugo based blog\"
+          :base-url \"https://www.site.com/\"
+          :working-directory \"~/site/content/post/\"
+          :online-suffix \".html\"
+          :working-suffix \".md\"
+          :rewrites ((\"\\(https://site.com/[0-9]+/[0-9]+/[0-9]+/\\)\" . \".md\")))))
+
 
    The last line tells `org-protocol-open-source' to open
    /home/user/org/index.php, if the URL cannot be mapped to an existing
@@ -556,8 +563,12 @@ The location for a browser's bookmark should look like this:
 		      ;; Try to match a rewritten URL and map it to
 		      ;; a real file.  Compare redirects without
 		      ;; suffix.
-		      (when (string-match-p (car rewrite) f1)
-			(throw 'result (concat wdir (cdr rewrite))))))))
+		      (when (string-match (car rewrite) f1)
+			(let ((replacement
+			       (concat (directory-file-name
+					(replace-match "" nil nil f1 1))
+				       (cdr rewrite))))
+			  (throw 'result (concat wdir replacement))))))))
 	      ;; -- end of redirects --
 
               (if (file-readable-p the-file)

+ 6 - 1
testing/lisp/test-org-protocol.el

@@ -137,7 +137,12 @@
 	     :base-url "http://another.example.com/"
 	     :online-suffix ".js"
 	     :working-directory ,(file-name-directory temp-file-name2))
-	    ))
+	    (test3
+	     :base-url "https://blog-example.com/"
+	     :working-directory ,(file-name-directory temp-file-name2)
+	     :online-suffix ".html"
+	     :working-suffix ".md"
+	     :rewrites (("\\(https://blog-example.com/[0-9]+/[0-9]+/[0-9]+/\\)" . ".md")))))
 	 (test-cases
 	  (list
 	   ;; Old-style URLs