shikensu: Run a sequence of functions on in-memory representations of files

[ filesystem, library, mit ] [ Propose Tags ] [ Report a vulnerability ]
Versions [RSS] 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5, 0.3.6, 0.3.7, 0.3.8, 0.3.9, 0.3.10, 0.3.11, 0.4.0, 0.4.1
Change log CHANGELOG.md
Dependencies aeson (>=2 && <3), base (>=4.9 && <5), bytestring (>=0.10 && <0.12), directory (>=1 && <2), filepath (>=1 && <2), flow (>=1.0 && <3), Glob (>=0.7 && <1), text (>=1 && <2), unordered-containers (>=0.2 && <0.3) [details]
License MIT
Author
Maintainer Steven Vandevelde <icid.asset@gmail.com>
Category Filesystem
Home page https://github.com/icidasset/shikensu#readme
Bug tracker https://github.com/icidasset/shikensu/issues
Source repo head: git clone https://github.com/icidasset/shikensu
Uploaded by icidasset at 2022-01-09T14:46:18Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 10934 total (29 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-09 [all 1 reports]

Readme for shikensu-0.4.1

[back to package description]

Shīkensu

シーケンス
Sequence

Run a sequence of functions on in-memory representations of files.
Build static websites with ease, without conforming to a specific structure.

Markdown example

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

This lists all the markdown files in the ./src directory
and then does the following in this exact order:

  1. Change the extension of each matched file to .html.
  2. Change the path of each matched file to %matched_path/%file_basename/index.%file_extension.
  3. Make an in-memory copy of the file that has the index.html path.
  4. Copy the information of each definition (aka. file) to its metadata "object" (so we can use that information in our content renderer).
  5. Map the content property of each definition (in this case we are rendering markdown).
  6. {post-flow} Write to the ./build directory.

Why?

Because this allows me to easily define a workflow for building a static website, and more specifically:

  • Have a clear overview of what's happening.
  • Do a bunch of actions in memory and then write it to disk in one go.
  • Have a list of information about the other files in the project which can then be shared with, for example, templates.

Usage examples