08
qr-code

o-blog patch for How to use tags

So, I wanted the tag to have dots (.) in it, but it seems the org mode tags do not support it.

O-blog has How to use tags, and says:

Special characters used in tags:

At sign (@) is converted to a dash (-). Underscore (_) is converted to a blank ( ).

… and it seems that those are the only non letters/numbers available. However, in experimenting, it seems that the pound sign (#) can be used, so we simply have to add the transformation for that.

(defun ob-parse-entry()
  "Parse blog entry from current position"
  (when (search-forward-regexp org-complex-heading-regexp
                               (point-at-eol)
                               t)
    (let* ((title (match-string-no-properties 4))
           ;; tags is a list of `ob:tags'
           ;; to be compliant with org tag syntax (no "-" org space)
           ;; "_" would be replaced with " " and "@" by "-"
           (tags (loop for tn in (org-get-local-tags)
                       with td
                       do (setf td
                                (replace-regexp-in-string
                                 "_" " "
                                 (replace-regexp-in-string 
                                  "@" "-" 
                                  (replace-regexp-in-string 
                                   "#" "." tn))))
                       and collect (make-ob:tags
                                    :name td
                                    :safe (ob:sanitize-string td))))

           ;; Timestamp is taken from either the CLOSED property or the
           ;; current timestamp.
           (timestamp (apply 'encode-time
                             (org-parse-time-string
                              (or (org-entry-get (point) "CLOSED")
                      (time-stamp-string "%:y-%02m-%02d %02H:%02M:%02S %u")))))
           ;; Some other time variables
           (year (string-to-number (format-time-string "%Y" timestamp)))
           (month (string-to-number (format-time-string "%m" timestamp)))
           (day (string-to-number (format-time-string "%d" timestamp)))

           (category (or (org-entry-get (point) "category")
                         (car (last (org-get-outline-path)))
                         (org-entry-get (point) "ARCHIVE_OLPATH")
                         (ob:blog-default-category BLOG)))
           (category-safe (ob:sanitize-string category))
           (page (org-entry-get (point) "PAGE"))

           (filename (or (org-entry-get (point) "CUSTOM_ID")
                         (ob:sanitize-string title)))
           (filepath (funcall (ob:blog-posts-filepath BLOG) category-safe year month))
           (htmlfile (funcall (ob:blog-posts-htmlfile BLOG) filepath day filename)))

      (when page
        (setq htmlfile page
              filename (file-name-sans-extension (file-name-nondirectory htmlfile))
              filepath (file-name-directory htmlfile)))

      (let ((content (ob-get-entry-text)))
        (make-ob:post :title title
                      :tags tags
                      :timestamp timestamp
                      :year year
                      :month month
                      :day day
                      :filename filename
                      :filepath filepath
                      :path-to-root (file-relative-name "." filepath)
                      :htmlfile htmlfile
                      :template (or (org-entry-get (point) "TEMPLATE")
                                    (if page "blog_static.html" "blog_post.html"))
                      :content content
                      :content-html (ob-export-string-to-html content)
                      :category (make-ob:category
                                 :name category
                                 :safe category-safe)
                      :sitemap (or (org-entry-get (point) "SITEMAP"))
                      )))))
blog comments powered by Disqus