mirror of
https://github.com/srid/rib.git
synced 2024-11-26 13:50:31 +03:00
Add getPostAttributeList
This commit is contained in:
parent
6e5fddb2c9
commit
cddae9e69c
@ -70,7 +70,6 @@ executable rib-example
|
||||
build-depends:
|
||||
base
|
||||
, clay
|
||||
, data-default
|
||||
, directory
|
||||
, reflex-dom-core
|
||||
, rib
|
||||
|
@ -28,7 +28,7 @@ elPandocDoc (Pandoc _meta blocks) = mapM_ renderBlock blocks
|
||||
-- | Render the first level of heading
|
||||
elPandocHeading1 :: DomBuilder t m => Pandoc -> m ()
|
||||
elPandocHeading1 (Pandoc _meta blocks) = forM_ blocks $ \case
|
||||
Header 1 _ xs -> mapM_ renderInline xs
|
||||
Header 1 _ xs -> elPandocInlines xs
|
||||
_ -> blank
|
||||
|
||||
-- | Render list of Pandoc inlines
|
||||
|
@ -9,16 +9,19 @@ module Rib.Types
|
||||
, PostCategory(..)
|
||||
, PostFilePath(..)
|
||||
, getPostAttribute
|
||||
, getPostAttributeList
|
||||
, getPostAttributeJson
|
||||
) where
|
||||
|
||||
import Data.Aeson (FromJSON, ToJSON, decode)
|
||||
import qualified Data.Map as Map
|
||||
import Data.Text (Text)
|
||||
import Data.Maybe
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics (Generic)
|
||||
|
||||
import Development.Shake.Classes (Binary, Hashable, NFData)
|
||||
import Text.Pandoc (Inline (Str), Meta (unMeta), MetaValue (MetaInlines), Pandoc (Pandoc))
|
||||
import Text.Pandoc
|
||||
import Text.Pandoc.UTF8 (fromStringLazy)
|
||||
|
||||
-- | Represents a HTML page that will be generated
|
||||
@ -44,6 +47,8 @@ data PostCategory
|
||||
newtype PostFilePath = PostFilePath FilePath
|
||||
deriving (Show, Eq, Hashable, Binary, NFData, Generic)
|
||||
|
||||
-- TODO: These functions should probably live in Pandoc Util module
|
||||
|
||||
-- Get the YAML metadata for the given key in a post
|
||||
--
|
||||
-- This has to always return `[Inline]` unless we upgrade pandoc. See
|
||||
@ -56,6 +61,15 @@ getPostAttribute k (Post (Pandoc meta _) _) =
|
||||
Just (MetaInlines inlines) -> Just inlines
|
||||
_ -> Nothing
|
||||
|
||||
-- Get the YAML metadata for a key that is a list of text values
|
||||
getPostAttributeList :: String -> Post -> Maybe [Text]
|
||||
getPostAttributeList k (Post (Pandoc meta _) _) =
|
||||
case Map.lookup k (unMeta meta) of
|
||||
Just (MetaList vals) -> Just $ catMaybes $ flip fmap vals $ \case
|
||||
MetaInlines [Str val] -> Just $ T.pack val
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
|
||||
-- Like getPostAttribute but expects the value to be JSON encoding of a type.
|
||||
getPostAttributeJson :: FromJSON a => String -> Post -> Maybe a
|
||||
getPostAttributeJson k p = do
|
||||
|
Loading…
Reference in New Issue
Block a user