2

I try to use shake to convert some markdonw files to html ("bake"). The markdown files are in a directory "dough" and the html should go to "baked". The goal is to produce the index.html file, which links the other files.

This is my first use of shake!

The conversion works, but at the end the first rule produces the error

`rule finished running but did not produce file:`

The cause is perhaps that the index.html file is produced before (with the second rule). How can I tell the first rule not to expect a result (or force the production again)?

secondary question: how to change the first rule to collect files with extension "md" and "markdown"?

Thank you for the help! Suggestions for improvements are most welcome!

bakedD  = "site/baked" -- toFilePath bakedPath
doughD = "site/dough"

shakeWrapped :: IO  ()
shakeWrapped = shakeArgs shakeOptions {shakeFiles=bakedD
                , shakeVerbosity=Loud
                , shakeLint=Just LintBasic
                } $
    do
        want ["index"<.>"html"]

        "index"<.>"html" %> \out ->
            do
                mds <- getDirectoryFiles  doughD ["//*.md"] 
                let htmlFiles = [bakedD </> md -<.> "html" | md <- mds]

                need htmlFiles
                liftIO $  bakeOneFileIO  "baked/index.html"

        (bakedD <> "//*.html") %> \out ->
            do
                let c = dropDirectory1 $ out -<.> "md"
                liftIO $  bakeOneFileIO  c
user855443
  • 2,596
  • 3
  • 25
  • 37

2 Answers2

0

The error message notes that you declare the file to produce index.html, but it doesn't produce that file. From a read of your build system, it appears it produces based/index.html? If so, change the want line area to read:

do
    want ["baked/index.html"]

    "baked/index.html" %> \out ->

Now you are saying at the end of the execution you want to produce a file baked/index.html, and that here is a rule that produces baked/index.html. (If it's really producing site/baked/index.html then adjust appropriately.)

Addressing your second question, mds <- getDirectoryFiles doughD ["//*.md","//*.markdown"] will detect both extensions.

As for style tips, using "index" <.> "html" is not really helping - "index.html" is identical but clearer to read. Other than that, it seems pretty idiomatic.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85
0

The issue was that the first rule wants a file, but this file is included (and produced) by the second rule. There is an indication for that problematic case that the \out variable is not used and the production of the index.htm is not required in this rule (as it is included in the second rule). One can take this as an indication that a phony rule would be appropriate and simplify the code:

bakedD  = "site/baked" -- toFilePath bakedPath
doughD = "site/dough"

shakeWrapped :: IO  ()
shakeWrapped = shakeArgs shakeOptions {shakeFiles=bakedD
                , shakeVerbosity=Loud
                , shakeLint=Just LintBasic
                } $
    do
        want ["allMarkdownConversion"]

        phony "allMarkdownConversion" $  
            do
                mds <- getDirectoryFiles  doughD ["//*.md"] -- markdown ext ??
                let htmlFiles = [bakedD </> md -<.> "html" | md <- mds]
--                liftIO $ putIOwords ["shakeWrapped - htmlFile", showT htmlFiles]
                need htmlFiles

        (bakedD <> "//*.html") %> \out ->
            do
                let c = dropDirectory1 $ out -<.> "md"
                liftIO $  bakeOneFileIO  c

I think that shake is a very convenient method to add a cache to a static site generator; it rebuilds only what is required!

user855443
  • 2,596
  • 3
  • 25
  • 37