Skip to content

Instantly share code, notes, and snippets.

@noteed
Created October 21, 2018 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noteed/dae3af9641c19118e119dc68214c2578 to your computer and use it in GitHub Desktop.
Save noteed/dae3af9641c19118e119dc68214c2578 to your computer and use it in GitHub Desktop.
Hakyll Compiler to create files from inline (embedded in site.hs) content
$ ./dist/build/site/site build
Initialising...
Creating store...
Creating provider...
Running rules...
Checking for out-of-date items
Compiling
updated hello.txt
Success
$ ls _site/
hello.txt
$ cat _site/hello.txt
Created inline: ./hello.txt
import Data.Monoid (mappend)
import System.FilePath (replaceExtension)
import Hakyll.Core.Compiler.Internal (compilerAsk, compilerProvider)
import Hakyll.Core.Provider (resourceFilePath)
import Hakyll
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
create ["hello.txt"] $ do
route idRoute
compile inlineCompiler
--------------------------------------------------------------------------------
-- | This will copy any file directly by using a system call
newtype InlineContent = InlineContent FilePath
deriving (Binary, Eq, Ord, Show, Typeable)
--------------------------------------------------------------------------------
instance Writable InlineContent where
write dst (Item _ (InlineContent src)) = writeFile dst ("Created inline: " ++ src ++ "\n")
--------------------------------------------------------------------------------
inlineCompiler :: Compiler (Item InlineContent)
inlineCompiler = do
identifier <- getUnderlying
provider <- compilerProvider <$> compilerAsk
makeItem $ InlineContent $ resourceFilePath provider identifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment