Created
October 21, 2018 23:04
-
-
Save noteed/dae3af9641c19118e119dc68214c2578 to your computer and use it in GitHub Desktop.
Hakyll Compiler to create files from inline (embedded in site.hs) content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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