diff --git a/blog-meta/blog-meta.cabal b/blog-meta/blog-meta.cabal index 3146d58..c83eb44 100644 --- a/blog-meta/blog-meta.cabal +++ b/blog-meta/blog-meta.cabal @@ -19,6 +19,7 @@ common deps bytestring ^>= 0.10.12.0, containers ^>= 0.6.4.1, filemanip, + filepath ^>= 1.4.2.1, pandoc-types ^>= 1.22, text ^>= 1.2.4.1, time ^>= 1.9.3 diff --git a/blog-meta/post-lists.hs b/blog-meta/post-lists.hs index e53f283..2fb365e 100644 --- a/blog-meta/post-lists.hs +++ b/blog-meta/post-lists.hs @@ -6,18 +6,18 @@ import Data.Ord (comparing) import Data.Text (Text) import qualified Data.Text as Text import Data.Time +import Misc import qualified YAML import YAML ((.:), (.!=), (##=)) import qualified System.Console.GetOpt as GetOpt import qualified System.FilePath.Find as Find -import Misc -import Data.Char (toLower) +import qualified System.FilePath as Path main :: IO () main = do Opts title dir tag out <- getOptions files <- Find.findL True (pure True) (Find.extension Find.==? ".md") dir - infos <- filter (checkTag tag) <$> traverse getInfo files + infos <- filter (checkTag tag) <$> traverse (getInfo dir) files let content = makeContent title infos case out of Nothing -> LazyBS.putStr content @@ -63,12 +63,14 @@ defOpts [dir, title] = defOpts _ = Nothing -getInfo :: FilePath -> IO PostInfo -getInfo file = do +getInfo :: FilePath -> FilePath -> IO PostInfo +getInfo dir file = do yaml <- YAML.readHeader file + let dirs = Path.splitPath dir + let file' = Path.joinPath $ drop (length dirs) $ Path.splitPath file unwrap file $ YAML.parseEither $ yaml & YAML.withMap "title, date, tags" \m -> - Info <$> return (Text.pack file) + Info <$> pure file' <*> m .: "title" <*> m .: "date" <*> m .: "tags" .!= [] @@ -76,7 +78,7 @@ getInfo file = do -- | the front matter info we care about data PostInfo = Info { - _nfoFile :: Text, + _nfoFile :: FilePath, _nfoTitle :: Text, infoDate :: BlogDate, infoTags :: [Text] @@ -87,7 +89,8 @@ instance YAML.ToYAML PostInfo where [("date" ##= date), ("title" ##= title), ("tags" ##= tags), - ("file" ##= file)] + ("file" ##= Text.pack (fixup file))] + where fixup f = Path.replaceExtension f "html" newtype BlogDate = D Day deriving (Eq, Ord) diff --git a/templates/postlist.html b/templates/postlist.html index 7aab586..10ec802 100644 --- a/templates/postlist.html +++ b/templates/postlist.html @@ -2,7 +2,7 @@