getSinglePage :: FilePath -> Action Page
getSinglePage dir = do
  content <- readMarkdown . T.pack <$> readFile' (dir </> "page.md")
  metaNoTitle <- liftIO
               . either (throwIO . userError) pure
               . eitherDecodeStrict . encodeUtf8 . T.pack
             =<< readFile' (dir </> "meta.json")
  meta <- addTitle content metaNoTitle
  pure (Page meta content dir)
  where
    addTitle :: Pandoc -> Meta () -> Action (Meta Text)
    addTitle pandoc meta = do
      case titleFromPandoc pandoc of
        Left e      -> liftIO (throwIO e)
        Right title -> pure $ meta { _metaTitle = title }
getSinglePage :: FilePath -> Action Page
getSinglePage dir = do
  content <- readMarkdown . T.pack <$> readFile' (dir </> "page.md")
  metaNoTitle <- liftIO
               . either (throwIO . userError) pure
               . eitherDecodeStrict . encodeUtf8 . T.pack
             =<< readFile' (dir </> "meta.json")
  meta <- addTitle content metaNoTitle
  pure (Page meta content dir)
  where
    addTitle :: Pandoc -> Meta () -> Action (Meta Text)
    addTitle pandoc meta = do
      case titleFromPandoc pandoc of
        Left e      -> liftIO (throwIO e)
        Right title -> pure $ meta { _metaTitle = title }
getSinglePage dir = do
  content <- readMarkdown . T.pack <$> readFile' (dir </> "page.md")
  metaNoTitle <- liftIO
               . either (throwIO . userError) pure
               . eitherDecodeStrict . encodeUtf8 . T.pack
             =<< readFile' (dir </> "meta.json")
  meta <- addTitle content metaNoTitle
  pure (Page meta content dir)
  where
    addTitle :: Pandoc -> Meta () -> Action (Meta Text)
    addTitle pandoc meta = do
      case titleFromPandoc pandoc of
        Left e      -> liftIO (throwIO e)
        Right title -> pure $ meta { _metaTitle = title }