Scheme:CHICKEN:Hydeを使ってみる
CHICKEN Scheme で書かれた静的サイトジェネレータ Hyde を試す。
目次
Download and Install CHICKEN
Download CHICKEN Source code
http://code.call-cc.org/ で最新バージョンを落とす。しかし、
Version5がリリースされているのは全世界の常識ですが、真に遺憾ながらライブラリの移植が現在進行中
ということなので、とりあえず4系を Index of /releases から落とす。
$ wget http://code.call-cc.org/releases/4.13.0/chicken-4.13.0.tar.gz
$ tar xf chicken-4.13.0.tar.gz
$ cd chicken-4.13.0
Compile and Install
引用 README
make PLATFORM=<platform> PREFIX=<destination>
make PLATFORM=<platform> PREFIX=<destination> install
Enter "make" without any options to see a list of supported platforms.
"PREFIX" defaults to "/usr/local".
$ make PLATFORM=linux PREFIX=${HOME}/usr/local
$ make PLATFORM=linux PREFIX=${HOME}/usr/local install
以下エラー
/home/kobapan/usr/local/bin/chicken-install -update-db
loading import libraries ...
generating database ...
Error: (open-output-file) cannot open file - No such file or directory: "/home/kobapan/local/lib/chicken/11/modules.db"
rules.make:336: ターゲット 'install-bin' のレシピで失敗しました
make[1]: [install-bin] エラー 70 (無視されました)
mkdir -p /home/kobapan/local/lib/chicken/11
再度インストールでおっけー
ドキュメンテーション
$ chicken-install apropos chicken-doc
$ cd `csi -p '(chicken-home)'`
$ curl http://3e8.org/pub/chicken-doc/chicken-doc-repo.tgz | tar xf
emacs support
Geiser: Installation を参考に、geiserをインストール
Emacs:シェル の PATH と alias を引き継ぐ を参考に、PATHを通す。
以下.emacsなどに書く
(load-file "~/.emacs.d/site-lisp/geiser/elisp/geiser.el")
(add-to-list 'auto-mode-alist '("\\.\\(sxml\\|scm\\)\\'" . scheme-mode))
(setq geiser-active-implementations '(chicken))
Install Hyde from egg
CHICKENのライブラリはeggからとってこれる
$ chicken-install hyde
依存関係も含めてeggをダウンロード、インストールしてくれる
各eggごとに.soファイルへコンパイルしてインストールという作業をするので時間がかかる
ソースコードを読みたいなら、-r オプションをつけると、カレントディレクトリにscmファイルを落としてくれる
$ chicken-install -r hyde
$ find
.
./hyde
./hyde/hyde.scm
./hyde/hyde.setup
./hyde/hyde.meta
./hyde/hyde-page-eval-env.scm
./hyde/hyde-cmd.scm
./hyde/hyde-atom.scm
install lowdown
Markdown を使うために、lowdownをインストールする。
lowdown - The CHICKEN Scheme wiki
$ chicken-install lowdown
対応している Markdown 書式は、daringfireball.net を参照する。
hyde のデフォルトのmdファイル用translater(translate-markdown)は、何もしてくれない。これは外部モジュールをAPIとして呼ぶための定義だけしてある。
An alist of source language translators indexed by file extensions. Default:
`(("sxml" ,translate-sxml) ("scss" ,translate-scss (ext . css) (layouts)) ("md" ,translate-markdown) ("wiki" ,translate-svnwiki) ("sw" ,translate-svnwiki))
Additionally, `("atom" ,translate-atom (ext . atom) (layouts)) can be made available by loading the hyde-atom extension from your site's hyde.scm.
To use Lowdown for Markdown pages you need to define a custom page translator in your site's hyde.scm like this:
(use lowdown) (translators (cons (list "md" markdown->html) (translators)))
サイト生成
$ mkdir cool-site
$ cd cool-site/
$ hyde init
creating layouts
creating src
creating out
creating hyde.scm
creating layouts/default.sxml
hyde.scmを編集する
(use hyde)
(use lowdown)
(translators (cons (list "md" markdown->html) (translators)))
Markdown形式でindexというタイトルのファイルを作る。
$ hyde new md index
$ cat src/index.md
((title . "index"))
これがyamlフロントマター的なもの。hyde では page-var と呼ぶ。ファイル名はタイトルから勝手に作られる、ということなんだが、このオプションに日本語を使うとファイル名が空っぽになるので、タイトルは後で書き直さないといけない。なので、indexというファイル名を指定してるといった方がしっくりくる。というか、index.mdという新しいファイルを作ってね、という指定なのか。
hyde new せずに、emacs のテンプレートを使った方が楽かな。
続いて本文を書く
((title . "index"))
Hey, welcome to my cool site!
[lowdown](http://wiki.call-cc.org/eggref/5/lowdown#lowdown)
で、hyde する
$ hyde
cleaning output directory
preparing compilation
compiling pages
index.md -> index.html
できたものを見てみると、
$ cat out/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">~% <html>~% <head>~% <title>index</title></head>~% <body>~% <h1>index</h1>~% <p>Hey, welcome to my cool site!~% <a href="http://wiki.call-cc.org/eggref/5/lowdown#lowdown">lowdown</a></p></body></html>
hyde new を使わずに、src/page_1.mdに直接書いてみる。
((title . "お問い合わせ"))お問い合わせはこちら
$ hyde
index.md -> index.html
page_1.md -> page_1.html
できた。
ローカルサーバでのテスト
$ hyde serve
1. http://localhost:8080/ をブラウザで開く。
2. プログラムを書き換える。
3. リロードする。
hyde.scm だけはリロードしても反映されないので、hyde serve を一旦 Ctrl+c して再起動が必要。
良いところ
カスタマイズしやすい
hyde.scmにガシガシ書けば割といける
Chicken がそもそもポータブル
Gaucheな人にも扱い易い
欠点
すごく限られた機能しかない。
→ いろいろ追加した。Scheme:CHICKEN:Hydeを改造する