6

我看到 create 函数需要一个标识符列表。

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

我应该使用哪个标识符列表来匹配站点的根目录?例如,我只想制作一个出现在“www.example.com”上的没有“/posts”或“/archives”或任何其他域部分的html页面。

我试过几个:

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阅读文档阅读源代码,这对我来说更清楚:

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,我应该如何更好地调查它以使其不那么神秘?

4

1 回答 1

0

create函数需要一个Identifiers. 对于单个元素,只需用括号 ( []) 将其括起来。并且IdentifierIsString该类的成员,因此假设您已启用-XOverloadedStrings,您可以仅使用常规带引号的字符串文字 ( "index.html") 构建一个。

因此,要创建一个在根目录下提供的文件,您将编写:

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

在没有明确文件名的情况下请求路径时提醒(例如http://www.example.com/index.html返回文件的内容(除非服务器以其他方式配置,但这是标准。)

于 2017-10-02T05:25:55.040 回答