我看到create函数接受一个标识符列表。
ghci λ> :t create
create :: [Identifier] -> Rules () -> Rules ()我应该使用什么标识符列表来匹配站点的根目录?例如,我只想做一个单独的html页面,它出现在"www.example.com“上,没有"/posts”或"/archives“或任何其他域部分。
我试过以下几种:
create "/" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls和
create "/*" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls和
create "." $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls和
create "./" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls和
create "/." $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls和
create "" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls和
create Nothing $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls我得到的错误如下:
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 Identifier、reading documentation或reading the source code对我来说更清楚了:
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’我应该使用什么魔法来创建显示为"/“的html,我应该如何更好地调查这一点,使其不那么神秘?
发布于 2017-10-02 13:25:55
create函数需要一个Identifiers列表。对于单个元素,只需用括号将其括起来([])。而且Identifier是IsString类的成员,因此假设您已经启用了-XOverloadedStrings,您可以只使用常规的带引号的字符串文字("index.html")构建一个。
因此,要创建一个在根目录提供服务的文件,您可以这样写:
create ["index.html"] $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls提醒当请求一个没有明确文件名的路径(例如http://www.example.com/)时,将返回文件index.html的内容(除非以某种其他方式配置服务器,但这是标准)。
https://stackoverflow.com/questions/46356263
复制相似问题