Каков корень сайта Hakyll?
Я вижу, что функция создания принимает список идентификаторов.
ghci λ> :t create
create :: [Identifier] -> Rules () -> Rules ()
Какой список идентификаторов я должен использовать, чтобы соответствовать корню сайта? Например, я просто хочу создать одну HTML-страницу, которая появится на "www.example.com" без "/ posts" или "/ archives" или каких-либо других частей домена.
Я попробовал несколько:
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, который будет отображаться как "/", и как мне лучше изучить это, чтобы сделать его менее загадочным?
1 ответ
create
функция требует список Identifiers
, Для случая отдельного элемента, просто окружите его скобками ([]
). А также Identifier
является членом IsString
класс, при условии, что вы включили -XOverloadedStrings
Вы можете создать его с помощью обычного строкового литерала в кавычках ("index.html"
).
Итак, чтобы создать файл, который обслуживается в корне, вы должны написать:
create ["index.html"] $ do
route idRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
Напоминание, когда путь запрашивается без явного имени файла (например, http://www.example.com/
) содержимое файла index.html
возвращаются (если сервер не настроен каким-либо другим способом, но это стандарт.)