Pages

Wednesday, 19 March 2014

在linux vps上搭建基于emacs的orgmode的静态博客程序-bastibe

首先把如下代码添加到~/.emacs.el文件的尾部:

(setq org-publish-project-alist
      '(("blog"
         :components ("blog-content" "blog-static"))
        ("blog-content"
         :base-directory "~/Projects/blog/posts"
         :html-extension "html"
         :base-extension "org"
         :publishing-directory "~/Projects/blog/publish"
         :publishing-function (org-html-publish-to-html)
         :auto-sitemap t
         :sitemap-filename "archive.org"
         :sitemap-title "Archive"
         :sitemap-sort-files anti-chronologically
         :sitemap-style list
         :makeindex t
         :recursive t
         :section-numbers nil
         :with-toc nil
         :with-latex t
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-head-extra
         "<link rel=\"alternate\" type=\"appliation/rss+xml\"
                href=\"http://bastibe.de/rss.xml\"
                title=\"RSS feed for bastibe.de\">
          <link href='http://fonts.googleapis.com/css?family=Roboto&subset=latin' rel='stylesheet' type='text/css'>
          <link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'>
          <link href= \"static/style.css\" rel=\"stylesheet\" type=\"text/css\" />
          <title>Basti's Scratchpad on the Internet</title>
          <meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=UTF-8\" />
          <meta name=\"viewport\" content=\"initial-scale=1,width=device-width,minimum-scale=1\">"
         :html-preamble
         "<div class=\"header\">
              <a href=\"http://bastibe.de\">Basti's Scratchpad on the Internet</a>
              <div class=\"sitelinks\">
                  <a href=\"http://alpha.app.net/bastibe\">alpha.app.net</a>  | <a href=\"http://github.com/bastibe\">Github</a>
              </div>
          </div>"
         :html-postamble
         (lambda (info)
           "Do not show disqus for Archive and Recent Posts"
           (cond ((string= (car (plist-get info :title)) "Archive") "")
                 ((string= (car (plist-get info :title)) "Recent Posts")
                  "<div id=\"archive\"><a href=\"archive.html\">Other posts</a></div>")
                 (t
             "<div id=\"archive\"><a href=\"archive.html\">Other posts</a></div>
              <div id=\"disqus_thread\"></div>
              <script type=\"text/javascript\">
              /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
              var disqus_shortname = 'bastibe';
              /* * * DON'T EDIT BELOW THIS LINE * * */
              (function() {
                var dsq = document.createElement('script');
                dsq.type = 'text/javascript';
                dsq.async = true;
                dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
                  })();
              </script>
              <noscript>Please enable JavaScript to view the
                  <a href=\"http://disqus.com/?ref_noscript\">comments powered by Disqus.</a></noscript>
              <a href=\"http://disqus.com\" class=\"dsq-brlink\">comments powered by <span class=\"logo-disqus\">Disqus</span></a>")))
         :exclude "rss.org\\|archive.org\\|theindex.org")
        ("blog-static"
         :base-directory "~/Projects/blog/static"
         :base-extension "png\\|jpg\\|css"
         :publishing-directory "~/Projects/blog/publish/static"
         :recursive t
         :publishing-function org-publish-attachment)))

