From abc69f4820273400010d6e90541b997a6c52a71a Mon Sep 17 00:00:00 2001 From: Kelvin Hu Date: Tue, 3 Sep 2013 16:07:26 +0800 Subject: [PATCH] refine function --- op-export.el | 8 ++++---- op-template.el | 2 +- op-util.el | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/op-export.el b/op-export.el index f01a472..6329f3c 100644 --- a/op-export.el +++ b/op-export.el @@ -151,7 +151,7 @@ can contain following parameters: (fix-timestamp-string creation-date) (format-time-string "%Y-%m-%d")) "-")) - (encoded-title (convert-string-to-path title))) + (encoded-title (encode-string-to-url title))) (format-spec uri-template `((?y . ,(car date-list)) (?m . ,(cadr date-list)) (?d . ,(caddr date-list)) @@ -261,7 +261,7 @@ file attribute property lists. PUB-BASE-DIR is the root publication directory." :category-index)) (setq cat-dir (file-name-as-directory (concat (file-name-as-directory pub-base-dir) - (convert-string-to-path (car cat-list))))) + (encode-string-to-url (car cat-list))))) (unless (file-directory-p cat-dir) (mkdir cat-dir t)) (string-to-file @@ -399,7 +399,7 @@ is the root publication directory." (defun op/generate-tag-uri (tag-name) "Generate tag uri based on TAG-NAME." - (concat "/tags/" (convert-string-to-path tag-name) "/")) + (concat "/tags/" (encode-string-to-url tag-name) "/")) (defun op/update-tags (file-attr-list pub-base-dir) "Update tag pages. FILE-ATTR-LIST is the list of all file attribute property @@ -457,7 +457,7 @@ TODO: improve this function." #'(lambda (tag-list) (setq tag-dir (file-name-as-directory (concat tag-base-dir - (convert-string-to-path (car tag-list))))) + (encode-string-to-url (car tag-list))))) (unless (file-directory-p tag-dir) (mkdir tag-dir t)) (string-to-file diff --git a/op-template.el b/op-template.el index 399a58f..d06e7cb 100644 --- a/op-template.el +++ b/op-template.el @@ -91,7 +91,7 @@ render from a default hash table." (mapcar #'(lambda (cat) (ht ("category-uri" - (concat "/" (convert-string-to-path cat) "/")) + (concat "/" (encode-string-to-url cat) "/")) ("category-name" (capitalize cat)))) (sort (remove-if #'(lambda (cat) diff --git a/op-util.el b/op-util.el index 4acee25..40bc990 100644 --- a/op-util.el +++ b/op-util.el @@ -175,10 +175,10 @@ want to make org-page depend on other libraries, so I copied the function here, so do `trim-string-left' and `trim-string-right'." (trim-string-left (trim-string-right str))) -(defun convert-string-to-path (string) - "Convert a string to legal URL path -TODO: improve doc here -TODO2: maybe DBCS strings should also be converted into ASCII URL path" +(defun encode-string-to-url (string) + "Encode STRING to legal URL. Why we do not use `url-encode-url' to encode the +string, is that `url-encode-url' will convert all not allowed characters into +encoded ones, like %3E, but we do NOT want this kind of url." (downcase (replace-regexp-in-string "[ :/\\]+" "-" string))) (defun get-full-url (uri)