2017-09-22 141 views
6

我看到創建函數需要一個標識符列表。Hakyll網站的根源是什麼?

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

我應該使用什麼樣的標識符列表來匹配網站的根?例如,我只想製作一個不帶「/ posts」或「/ archives」或任何其他域部分的「www.example.com」上出現的單個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和我應該怎麼已經調查這更好使它那麼神祕?

+0

這取決於您的服務器配置方式。當有人試圖訪問www.example.com時,通常「www.example.com/index.html」將成爲着陸頁。請參閱[此行](https://github.com/gallais/gallais.github.io/blob/source/src/site.hs#L68)。 – gallais

+0

您是否嘗試過'fromFilePath「./」'? – arrowd

+0

@gallais,據我所知,使用index.html生成一個默認文件服務器,似乎不尊重我提供的任何模板或內容。 – Mittenchops

回答

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的內容(除非以其他方式配置服務器,但這是標準配置)。

+0

我也有類似的,試圖用降價: ''創建[ 「index.md」] $做 路線(setExtension 「HTML」) 編譯$ pandocCompiler >> = loadAndApplyTemplate 「模板/ default.html中」 的DefaultContext > > = relativizeUrls '' 我得到這個錯誤當我 ''堆棧建立'' ''' [錯誤]沒有找到Hakyll.Core.Compiler.Require.load:templates/default.html(快照_final)在緩存中,緩存可能已損壞,或者您所指的項目可能不存在 ''' – Mittenchops