Mit*_*ops 6 haskell static-site hakyll
我看到create函数带有一个Identifier列表.
ghci ?> :t create
create :: [Identifier] -> Rules () -> Rules ()
Run Code Online (Sandbox Code Playgroud)
我应该使用什么标识符列表来匹配站点的根目录?例如,我只想制作一个单独的html页面,该页面出现在"www.example.com"上,没有"/ posts"或"/ archives"或任何其他域名部分.
我试过几个:
create "/" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
和
create "/*" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
和
create "." $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
和
create "./" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
和
create "/." $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
和
create "" $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
和
create Nothing $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
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
Run Code Online (Sandbox Code Playgroud)
我不能说:i Identifier或阅读文档或阅读源代码使我更清楚:
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’
Run Code Online (Sandbox Code Playgroud)
我应该使用什么神奇的咒语来创建出现"/"的html,我应该如何更好地调查它以使其不那么神秘?
该create函数需要一个Identifiers. 对于单个元素的情况,只需用方括号 ( []) 括起来即可。并且Identifier是该类的成员IsString,因此假设您已启用,-XOverloadedStrings您可以仅使用常规的带引号的字符串文字 ( "index.html") 来构建一个。
因此,要创建一个在根目录下提供服务的文件,您可以编写:
create ["index.html"] $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Run Code Online (Sandbox Code Playgroud)
提醒当请求路径时没有显式文件名(例如http://www.example.com/)时,将返回文件的内容index.html(除非服务器以其他方式配置,但这是标准。)