shikensu haskell
v0.4.1
shikensu
順序
對文件的記憶體表示形式運行一系列函數。
輕鬆建立靜態網站,無需遵守特定結構。
import Shikensu
import Shikensu.Contrib ( clone , copyPropsToMetadata , permalink , renameExt , renderContent )
import Shikensu.Contrib.IO ( read , write )
import Data.ByteString ( ByteString )
import Flow
import Prelude hiding ( read )
import qualified Data.Text.Encoding as Text ( decodeUtf8 , encodeUtf8 )
main :: IO Dictionary
main =
-- This IO operation will read the files matching the glob pattern `src/**/*.md`,
-- transform them (see the `flow` function) and then write them to the `build` directory.
dictionary_io
dictionary_io :: IO Dictionary
dictionary_io =
Shikensu. listRelative [ " src/**/*.md " ] " ./ "
>>= read
>>= flow
>>= write " ./build "
flow :: Dictionary -> IO Dictionary
flow =
renameExt " .md " " .html "
.> permalink " index "
.> clone " index.html " " 200.html "
.> copyPropsToMetadata
.> renderContent markdownRenderer
.> return
markdownRenderer :: Definition -> Maybe ByteString
markdownRenderer def =
content def
|> fmap Text. decodeUtf8
|> fmap Markdown. render
|> fmap Text. encodeUtf8
這列出了./src
目錄中的所有 markdown 文件
然後按照這個確切的順序執行以下操作:
.html
。%matched_path/%file_basename/index.%file_extension
。index.html
路徑的文件的記憶體副本。content
屬性(在本例中我們正在渲染 markdown)。./build
目錄。因為這讓我可以輕鬆定義建立靜態網站的工作流程,更具體地說: