diff --git a/Shakefile.hs b/Shakefile.hs index e1a5a8c..318022a 100644 --- a/Shakefile.hs +++ b/Shakefile.hs @@ -4,7 +4,7 @@ import Protolude import Development.Shake -import Development.Shake.Command +-- import Development.Shake.Command import Development.Shake.FilePath import Data.Time.Format.ISO8601 (iso8601Show) @@ -62,8 +62,9 @@ optimDir = "_optim" data BlogPost = BlogPost { postTitle :: T.Text , postDate :: T.Text - , postAuthors :: [T.Text] + , postAuthor :: T.Text , postUrl :: FilePath + , postSrc :: FilePath , postTags :: [T.Text] , postDescr :: T.Text , postToc :: Bool @@ -80,11 +81,14 @@ getBlogpostFromMetas path toc pandoc@(Pandoc meta _) = do eitherBlogpost <- liftIO $ Pandoc.runIO $ do title <- fmap (T.dropEnd 1) $ inlineToText $ docTitle meta date <- fmap (T.dropAround dateEnvelope) $ inlineToText $ docDate meta - authors <- mapM inlineToText $ docAuthors meta + author <- case head $ docAuthors meta of + Just m -> inlineToText m + Nothing -> return "" let tags = tagsToList $ lookupMeta "keywords" meta description = descr $ lookupMeta "description" meta + url = "/" dropDirectory1 path -<.> "org" liftIO $ print (lookupMeta "keywords" meta) - return $ BlogPost title date authors path tags description toc pandoc + return $ BlogPost title date author url path tags description toc pandoc case eitherBlogpost of Left _ -> fail "BAD" Right bp -> return bp @@ -155,7 +159,7 @@ buildArchive buildArchive getPosts getTemplate out = do css <- genAllDeps ["//*.css"] posts <- fmap sortByPostDate $ getPosts () - need $ css <> map postUrl posts + need $ css <> map postSrc posts let title :: Text title = "#+title: Posts" @@ -170,7 +174,7 @@ buildArchive getPosts getTemplate out = do let htmlContent = renderMustache template $ object [ "title" .= postTitle bp - , "authors" .= postAuthors bp + , "author" .= postAuthor bp , "date" .= postDate bp , "tags" .= postTags bp , "description" .= postDescr bp @@ -183,8 +187,7 @@ postInfo bp = "- " <> date <> ": " <> orglink where date = T.takeWhile (/= ' ') (postDate bp) - url = toS (dropDirectory1 (postUrl bp)) - orglink = "[[file:" <> url <> "][" <> (postTitle bp) <> "]]" + orglink = "[[file:" <> (toS (postUrl bp)) <> "][" <> (postTitle bp) <> "]]" replaceLinks :: Pandoc -> Pandoc replaceLinks = walk replaceOrgLink @@ -196,6 +199,7 @@ replaceLinks = walk replaceOrgLink else lnk replaceOrgLink x = x +orgContentToText :: (MonadIO m, MonadFail m) => Text -> m Text orgContentToText org = do eitherResult <- liftIO $ Pandoc.runIO $ Readers.readOrg (def { readerStandalone = True }) org pandoc <- case eitherResult of @@ -206,6 +210,7 @@ orgContentToText org = do Left _ -> fail "BAD" Right innerHtml -> return innerHtml +postamble :: (MonadIO m, MonadFail m) => Text -> BlogPost -> m Text postamble now bp = orgContentToText $ unlines $ [ "@@html: