gpt4 book ai didi

haskell - Hakyll 网站的根源是什么?

转载 作者:行者123 更新时间:2023-12-03 14:40:37 24 4
gpt4 key购买 nike

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

最佳答案

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返回(除非服务器以其他方式配置,但这是标准。)

关于haskell - Hakyll 网站的根源是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46356263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com