sitepipe-0.2.0.0: A simple to understand static site generator

Safe HaskellNone
LanguageHaskell2010

SitePipe

Contents

Synopsis

SitePipe

This module re-exports everything you need to build a site. In addition to exporting all of SitePipe it also exports Data.Aeson, Data.Aeson.Lens, Control.Lens, System.FilePath.Posix, and liftIO

Running SitePipe

site :: SiteM () -> IO () Source #

Build a site generator from a set of rules embedded in a SiteM. Use this in your main function.

main :: IO ()
main = site $ do
  posts <- resourceLoader markdownReader ["posts/*.md"]
  writeTemplate "templates/post.html" posts

siteWithGlobals :: Value -> SiteM () -> IO () Source #

Like site, but allows you to pass an Value Object which consists of an environment which is available inside your templates.

This is useful for globally providing utility functions for use in your templates.

import qualified Text.Mustache as MT
import qualified Text.Mustache.Types as MT
utilityFuncs :: MT.Value
utilityFuncs = MT.object
  ["truncate" MT.~> MT.overText (T.take 30)
  ]

main :: IO ()
main = siteWithGlobals utilityFuncs $ do
 -- your site ...
<!-- in your template -->
{{#truncate}}
  Anything inside this block will be truncated to 30 chars.
  {{vars}} are interpolated before applying the function.
{{/truncate}}

Loaders

resourceLoader Source #

Arguments

:: (String -> IO String)

A reader which processes file contents

-> [GlobPattern]

File glob; relative to the site directory

-> SiteM [Value]

Returns a list of Aeson objects

Given a resource reader (see SitePipe.Readers) this function finds all files matching any of the provided list of fileglobs (according to srcGlob) and returns a list of loaded resources as Aeson Values.

Writers

writeWith Source #

Arguments

:: ToJSON a 
=> (a -> SiteM String)

A function which renders a resource to a string.

-> [a]

List of resources to write

-> SiteM () 

Write a list of resources using the given processing function from a resource to a string.

writeTemplate Source #

Arguments

:: ToJSON a 
=> FilePath

Path to template (relative to site dir)

-> [a]

List of resources to write

-> SiteM () 

Given a path to a mustache template file (relative to your source directory); this writes a list of resources to the output directory by applying each one to the template.

textWriter Source #

Arguments

:: ToJSON a 
=> [a]

List of resources to write

-> SiteM () 

Writes the content of the given resources without using a template.

Loader/Writers

copyFiles :: [GlobPattern] -> SiteM () Source #

Given a list of file or directory globs (see srcGlob) we copy matching files and directories as-is from the source directory to the output directory maintaining their relative filepath.

copyFilesWith :: (FilePath -> FilePath) -> [GlobPattern] -> SiteM () Source #

Runs copyFiles but using a filepath transforming function to determine the output filepath. The filepath transformation accepts and should return a relative path.

Readers

Built-in

markdownReader :: String -> IO String Source #

Reads markdown files into html

textReader :: String -> IO String Source #

Reads text files without processing

Reader Generators

mkPandocReader :: (ReaderOptions -> String -> Either PandocError Pandoc) -> String -> IO String Source #

Given any standard pandoc reader (see Text.Pandoc; e.g. readMarkdown, readDocX) makes a resource reader compatible with resourceLoader.

docs <- resourceLoader (mkPandocReader readDocX) ["docs/*.docx"]

Utilities

setExt :: String -> FilePath -> FilePath Source #

Set the extension of a filepath or url to the given extension. Use setExt "" to remove any extension.

addPrefix :: String -> FilePath -> FilePath Source #

Add a prefix to a filepath or url

getTags Source #

Arguments

:: (String -> String)

Accept a tagname and create a url

-> [Value]

List of posts

-> [Value] 

Given a function which creates a url from a tag name and a list of posts (which have a tags property which is a list of strings) this returns a list of tags which contain:

  • name: The tag name
  • url: The tag's url
  • posts: The list of posts matching that tag

Types

Exports

liftIO :: MonadIO m => forall a. IO a -> m a #

Lift a computation from the IO monad.