Replace magic string for default Article description by a template variable and add another one for a default description for Pages

This commit is contained in:
Tissevert 2020-06-21 22:16:14 +02:00
parent 8382dc11f2
commit 5211379f00
4 changed files with 18 additions and 11 deletions

View file

@ -1,11 +1,13 @@
allLink = See all allLink = See all
allPage = All articles{? tagged ${tag}?} allPage = All articles{? tagged ${tag}?}
articleDescription = A new article on ${name}
commentsLink = Comment on the fediverse commentsLink = Comment on the fediverse
commentsSection = Comments commentsSection = Comments
dateFormat = en-US dateFormat = en-US
latestLink = See only latest latestLink = See only latest
latestPage = Latest articles{? tagged ${tag}?} latestPage = Latest articles{? tagged ${tag}?}
metadata = {?by ${author} ?}on ${date}{? tagged ${tags}?} metadata = {?by ${author} ?}on ${date}{? tagged ${tags}?}
pageDescription = Read on ${name}
pagesList = Pages pagesList = Pages
rssLink = Subscribe rssLink = Subscribe
rssTitle = Follow all articles{? tagged ${tag}?} rssTitle = Follow all articles{? tagged ${tag}?}

View file

@ -26,12 +26,14 @@ variables :: Map String [Text]
variables = Map.fromList [ variables = Map.fromList [
("allLink", []) ("allLink", [])
, ("allPage", ["tag"]) , ("allPage", ["tag"])
, ("articleDescription", ["name"])
, ("commentsLink", []) , ("commentsLink", [])
, ("commentsSection", []) , ("commentsSection", [])
, ("dateFormat", []) , ("dateFormat", [])
, ("latestLink", []) , ("latestLink", [])
, ("latestPage", ["tag"]) , ("latestPage", ["tag"])
, ("metadata", ["author", "date", "tags"]) , ("metadata", ["author", "date", "tags"])
, ("pageDescription", ["name"])
, ("pagesList", []) , ("pagesList", [])
, ("rssLink", []) , ("rssLink", [])
, ("rssTitle", ["tag"]) , ("rssTitle", ["tag"])

View file

@ -9,7 +9,7 @@ module DOM.Card (
import Article (Article(..)) import Article (Article(..))
import ArticlesList (ArticlesList(..)) import ArticlesList (ArticlesList(..))
import qualified ArticlesList (description) import qualified ArticlesList (description)
import Blog (Blog(..), Renderer, Skin(..)) import Blog (Blog(..), Renderer, Skin(..), template)
import Collection (Collection(..)) import Collection (Collection(..))
import qualified Collection (title) import qualified Collection (title)
import Control.Applicative ((<|>)) import Control.Applicative ((<|>))
@ -18,7 +18,7 @@ import qualified Data.Map as Map (lookup)
import Data.Text (Text, pack) import Data.Text (Text, pack)
import Lucid (HtmlT, content_, meta_) import Lucid (HtmlT, content_, meta_)
import Lucid.Base (makeAttribute) import Lucid.Base (makeAttribute)
import Markdown (MarkdownContent(..)) import Markdown (MarkdownContent(..), metadata)
import qualified Markdown (Markdown(..)) import qualified Markdown (Markdown(..))
import Page (Page(..)) import Page (Page(..))
import Pretty ((.$)) import Pretty ((.$))
@ -51,7 +51,7 @@ make element siteURL = do
sitePrefix = pack . (siteURL </>) sitePrefix = pack . (siteURL </>)
mDImage :: (Renderer m, MarkdownContent a ) => a -> m (Maybe String) 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 :: (Renderer m, MarkdownContent a) => a -> m String
mDTitle = return . Markdown.title . getMarkdown mDTitle = return . Markdown.title . getMarkdown
@ -59,22 +59,23 @@ mDTitle = return . Markdown.title . getMarkdown
mDUrlPath :: (Renderer m, MarkdownContent a) => a -> m String mDUrlPath :: (Renderer m, MarkdownContent a) => a -> m String
mDUrlPath a = return $ Markdown.path (getMarkdown a) <.> "html" 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 instance HasCard Article where
cardType _ = return "article" cardType _ = return "article"
description (Article (Markdown.Markdown {Markdown.metadata})) = description = mDDescription "articleDescription"
fmap pack . getDescription $ Map.lookup "summary" metadata
where
getDescription = maybe (asks $name.$("A new article on " <>)) return
image = mDImage image = mDImage
title = mDTitle title = mDTitle
urlPath = mDUrlPath urlPath = mDUrlPath
instance HasCard Page where instance HasCard Page where
cardType _ = return "website" cardType _ = return "website"
description page@(Page (Markdown.Markdown {Markdown.metadata})) = description = mDDescription "pageDescription"
fmap pack . getDescription $ Map.lookup "summary" metadata
where
getDescription = maybe (title page) return
image = mDImage image = mDImage
title = mDTitle title = mDTitle
urlPath = mDUrlPath urlPath = mDUrlPath

View file

@ -10,12 +10,14 @@ defaultWording :: Wording
defaultWording = Wording $ Map.fromList [ defaultWording = Wording $ Map.fromList [
("allLink", "See all") ("allLink", "See all")
, ("allPage", "All articles{? tagged ${tag}?}") , ("allPage", "All articles{? tagged ${tag}?}")
, ("articleDescription", "A new article on ${name}")
, ("commentsLink", "Comment on the fediverse") , ("commentsLink", "Comment on the fediverse")
, ("commentsSection", "Comments") , ("commentsSection", "Comments")
, ("dateFormat", "en-US") , ("dateFormat", "en-US")
, ("latestLink", "See only latest") , ("latestLink", "See only latest")
, ("latestPage", "Latest articles{? tagged ${tag}?}") , ("latestPage", "Latest articles{? tagged ${tag}?}")
, ("metadata", "{?by ${author} ?}on ${date}{? tagged ${tags}?}") , ("metadata", "{?by ${author} ?}on ${date}{? tagged ${tags}?}")
, ("pageDescription", "Read on ${name}")
, ("pagesList", "Pages") , ("pagesList", "Pages")
, ("rssLink", "Subscribe") , ("rssLink", "Subscribe")
, ("rssTitle", "Follow all articles{? tagged ${tag}?}") , ("rssTitle", "Follow all articles{? tagged ${tag}?}")