7

org2blog--将org发布到wordpress

 3 years ago
source link: https://www.lujun9972.win/blog/2015/04/24/org2blog--%E5%B0%86org%E5%8F%91%E5%B8%83%E5%88%B0wordpress/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

2.1 配置blog信息

`org2blog/wp-blog-alist'定义了多个blog的信息.其中每个元素的car为一个表示blog的名称的字符串,每个元素的cdr为一个plist,为每个blog提供属性说明.

(setq org2blog/wp-blog-alist
      `(("DarkSun.1kapp.com"
         :url "http://darksun.1kapp.com/xmlrpc.php"
         :username "lujun9972"
         :default-categories ("Emacs")
         :keep-new-lines t
         :confirm t
         :wp-code nil
         :tags-as-categories nil)
        ("DarkSun.blog.51cto.com"
         :url "http://darksun.blog.51cto.com/xmlrpc.php"
         :username "lujun9972"
         :default-categories ("Emacs")
         :keep-new-lines t
         :confirm t
         :wp-code nil
         :tags-as-categories nil)))

关于plist中的属性说明如下:

urlblog中xmlrpc的url地址,必填 username登陆blog的用户名,必填 password登陆blog的密码 default-title新建文章时的默认标题,默认值为`org2blog/wp-default-title'的值 default-categories新建文章时默认所属的类别列表,默认值为`org2blog/wp-default-categories'的值 tags-as-categories是否将文章tag作为文章的类别,默认值为`org2blog/wp-use-tags-as-categories'的值 confirm发布文章时,是否需要用户确认,默认值为`org2blog/wp-confirm-post'的值 show发布完文章后,是否使用浏览器访问该文章. 默认值为`org2blog/wp-show-post-in-browser'的值 keep-new-lines是否删除文章中的空行. 默认值为`org2blog/wp-keep-new-lines'的值 wp-latex是否将org文件中的LaTeX代码转换为WP的latex代码. 默认值为`org2blog/wp-use-wp-latex'的值 wp-code是否将org中的<pre>…</pre>转换为WP的源代码块格式. 默认值为`org2blog/wp-use-sourcecode-shortcode' track-posts是否追踪已发布的文章,若允许追踪,则会在发布的org文件中增加`#+POSTID: '行,通过这种方法可以更新已发布的文章.

2.2 配置post templates

通过修改变量`org2blog/wp-buffer-template'和`org2blog/wp-buffer-format-function'的值可以自动以新建文章的内容模板.

其中org2blog使用(funcall org2blog/wp-buffer-format-function org2blog/wp-buffer-template)的返回值作为新建的文章模板.

(setq org2blog/wp-buffer-template "#+TITLE: %s\n#+AUTHOR: %s\n#+DATE: %s\n#+OPTIONS: toc:nil num:nil todo:nil pri:nil tags:nil ^:nil\n#+CATEGORY: %s\n#+TAGS:\n#+DESCRIPTION:\n\n")

(defun org2blog/wp-format-buffer-with-author (buffer-template)
  "Default buffer formatting function."
  (format buffer-template
          ;; TITLE
          (or (plist-get (cdr org2blog/wp-blog) :default-title)
              org2blog/wp-default-title
              (read-string "请输入POST标题:"))
          ;; AUTHOR
          user-login-name
          ;; DATE
          (format-time-string "[%Y-%m-%d %a %H:%M]" (current-time))
          ;; CATEGORY
          (mapconcat
           (lambda (cat) cat)
           (or (plist-get (cdr org2blog/wp-blog) :default-categories)
               org2blog/wp-default-categories)
           ", ")
          ))

(setq org2blog/wp-buffer-format-function 'org2blog/wp-format-buffer-with-author)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK