What's the root of a Hakyll site?
Asked Answered
W

1

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?

Whizbang answered 22/9, 2017 at 3:14 Comment(7)
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.Harmful
Have you tried fromFilePath "./"?Prepense
@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.Whizbang
@arrowd, • Couldn't match expected type ‘Rules () -> Rules a0’ with actual type ‘Rules ()’Whizbang
Check parentheses: create (fromFilePath "./") $ do.Prepense
• 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 .Whizbang
It kind of blows my mind this doesn't have a trivial answer that works with minimal configuration. This is "hello world" for Hakyll.Whizbang
S
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.)

Scruff answered 2/10, 2017 at 5:25 Comment(1)
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 ```Whizbang

© 2022 - 2024 — McMap. All rights reserved.