From 56e90e45673833a3c03fa45ce010395e9d4298db Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 23 Mar 2022 13:46:07 +0100 Subject: [PATCH] Move some attributes around --- src/templates/default.html | 12 +++++++++--- src/templates/gogen.html | 4 ++-- ssg/src/Formats/Gogen.hs | 26 ++++++++++++++++++++++++-- ssg/src/Main.hs | 4 +++- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/templates/default.html b/src/templates/default.html index 8049a55..2964f0b 100644 --- a/src/templates/default.html +++ b/src/templates/default.html @@ -5,7 +5,9 @@ - + $if(desc)$ + + $endif$ $if(author)$ @@ -18,7 +20,9 @@ - + $if(desc)$ + + $endif$ $if(image)$ @@ -33,7 +37,9 @@ - + $if(desc)$ + + $endif$ $if(image)$ diff --git a/src/templates/gogen.html b/src/templates/gogen.html index d32b4dd..6f72eb8 100644 --- a/src/templates/gogen.html +++ b/src/templates/gogen.html @@ -7,9 +7,9 @@ (updated: $updated$) $endif$ - $if(alternative_writings)$ + $if(alternatives)$
- $alternative_writings$ + $alternatives$
$endif$ diff --git a/ssg/src/Formats/Gogen.hs b/ssg/src/Formats/Gogen.hs index 40dc2ec..4ca5b4e 100644 --- a/ssg/src/Formats/Gogen.hs +++ b/ssg/src/Formats/Gogen.hs @@ -35,13 +35,35 @@ replaceFuriganaWithKanji :: FuriganaTemplate -> String replaceFuriganaWithKanji = gsub [re|\[(.*?)\]\((.*?)\)|] (\(kanji:kana:_) -> kanji :: String) replaceFuriganaWithHtml :: FuriganaTemplate -> String -replaceFuriganaWithHtml = between "" "" . gsub [re|\[(.*?)\]\((.*?)\)|] (\(kanji:kana:_) -> "" ++ kanji ++" ( " ++ kana ++ ")" :: String) +replaceFuriganaWithHtml = between "" "" . gsub regex matchToHtml where + regex = [re|\[(.*?)\]\((.*?)\)|] + + between :: String -> String -> String -> String between x y s = x ++ s ++ y + matchToHtml :: [String] -> String + matchToHtml (kanji:kana:_) = + let defaultKanji = if kanji == "" then "〇" else kanji + in foldr1 (++) ["", defaultKanji, " (", kana, ")"] + + + +{- | + 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 = dateField "date" "%Y-%m-%d" <> field "titleHtml" convertFuriganaTitleHtml <> defaultContext - + <> constField "lang" "en" \ No newline at end of file diff --git a/ssg/src/Main.hs b/ssg/src/Main.hs index 27b2719..34e3e7b 100644 --- a/ssg/src/Main.hs +++ b/ssg/src/Main.hs @@ -85,7 +85,9 @@ main = hakyllWith config $ do constField "type" "article" <> field "title" convertFuriganaTitle <> field "titleHtml" convertFuriganaTitleHtml - <> postCtx + <> constField "root" root + <> constField "siteName" siteName + <> gogenCtx route $ setExtension ".html" compile $ do