首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hakyll站点的根是什么?

Hakyll站点的根是什么?
EN

Stack Overflow用户
提问于 2017-09-22 11:14:04
回答 1查看 256关注 0票数 6

我看到create函数接受一个标识符列表。

代码语言:javascript
复制
ghci    λ> :t create
create :: [Identifier] -> Rules () -> Rules ()

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

我试过以下几种:

代码语言:javascript
复制
create "/" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

代码语言:javascript
复制
create "/*" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

代码语言:javascript
复制
create "." $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

代码语言:javascript
复制
create "./" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

代码语言:javascript
复制
create "/." $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

代码语言:javascript
复制
create "" $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

代码语言:javascript
复制
create Nothing $ do
    route   idRoute
    compile $ pandocCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

我得到的错误如下:

代码语言:javascript
复制
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 Identifierreading documentationreading the source code对我来说更清楚了:

代码语言:javascript
复制
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,我应该如何更好地调查这一点,使其不那么神秘?

EN

回答 1

Stack Overflow用户

发布于 2017-10-02 13:25:55

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

因此,要创建一个在根目录提供服务的文件,您可以这样写:

代码语言:javascript
复制
create ["index.html"] $ do
route   idRoute
compile $ pandocCompiler
    >>= loadAndApplyTemplate "templates/default.html" defaultContext
    >>= relativizeUrls

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46356263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档