as3:~# mkdir -p ~/Projects/blog/posts ~/Projects/blog/static
as3:~# mkdir -p ~/Projects/blog/publish
as3:~# mkdir -p ~/Projects/blog/publish/static
as3:~# wget https://github.com/bastibe/bastibe.github.com/archive/source.zip
as3:~# unzip source.zip
as3:~# cd bastibe.github.com-source/
as3:~/bastibe.github.com-source# ls
CNAME  posts  static bastibe.github.com
as3:~/bastibe.github.com-source# ls bastibe.github.com
as3:~/bastibe.github.com-source# rm -rf bastibe.github.com
as3:~/bastibe.github.com-source# ls
CNAME  posts  static
as3:~/bastibe.github.com-source# mv posts/* ~/Projects/blog/posts/
as3:~/bastibe.github.com-source# mv static/* ~/Projects/blog/static/
as3:~/bastibe.github.com-source# cd ~/Projects/blog/posts/
as3:~/Projects/blog/posts# ls
2009-03-05-great-scott.org
2009-03-12-kompilieren-auf-windows.org
2009-03-14-get-a-mac.org
2009-03-15-debugging-und-gcc-auf-windows.org
2009-03-19-western-digital-festplatten-umtausch-mit-uberraschungen.org
2009-03-24-e-text-editor-goes-open-source.org
2009-03-28-synchronisieren-von-google.org
2009-03-29-mirrors-edge.org
2009-03-31-es-geht-um-tabs.org
2009-04-19-tagged-file-system.org
2009-04-25-gedanken-zu-user-interfaces.org
2010-07-03-strangeness-of-widescreen-displays-in-modern-operating-systems.org
2011-02-03-installing-python-slash-numpy-slash-scipy-slash-matplotlib-on-osx.org
2011-03-04-installing-pygame-using-homebrew.org
2011-08-01-compiling-scipy-and-matplotlib-using-pip-on-lion.org
2011-09-03-adobe-air-application-crashes.org
2011-10-13-compiling-scipy-and-matplotlib-again.org
2011-12-04-how-to-make-tagbar-work-with-objective-c.org
2012-02-03-text-editors.org
2012-02-22-how-to-gem-install-rlua-on-osx-slash-homebrew.org
2012-07-09-apple-is-failing-me.org
2012-07-15-solarized-for-pygments.org
2012-07-18-blogging-with-pelican.org
2012-07-29-using-raspberry-pi-as-time-machine.org
2012-08-28-errors-in-epydoc.org
2012-09-08-on-the-virtue-of-oss.org
2012-09-13-Kindle-app-does-not-start.org
2012-09-20-story-about-schemes.org
2012-10-13-emacs.org
2012-10-14-emacs-customizations.org
2012-10-20-matlab-mex-and-osx.org
2012-10-28-names.org
2012-11-01-apple-tv.org
2012-11-02-real-time-signal-processing-in-python.org
2013-01-20-a-python-primer-for-matlab-users.org
2013-05-30-speeding-up-matplotlib.org
2013-11-13-blogging-with-emacs.org
2013-11-27-audio-in-python.org
archive.org
index.org
rss.org
theindex.inc
theindex.org
as3:~/Projects/blog/posts# emacs index.org (这个就是生成/更新静态网站的命令。)

发贴方法:
as3:~/Projects/blog/publish# cd ~/Projects/blog/posts
as3:~/Projects/blog/posts# nano 2014-03-19-test1.org
按~/Projects/blog/posts/里面某个org文件的格式,新建帖子2014-03-19-test1.org,格式如下:
#+title: 测试1

这是测试1.


(如果要插入html代码,则格式为:
#+TITLE: 某个标题
#+BEGIN_HTML
这里插入html 代码
#+END_HTML

这里写一些文字。

然后,
as3:~/Projects/blog/posts# nano index.org
在此行* [[file:2013-11-27-audio-in-python.org][Sound in Python]]的上一行加上:
* [[file:2014-03-19-test1.org][测试1]]

然后,
as3:~/Projects/blog/posts# emacs index.org
(这个就是更新静态网站的命令。上面需先编辑index.org,否则所发表的帖子的超链地址不会出现在首页)
(按alt+x,输入org-publish-project,回车,输入blog,回车,可能会出现提示:
Invalid read syntax: "#",没关系,重来一次,再按alt+x,输入org-publish-project,回车,输入blog,回车,等到emacs编辑器里面的文字闪动停止,即可。按ctrl+x ctrl+c退出emacs.)
as3:~/Projects/blog/posts# cd ~/Projects/blog/publish/
as3:~/Projects/blog/publish# nohup Rwebserver 35637 > /dev/null &
访问http://as3.brite.biz:35637/即可看到网站效果。

~/Projects/blog/publish/就是静态网站的根目录。

演示地址:http://as3.brite.biz:35637/,http://bt.brite.biz.st, http://luckypoem.bitbucket.io
程序作者的演示站点:http://bastibe.de/,
教程:http://bastibe.de/2013-11-13-blogging-with-emacs.html
这个程序有个特点:所发表的帖子的超链会自动出现在http://bt.brite.biz.st/archive.html 里面。
项目地址:https://github.com/bastibe/bastibe.github.com/tree/source
源码下载地址:https://github.com/bastibe/bastibe.github.com/archive/source.zip


相关帖子:在linux vps上搭建基于emacs的orgmode的静态博客程序-Homepage