Pages

Wednesday, 28 December 2016

搭建基于haskell的静态博客程序ocharles-blog

先按此文http://briteming.blogspot.jp/2016/07/hakyll.html安装stack和ghc.

cd /usr/local
git clone https://github.com/ocharles/blog ocharles-blog
cd ocharles-blog

root@AR:/usr/local/ocharles-blog# ls
cabal.sandbox.config  default.nix  LICENSE        Setup.hs    templates
guest-posts  ocharles-blog.cabal    shell.nix
code              hakyll.hs    pages      
css              img       posts       
root@AR:/usr/local/ocharles-blog# stack init
root@AR:/usr/local/ocharles-blog# stack build
(这一步可能会遇到http://briteming.blogspot.com/2016/12/stack-install-wai-app-static.html文中所提到的错误,见https://github.com/ocharles/blog/issues/34。解决办法参考http://briteming.blogspot.com/2016/12/stack-install-wai-app-static.html)
会显示:
...
Linking .stack-work/dist/i386-linux/Cabal-1.24.0.0/build/ocharles-blog/ocharles-blog ...
ocharles-blog-1.0.0: copy/register
Installing executable(s) in
/usr/local/ocharles-blog/.stack-work/install/i386-linux/nightly-2016-12-23/8.0.1/bin
root@AR:/usr/local/ocharles-blog# .stack-work/dist/i386-linux/Cabal-1.24.0.0/build/ocharles-blog/ocharles-blog build (此即生成/更新静态网站的根目录的命令.此步会遇到错误提示,解决办法:把帖子的title的值加上英文单引号或双引号)
root@AR:/usr/local/ocharles-blog# ls
cabal.sandbox.config  default.nix  LICENSE        Setup.hs    templates
_cache              guest-posts  ocharles-blog.cabal    shell.nix
code              hakyll.hs    pages        _site
css              img       posts        stack.yaml
(生成了_site目录)
root@AR:/usr/local/ocharles-blog# cd _site
root@AR:/usr/local/ocharles-blog/_site# ls
css  guest-posts  img  index.html  pages  posts  posts.rss
root@AR:/usr/local/ocharles-blog/_site#
(可见 /usr/local/ocharles-blog/_site就是静态网站的根目录)

新建源帖:
root@AR:/usr/local/ocharles-blog/_site# cd ../posts
root@AR:/usr/local/ocharles-blog/posts# nano 2016-12-28-test-1.md
root@AR:/usr/local/ocharles-blog/posts# cat 2016-12-28-test-1.md
---
title: 测试1
---

这是测试1.

root@AR:/usr/local/ocharles-blog/posts#  cd ..
root@AR:/usr/local/ocharles-blog# .stack-work/dist/i386-linux/Cabal-1.24.0.0/build/ocharles-blog/ocharles-blog build

演示网站:http://ocb.bright.biz.st/, https://ocharles.org.uk/blog/(程序作者的博客)
项目地址:https://github.com/ocharles/blog
https://github.com/ocharles/blog/issues/34