Skip to content

Commit

Permalink
refine function
Browse files Browse the repository at this point in the history
  • Loading branch information
sillykelvin committed Sep 3, 2013
1 parent 4594f8f commit abc69f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions op-export.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion op-template.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions op-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit abc69f4

Please sign in to comment.