本文讨论用 weblogger 写 WordPress 博客的相关技术问题,本文内容大量参考 vvoody 的《用weblogger写WordPress博客》一文中的内容,略作修改,在此深表谢意。
此文让你不用登录 wordpress 的后台程序撰写博客,而是利用 Emacs ! 源起看到eexpress用 vim 来写 wordpress,所以想着 Emacs 有没有此类插件。Google 了一下,果然有 weblogger 这个一个库。看了下别的资料,在此简单整理下使用方法。
本文只针对 WordPress 用户,虽然介绍可以使用 Blogger, MetaWeblog 等博客程序,还请读者自己尝试。测试环境 Emacs 23.1.1。
1. 下载weblogger.el 和 xml-rpc.el
这两个文件我已经打过补丁,分别来自Gabriel Saldaña、rix和wd,感谢他们。现在weblogger可以正常使用分类、Tags、html、permlink。
2. 把这个两个 el 文件放到你的 Emacs 启动路径里,比如我的是:~/.emacs.d/site-lisp
3. 在 ~/.emacs 里添加一句:(require ‘weblogger)
1. 先得设置你的博客,M-x weblogger-setup-weblog。
2. Server Endpoint (URL): http://vvoody.org/blog/xmlrpc.php WordPress 的博客必须填 xmlrpc.php。
3. 输入用户名密码后,Emacs 就会提示你连接成功,会将你博客的信息添加在 .emacs 文件末尾。 PS: 千万别把空间的用户名和博客的用户名搞混,我就是因为这个登了半天也上不去。
1. M-x weblogger-select-configuration,选择你刚才设置的配置信息,否则默认是 openweblog.com。以后每次要登录你的博客都要使用这个命令。
2. M-x weblogger-start-entry 初始有 Subject, Categories, Permlink, Tags, From, Newsgroup 和 –text follow this line–。 Categories就是文章分类,这个分类必须是在你的博客中已经存在的,否则你新创建一个最后系统还是会认成 Uncategorized。编辑状态见下图:
用weblogger写 WordPress博客
3. 当你写完要发表时用命令:M-x weblogger-publish-entry (C-x C-s)来发表你的文章。如果你暂时不想发表的话,那么 M-x weblogger-save-entry 则是将你文章保存到服务器上,下次可以继续编辑。
weblogger 会自动保存你的博客在 ~/Mail/drafts 里。
你可能想发表之前保存的草稿,或者不满意已经发表的文章,需要修改或者删除,那么你需要用到:M-x weblogger-fetch-entries (之前你仍需要 M-x weblogger-select-configuration ,输入密码后登录)。
fetch 来的第一篇文章一般是草稿,如果没有草稿则是最新发表的文章。当然,你可以使用 M-x weblogger-prev-entry (C-c C-p) 或 M-x weblogger-next-entry (C-c C-n) 来载入前/后一篇文章。
编辑好了一篇文章/草稿后,M-x weblogger-publish-entry (C-x C-s)就可以发表了。若要删除某篇文章,则是切换到那篇文章,然后执行 M-x weblogger-delete-entry (C-c C-k)
基本的操作就是这么些,weblogger 还提供了一些文章模板什么的,这些大家可以自己尝试。
下面列出在 weblogger 模式下可用的标记:
粗体 <strong>blod</strong> 斜体 <em>italic</em> 链接 <a href=”http://www.xxx.com/” mce_href=”http://www.xxx.com/”>aLink</a> 贴图 <img src=”http://www.yyy.com/zzz.jpg” mce_src=”http://www.yyy.com/zzz.jpg” alt=”zzz.jpg” /> 列表 <ul><li>item_1</li><li>item_2</li></ul> <ol><li>item_1</li><li>item_2</li></ol> 代码 ── <code>int main()</code> 引用 ── <blockquote>aQuote</blockquote> 更多 ── <!–more–>many many words… ‘<’ ── < ‘>’ ── >
详细的操作快捷键如下:
;; C-x C-s -- post-and-publish current buffer to the weblog. ;; Calling weblogger-publish-entry with an prefix argument ;; (i.e. C-u C-x C-s) will prompt for which weblog ;; to use. ;; C-c C-c -- save as draft and bury the buffer. ;; C-c C-n -- post (but not publish) the current entry and ;; load the next entry. ;; C-c C-p -- post (but not publish) the current entry and ;; load the previous entry. ;; C-c C-k -- delete the current entry. ;; M-g -- synchronise weblogger.el's idea of the entries available ;; with the weblog server. ;; C-c C-t m -- edit the main template. ;; C-c C-t a -- edit the Archive Index template ;; C-c C-s s -- Change the server being used. ;; C-c C-s w -- Change the weblog. ;; C-c C-s u -- Change the user (re-login).
以上代码就是 WordPress 中的代码编辑方式中插入的代码,可以直接在 weblogger 模式里用。
参考:
注:如果你发现撰写时候的格式和最终发布显示的格式不一样,建议关闭auto-fill-mode. 另外, 编辑已发布的文章并再次发布有时间问题,快8小时。