Move some attributes around

This commit is contained in:
Oystein Kristoffer Tveit 2022-03-23 13:46:07 +01:00
parent ec31242981
commit 56e90e4567
4 changed files with 38 additions and 8 deletions

View File

@ -5,7 +5,9 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
$if(desc)$
<meta name="description" content="$desc$"> <meta name="description" content="$desc$">
$endif$
$if(author)$ $if(author)$
<meta name="author" content="$author$"> <meta name="author" content="$author$">
@ -18,7 +20,9 @@
<meta property="og:site_name" content="$siteName$"> <meta property="og:site_name" content="$siteName$">
<meta property="og:title" content="$title$"> <meta property="og:title" content="$title$">
<meta property="og:url" content="$root$$url$"> <meta property="og:url" content="$root$$url$">
$if(desc)$
<meta property="og:description" content="$desc$"> <meta property="og:description" content="$desc$">
$endif$
$if(image)$ $if(image)$
<meta property="og:image" content="$root$$image$"> <meta property="og:image" content="$root$$image$">
@ -33,7 +37,9 @@
<meta property="twitter:card" content="summary_large_image"> <meta property="twitter:card" content="summary_large_image">
<meta property="twitter:site" content="$siteName$"> <meta property="twitter:site" content="$siteName$">
<meta property="twitter:title" content="$title$"> <meta property="twitter:title" content="$title$">
$if(desc)$
<meta property="twitter:description" content="$desc$"> <meta property="twitter:description" content="$desc$">
$endif$
$if(image)$ $if(image)$
<meta property="twitter:image" content="$root$$image$"> <meta property="twitter:image" content="$root$$image$">

View File

@ -7,9 +7,9 @@
<small>(updated: $updated$)</small> <small>(updated: $updated$)</small>
$endif$ $endif$
</div> </div>
$if(alternative_writings)$ $if(alternatives)$
<div> <div>
$alternative_writings$ $alternatives$
</div> </div>
$endif$ $endif$
</header> </header>

View File

@ -35,13 +35,35 @@ replaceFuriganaWithKanji :: FuriganaTemplate -> String
replaceFuriganaWithKanji = gsub [re|\[(.*?)\]\((.*?)\)|] (\(kanji:kana:_) -> kanji :: String) replaceFuriganaWithKanji = gsub [re|\[(.*?)\]\((.*?)\)|] (\(kanji:kana:_) -> kanji :: String)
replaceFuriganaWithHtml :: FuriganaTemplate -> String replaceFuriganaWithHtml :: FuriganaTemplate -> String
replaceFuriganaWithHtml = between "<ruby>" "</ruby>" . gsub [re|\[(.*?)\]\((.*?)\)|] (\(kanji:kana:_) -> "<rb>" ++ kanji ++"</rb> <rp>(</rp><rt> " ++ kana ++ "</rt><rp>)</rp>" :: String) replaceFuriganaWithHtml = between "<ruby>" "</ruby>" . gsub regex matchToHtml
where where
regex = [re|\[(.*?)\]\((.*?)\)|]
between :: String -> String -> String -> String
between x y s = x ++ s ++ y between x y s = x ++ s ++ y
matchToHtml :: [String] -> String
matchToHtml (kanji:kana:_) =
let defaultKanji = if kanji == "" then "" else kanji
in foldr1 (++) ["<rb>", defaultKanji, "</rb> <rp>(</rp><rt>", kana, "</rt><rp>)</rp>"]
{- |
title: String
titleHtml: String
finished: Boolean
updated: String
lang: String
antonyms: Maybe [String]
synonyms: Maybe [String]
leads_here: Maybe [String]
alternatives: Maybe [String]
see_also: Maybe [String]
-}
gogenCtx :: Context String gogenCtx :: Context String
gogenCtx = gogenCtx =
dateField "date" "%Y-%m-%d" dateField "date" "%Y-%m-%d"
<> field "titleHtml" convertFuriganaTitleHtml <> field "titleHtml" convertFuriganaTitleHtml
<> defaultContext <> defaultContext
<> constField "lang" "en"

View File

@ -85,7 +85,9 @@ main = hakyllWith config $ do
constField "type" "article" constField "type" "article"
<> field "title" convertFuriganaTitle <> field "title" convertFuriganaTitle
<> field "titleHtml" convertFuriganaTitleHtml <> field "titleHtml" convertFuriganaTitleHtml
<> postCtx <> constField "root" root
<> constField "siteName" siteName
<> gogenCtx
route $ setExtension ".html" route $ setExtension ".html"
compile $ do compile $ do