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:
parent
8382dc11f2
commit
5211379f00
4 changed files with 18 additions and 11 deletions
|
@ -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}?}
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}?}")
|
||||
|
|
Loading…
Reference in a new issue