Cyrogen
と言うClojure
で書かれた静的サイトジェネレータを使ってみた。
ブログを書くのに必要な機能が一通り入っていた。
Hugo
がいいかClojure
を使いたいCryogen
を見つけるhttps://cryogenweb.org/に従えばすぐできた。lein run
でビルド、lein serve
でテストサーバ起動。
content/config.edn
に:theme
の設定があり、これでテーマを変えられる。nucleus
を使うことにした。
themes/{テーマ名}/html
にテンプレートがあるので、ここをいじると不要な要素消せる。
これで、余計なアイコンとかを消した。
themes/{テーマ名}/css
にCSSがあるので、ここをいじるとスタイル調整できる。
これで、背景をダークに、文字色を白に変えた。
Cryogen公式見ると、src/core.clj
で以下のようにcompile-assets-timed
にフックしたいタイミングをキーにセットして、そこで呼ばれる関数を渡すとできるみたい。
+ (defn compile-site
+ (compile-assets-timed
+ {:extend-params-fn
+ (fn extend-params [params site-data]
+ (let [tag-count (->> (:posts-by-tag site-data)
+ (map (fn [[k v]] [k (count v)]))
+ (into {}))]
+ (update
+ params :tags
+ #(map (fn [t] (assoc t
+ :count (tag-count (:name t))))
+ %))))}))
(defn -main []
(load-plugins)
- (compile-assets-timed)
+ (compile-site)
(System/exit 0))
この例だと、{{tag.count}}
をテンプレート内で使えるようになる。
フックできるタイミングはcryogen_core/compiler.clj
のcompile-assets
を見ると書いていた。
(defn compile-assets
"Generates all the html and copies over resources specified in the config.
Params:
- `overrides-and-hooks` - may contain overrides for `config.edn`; anything
here will be available to the page templates, except for the following special
parameters:
- `:extend-params-fn` - a function (`params`, `site-data`) -> `params` -
use it to derive/add additional params for templates
- `:postprocess-article-html-fn` - a function (`article`, `params`) -> `article`
called after the `:content` has been rendered to HTML and
right before it is written to the disk. Example fn:
`(fn postprocess [article params] (update article :content selmer.parser/render params))`
- `:update-article-fn` - a function (`article`, `config`) -> `article` to update a
parsed page/post. Return nil to exclude it.
- `changeset` - as supplied by
[[cryogen-core.watcher/start-watcher-for-changes!]] to its callback
for incremental compilation, see [[only-changed-files-filter]]
for details
Note on terminology:
- `article` - a post or page data (including its title, content, etc.)
- `config` - the site-wide configuration ± from `config.edn` and the provided overrides
- `params` - `config` + content such as `:pages` etc.
- `site-data` - a subset of the site content such as `:pages`, `:posts` - see the code below"
...)