diff --git a/share/defaultWording.conf b/share/defaultWording.conf index 430e168..99dd6f4 100644 --- a/share/defaultWording.conf +++ b/share/defaultWording.conf @@ -1,11 +1,13 @@ allLink = See all allPage = All articles{? tagged ${tag}?} +articleDescription = A new article on ${name} commentsLink = Comment on the fediverse commentsSection = Comments dateFormat = en-US latestLink = See only latest latestPage = Latest articles{? tagged ${tag}?} metadata = {?by ${author} ?}on ${date}{? tagged ${tags}?} +pageDescription = Read on ${name} pagesList = Pages rssLink = Subscribe rssTitle = Follow all articles{? tagged ${tag}?} diff --git a/src/Blog/Wording.hs b/src/Blog/Wording.hs index 6d5e7a2..3be9b38 100644 --- a/src/Blog/Wording.hs +++ b/src/Blog/Wording.hs @@ -26,12 +26,14 @@ variables :: Map String [Text] variables = Map.fromList [ ("allLink", []) , ("allPage", ["tag"]) + , ("articleDescription", ["name"]) , ("commentsLink", []) , ("commentsSection", []) , ("dateFormat", []) , ("latestLink", []) , ("latestPage", ["tag"]) , ("metadata", ["author", "date", "tags"]) + , ("pageDescription", ["name"]) , ("pagesList", []) , ("rssLink", []) , ("rssTitle", ["tag"]) diff --git a/src/DOM/Card.hs b/src/DOM/Card.hs index 08b1a46..be7ccbe 100644 --- a/src/DOM/Card.hs +++ b/src/DOM/Card.hs @@ -9,7 +9,7 @@ module DOM.Card ( import Article (Article(..)) import ArticlesList (ArticlesList(..)) import qualified ArticlesList (description) -import Blog (Blog(..), Renderer, Skin(..)) +import Blog (Blog(..), Renderer, Skin(..), template) import Collection (Collection(..)) import qualified Collection (title) import Control.Applicative ((<|>)) @@ -18,7 +18,7 @@ import qualified Data.Map as Map (lookup) import Data.Text (Text, pack) import Lucid (HtmlT, content_, meta_) import Lucid.Base (makeAttribute) -import Markdown (MarkdownContent(..)) +import Markdown (MarkdownContent(..), metadata) import qualified Markdown (Markdown(..)) import Page (Page(..)) import Pretty ((.$)) @@ -51,7 +51,7 @@ make element siteURL = do sitePrefix = pack . (siteURL ) mDImage :: (Renderer m, MarkdownContent a ) => a -> m (Maybe String) -mDImage = return . Map.lookup "featuredImage" . Markdown.metadata . getMarkdown +mDImage = return . Map.lookup "featuredImage" . metadata . getMarkdown mDTitle :: (Renderer m, MarkdownContent a) => a -> m String mDTitle = return . Markdown.title . getMarkdown @@ -59,22 +59,23 @@ mDTitle = return . Markdown.title . getMarkdown mDUrlPath :: (Renderer m, MarkdownContent a) => a -> m String mDUrlPath a = return $ Markdown.path (getMarkdown a) <.> "html" +mDDescription :: (Renderer m, MarkdownContent a) => String -> a -> m Text +mDDescription key = + getDescription . Map.lookup "summary" . metadata . getMarkdown + where + getDescription = maybe defaultDescription (return . pack) + defaultDescription = asks name >>= template key . \v -> [("name", pack v)] + instance HasCard Article where cardType _ = return "article" - description (Article (Markdown.Markdown {Markdown.metadata})) = - fmap pack . getDescription $ Map.lookup "summary" metadata - where - getDescription = maybe (asks $name.$("A new article on " <>)) return + description = mDDescription "articleDescription" image = mDImage title = mDTitle urlPath = mDUrlPath instance HasCard Page where cardType _ = return "website" - description page@(Page (Markdown.Markdown {Markdown.metadata})) = - fmap pack . getDescription $ Map.lookup "summary" metadata - where - getDescription = maybe (title page) return + description = mDDescription "pageDescription" image = mDImage title = mDTitle urlPath = mDUrlPath diff --git a/test/Mock/Blog/Wording.hs b/test/Mock/Blog/Wording.hs index 456b1d6..7b7df50 100644 --- a/test/Mock/Blog/Wording.hs +++ b/test/Mock/Blog/Wording.hs @@ -10,12 +10,14 @@ defaultWording :: Wording defaultWording = Wording $ Map.fromList [ ("allLink", "See all") , ("allPage", "All articles{? tagged ${tag}?}") + , ("articleDescription", "A new article on ${name}") , ("commentsLink", "Comment on the fediverse") , ("commentsSection", "Comments") , ("dateFormat", "en-US") , ("latestLink", "See only latest") , ("latestPage", "Latest articles{? tagged ${tag}?}") , ("metadata", "{?by ${author} ?}on ${date}{? tagged ${tags}?}") + , ("pageDescription", "Read on ${name}") , ("pagesList", "Pages") , ("rssLink", "Subscribe") , ("rssTitle", "Follow all articles{? tagged ${tag}?}")