6

I see the create function takes a list of Identifiers.

ghci    λ> :t create
create :: [Identifier] -> Rules () -> Rules ()

What list of identifier should I use to match the root of the site? Eg, I just want to make a single html page that appears on "www.example.com" without "/posts" or "/archives" or any other domain parts.

I've tried a few:

create "/" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

and

create "/*" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

and

create "." $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

and

create "./" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

and

create "/." $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

and

create "" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

and

create Nothing $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

I get errors like:

site.hs:24:12: error:
    • Couldn't match type ‘Identifier’ with ‘Char’
        arising from the literal ‘""’
    • In the first argument of ‘create’, namely ‘""’
      In the expression: create ""
      In a stmt of a 'do' block:
        create ""
        $ do { route idRoute;
               compile
               $ pandocCompiler
                 >>= loadAndApplyTemplate "templates/default.html" defaultContext
                 >>= relativizeUrls }
Failed, modules loaded: none.
Loaded GHCi configuration from /tmp/ghci29841/ghci-script

I can't say :i Identifier or reading documentation or reading the source code makes this any clearer for me:

ghci    λ> :i Identifier
data Identifier
  = Hakyll.Core.Identifier.Identifier {identifierVersion :: Maybe
                                                              String,
                                       Hakyll.Core.Identifier.identifierPath :: String}
    -- Defined in ‘Hakyll.Core.Identifier’
instance Eq Identifier -- Defined in ‘Hakyll.Core.Identifier’
instance Ord Identifier -- Defined in ‘Hakyll.Core.Identifier’
instance Show Identifier -- Defined in ‘Hakyll.Core.Identifier’

What magic incantation should I use to create html that will appear "/", and how should I have investigated this better to make it less mysterious?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • It depends on the way your server is configured. Typically `www.example.com/index.html` will be the landing page when someone tries to visit `www.example.com`. See for instance [this line](https://github.com/gallais/gallais.github.io/blob/source/src/site.hs#L68). – gallais Sep 22 '17 at 12:41
  • Have you tried `fromFilePath "./"`? – arrowd Sep 22 '17 at 15:17
  • @gallais, as far as I can tell, using index.html produces a default file server that does not seem to respect any of the templates or content I provided. – Mittenchops Sep 23 '17 at 04:58
  • @arrowd, • Couldn't match expected type ‘Rules () -> Rules a0’ with actual type ‘Rules ()’ – Mittenchops Sep 23 '17 at 04:59
  • Check parentheses: `create (fromFilePath "./") $ do`. – arrowd Sep 23 '17 at 06:32
  • • Couldn't match expected type ‘[Identifier]’ with actual type ‘Identifier’ • In the first argument of ‘create’, namely ‘(fromFilePath "./")’ In the expression: create (fromFilePath "./") Replacing with create [(fromFilePath "./")] $ do No error, but can't rebuild: [ERROR] Hakyll.Core.Compiler.cached: You are trying to (perhaps indirectly) use `cached` on a non-existing resource: there is no file backing . – Mittenchops Sep 23 '17 at 15:13
  • It kind of blows my mind this doesn't have a trivial answer that works with minimal configuration. This is "hello world" for Hakyll. – Mittenchops Sep 23 '17 at 18:45

1 Answers1

0

The create function requires a list of Identifiers. For the case of a single element, just surround it with brackets ([]). And Identifier is a member of the IsString class so assuming you have enabled -XOverloadedStrings you can build one with just a regular quoted string literal ("index.html").

So to create a file that is served at the root you would write:

create ["index.html"] $ do
route   idRoute
compile $ pandocCompiler
    >>= loadAndApplyTemplate "templates/default.html" defaultContext
    >>= relativizeUrls

Reminder when a path is requested without an explicit file name (e.g. http://www.example.com/) the contents of the file index.html are returned (Unless the server is configured in some other way, but this is the standard.)

John F. Miller
  • 26,961
  • 10
  • 71
  • 121
  • I have similar, trying to use markdown: `` create ["index.md"] $ do route (setExtension "html") compile $ pandocCompiler >>= loadAndApplyTemplate "templates/default.html" defaultContext >>= relativizeUrls `` I get this error when I ``stack build`` ``` [ERROR] Hakyll.Core.Compiler.Require.load: templates/default.html (snapshot _final) was not found in the cache, the cache might be corrupted or the item you are referring to might not exist ``` – Mittenchops Oct 03 '17 at 04:15