Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix og:image path to be absolute #537

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions emanote/src/Emanote/Model/Note.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Network.URI.Slug (Slug)
import Optics.Core ((%), (.~))
import Optics.TH (makeLenses)
import Relude
import System.FilePath (takeFileName, (</>))
import System.FilePath (takeDirectory, takeFileName, (</>))
import Text.Pandoc (readerExtensions, runPure)
import Text.Pandoc.Builder qualified as B
import Text.Pandoc.Definition (Pandoc (..))
Expand Down Expand Up @@ -368,9 +368,8 @@ parseNoteMarkdown scriptingEngine pluginBaseDir fp md = do
tell [toText $ "Pandoc filter " <> p <> " not found in any of: " <> show pluginBaseDir]
pure Nothing
(x : _) -> pure $ Just x

doc <- applyPandocFilters scriptingEngine filterPaths $ preparePandoc doc'
let meta = applyNoteMetaFilters doc frontmatter
let meta = applyNoteMetaFilters (takeDirectory fp) doc frontmatter
pure (doc, meta)
where
withAesonDefault default_ mv =
Expand All @@ -381,8 +380,8 @@ defaultFrontMatter :: Aeson.Value
defaultFrontMatter =
Aeson.toJSON $ Map.fromList @Text @[Text] $ one ("tags", [])

applyNoteMetaFilters :: Pandoc -> Aeson.Value -> Aeson.Value
applyNoteMetaFilters doc =
applyNoteMetaFilters :: FilePath -> Pandoc -> Aeson.Value -> Aeson.Value
applyNoteMetaFilters fileDirectory doc =
addTagsFromBody
>>> addDescriptionFromBody
>>> addImageFromBody
Expand All @@ -407,7 +406,7 @@ applyNoteMetaFilters doc =
-- `![[foo.jpeg]]` is not handled at all.
addImageFromBody =
overrideAesonText ("page" :| ["image"]) $ \case
B.Image _ _ (url, _) -> [url]
B.Image _ _ (url, _) -> [T.pack (fileDirectory </> T.unpack url)]
_ -> mempty
overrideAesonText :: forall a. (W.Walkable a Pandoc) => NonEmpty Text -> (a -> [Text]) -> Aeson.Value -> Aeson.Value
overrideAesonText key f frontmatter =
Expand Down