问题
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?
回答1:
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.)
来源:https://stackoverflow.com/questions/46356263/whats-the-root-of-a-hakyll-site