Permalink
Browse files

Merge pull request #346 from avdv/fix-URL-to-path-mapping-for-images

Fix fixURLs to employ the same logic as in the Wiki
  • Loading branch information...
2 parents 0fb5a1c + b63f5f2 commit 2a64312bd65345eb23b676e070ec3e2d3c294a2d @jgm committed Feb 4, 2013
Showing with 23 additions and 10 deletions.
  1. +23 −10 Network/Gitit/Export.hs
View
@@ -41,13 +41,15 @@ import Control.Exception (throwIO)
import System.Environment (getEnvironment)
import System.Exit (ExitCode(..))
import System.IO (openTempFile)
-import System.Directory (getCurrentDirectory, setCurrentDirectory, removeFile)
+import System.Directory (getCurrentDirectory, setCurrentDirectory, removeFile,
+ doesFileExist)
import System.Process (runProcess, waitForProcess)
import Codec.Binary.UTF8.String (encodeString)
import Text.HTML.SanitizeXSS
import Text.Pandoc.Writers.RTF (writeRTFWithEmbeddedImages)
import qualified Data.Text as T
import Data.List (isPrefixOf)
+import Paths_gitit (getDataFileName)
defaultRespOptions :: WriterOptions
defaultRespOptions = def { writerStandalone = True }
@@ -274,16 +276,27 @@ respondPDF page old_pndc = fixURLs page old_pndc >>= \pndc -> do
-- images in the staticDir with their correct absolute file path.
fixURLs :: String -> Pandoc -> GititServerPart Pandoc
fixURLs page pndc = do
- curdir <- liftIO getCurrentDirectory
cfg <- getConfig
-
- let go (Image ils (url, title)) = Image ils (fixURL url, title)
- go x = x
-
- fixURL ('/':url) = curdir </> staticDir cfg </> url
- fixURL url = curdir </> repositoryPath cfg </> takeDirectory page </> url
-
- return $ bottomUp go pndc
+ defaultStatic <- liftIO $ getDataFileName $ "data" </> "static"
+
+ let static = staticDir cfg
+ let repoPath = repositoryPath cfg
+
+ let go (Image ils (url, title)) = do
+ fixedURL <- fixURL url
+ return $ Image ils (fixedURL, title)
+ go x = return x
+
+ fixURL ('/':url) = resolve url
+ fixURL url = resolve $ takeDirectory page </> url
+
+ resolve p = do
+ sp <- doesFileExist $ static </> p
+ dsp <- doesFileExist $ defaultStatic </> p
+ return (if sp then static </> p
+ else (if dsp then defaultStatic </> p
+ else repoPath </> p))
+ liftIO $ bottomUpM go pndc
exportFormats :: Config -> [(String, String -> Pandoc -> Handler)]
exportFormats cfg = if pdfExport cfg

0 comments on commit 2a64312

Please sign in to comment.