WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9e2fe83

Browse files
committed
fix image prefix
1 parent bf6fea9 commit 9e2fe83

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/MyLib.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ theWriter source destination prefix (parentPathComponents, item) = do
152152
let dst = hashDir File.</> key ++ ".html"
153153
putStrLn $ " Compiling " ++ src ++ " -> " ++ dst
154154
let safePrefix = List.dropWhileEnd (== '/') $ dropWhile (== '/') prefix
155-
TIO.writeFile dst (CMark.nodeToHtml [] $ MyMark.prefixImageUrl (safePrefix ++ "/resources/" ++ _hash) $ CMark.commonmarkToNode [] _content)
155+
let finalPrefix = List.intercalate "/" (filter (not . null) [safePrefix, "resources", _hash])
156+
TIO.writeFile dst (CMark.nodeToHtml [] $ MyMark.prefixImageUrl finalPrefix $ CMark.commonmarkToNode [] _content)
156157

157158
let writeFileType key =
158159
\case

src/MyMark.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import Data.Text qualified as T
55

66
prefixImageUrl :: String -> Node -> Node
77
prefixImageUrl prefix node =
8-
let safePrefix = T.dropWhileEnd (== '/') (T.pack prefix) <> T.pack "/"
8+
let safePrefix = T.pack ("/" ++ prefix ++ "/")
99
replaceUrl url = if T.isPrefixOf (T.pack "http") url then url else safePrefix <> T.dropWhile (== '/') url
1010
recurse (Node posInfo nodeType nodes) =
1111
case nodeType of
1212
IMAGE url title -> Node Nothing (IMAGE (replaceUrl url) title) nodes
13-
PARAGRAPH -> Node Nothing PARAGRAPH $ workOnInlineMath nodes
13+
PARAGRAPH -> Node Nothing PARAGRAPH $ workOnInlineMath (map (prefixImageUrl prefix) nodes)
1414
CODE_BLOCK info text -> if info == T.pack "math" then mathBlock text else Node Nothing nodeType nodes
1515
_ -> Node Nothing nodeType (recurse <$> nodes)
1616
in recurse node

0 commit comments

Comments
 (0)