{-# LANGUAGE OverloadedStrings #-} module MdBlocks.Resolver ( resolveBlock ) where import Data.Text (Text) import MdBlocks.Address import MdBlocks.Types resolveBlock :: Address -> [Block] -> Maybe Block resolveBlock (GlobalId ident) blocks = findById ident blocks resolveBlock (FileAddress fp ident) blocks = findByFileAndId fp ident blocks findById :: Text -> [Block] -> Maybe Block findById ident = go where go [] = Nothing go (b:bs) | mdId (blockMeta b) == Just ident = Just b | otherwise = go bs findByFileAndId :: FilePath -> Text -> [Block] -> Maybe Block findByFileAndId fp ident = go where go [] = Nothing go (b:bs) | blockFile b == fp , mdId (blockMeta b) == Just ident = Just b | otherwise = go bs