Discussion:
[hakyll] Noob question about referencing a static HTML document
j***@gmail.com
2015-09-19 11:57:27 UTC
Permalink
Hi,

I have a directory (misc/) of files like spreadsheet etc that I deploy with
copyFileCompiler, and that I can reference from posts.

That works fine.

I build an index document of non-dated articles like this:

create ["documents.html"] $ do
route idRoute
compile $ do
docs <- loadAll "docs/*"

let docListCtx =
listField "docs" docsCtx (return docs) `mappend`
constField "title" "Documents" `mappend`
defaultContext

makeItem ""
= loadAndApplyTemplate "templates/documents.html"
docListCtx
= loadAndApplyTemplate "templates/default.html" docListCtx
= relativizeUrls
I'd like to include the contents of 'misc/' in there too, just listed with
the filenames.

I tried processing them similarly, but one of the files is already HTML,
saved from Open Office Calc.

I got:

[ERROR] Hakyll.Core.Compiler.Require.load: misc/houseonhillheat.html
(snapshot _final) was found in the cache, but does not have the right type:
expected [Cha
r] but got CopyFile

How would I get what is essentially a file listing (with the filenames
displayed but not the path) - ideally merged into the same list as
documents.html?


Thanks
james
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2015-09-25 16:11:13 UTC
Permalink
Hello James,

The problem is that you are compiling these files as:

Item CopyFile

And then loading them again as:

Item String

The latter type is inferred from `docsCtx`, which probably has the type
signature:

docsCtx :: Context String

That is not what we want. We need to build our own `Context` in this
case [1]. I imagine something like this:

docsCtx :: Context CopyFile
docsCtx = mconcat
[ field "basename" $ \item ->
let CopyFile path = itemBody item
in return (takeBaseName path)
, urlField "url"
]

You can add more fields if you need them. Once you have this, the
following code in the `templates/documents.html` template seems to work:

<ul>
$for(docs)$
<li><a href="$url$">$basename$</a></li>
$endfor$
</ul>

[1]: http://jaspervdj.be/hakyll/tutorials/04-compilers.html#templates-context

Hope this helps,
Peace,
Jasper
Post by j***@gmail.com
Hi,
I have a directory (misc/) of files like spreadsheet etc that I deploy with
copyFileCompiler, and that I can reference from posts.
That works fine.
create ["documents.html"] $ do
route idRoute
compile $ do
docs <- loadAll "docs/*"
let docListCtx =
listField "docs" docsCtx (return docs) `mappend`
constField "title" "Documents" `mappend`
defaultContext
makeItem ""
= loadAndApplyTemplate "templates/documents.html"
docListCtx
= loadAndApplyTemplate "templates/default.html" docListCtx
= relativizeUrls
I'd like to include the contents of 'misc/' in there too, just listed with
the filenames.
I tried processing them similarly, but one of the files is already HTML,
saved from Open Office Calc.
[ERROR] Hakyll.Core.Compiler.Require.load: misc/houseonhillheat.html
expected [Cha
r] but got CopyFile
How would I get what is essentially a file listing (with the filenames
displayed but not the path) - ideally merged into the same list as
documents.html?
Thanks
james
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...