Skip to content

Commit ceb9ad5

Browse files
Fix og:image path to be absolute
This change resolves the relative note image path to make an absolute url. For `blog/post.md` with a `![img](media/image.png)`, the og:image is: - Before: `siteUrl/media/image.png` - After: `siteUrl/blog/media/image.png`
1 parent 013be93 commit ceb9ad5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

emanote/src/Emanote/Model/Note.hs

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Network.URI.Slug (Slug)
3030
import Optics.Core ((%), (.~))
3131
import Optics.TH (makeLenses)
3232
import Relude
33-
import System.FilePath (takeFileName, (</>))
33+
import System.FilePath (takeDirectory, takeFileName, (</>))
3434
import Text.Pandoc (readerExtensions, runPure)
3535
import Text.Pandoc.Builder qualified as B
3636
import Text.Pandoc.Definition (Pandoc (..))
@@ -368,9 +368,8 @@ parseNoteMarkdown scriptingEngine pluginBaseDir fp md = do
368368
tell [toText $ "Pandoc filter " <> p <> " not found in any of: " <> show pluginBaseDir]
369369
pure Nothing
370370
(x : _) -> pure $ Just x
371-
372371
doc <- applyPandocFilters scriptingEngine filterPaths $ preparePandoc doc'
373-
let meta = applyNoteMetaFilters doc frontmatter
372+
let meta = applyNoteMetaFilters (takeDirectory fp) doc frontmatter
374373
pure (doc, meta)
375374
where
376375
withAesonDefault default_ mv =
@@ -381,8 +380,8 @@ defaultFrontMatter :: Aeson.Value
381380
defaultFrontMatter =
382381
Aeson.toJSON $ Map.fromList @Text @[Text] $ one ("tags", [])
383382

384-
applyNoteMetaFilters :: Pandoc -> Aeson.Value -> Aeson.Value
385-
applyNoteMetaFilters doc =
383+
applyNoteMetaFilters :: FilePath -> Pandoc -> Aeson.Value -> Aeson.Value
384+
applyNoteMetaFilters fileDirectory doc =
386385
addTagsFromBody
387386
>>> addDescriptionFromBody
388387
>>> addImageFromBody
@@ -407,7 +406,7 @@ applyNoteMetaFilters doc =
407406
-- `![[foo.jpeg]]` is not handled at all.
408407
addImageFromBody =
409408
overrideAesonText ("page" :| ["image"]) $ \case
410-
B.Image _ _ (url, _) -> [url]
409+
B.Image _ _ (url, _) -> [T.pack (fileDirectory </> T.unpack url)]
411410
_ -> mempty
412411
overrideAesonText :: forall a. (W.Walkable a Pandoc) => NonEmpty Text -> (a -> [Text]) -> Aeson.Value -> Aeson.Value
413412
overrideAesonText key f frontmatter =

0 commit comments

Comments
 (0)