Skip to content
This repository

Fix fixURLs to employ the same logic as in the Wiki #346

Merged
merged 1 commit into from about 1 year ago

2 participants

avdv John MacFarlane
avdv

When including an image in a wiki page, the server will look for it in
the static dir first, in the default static dir second and lastly in
the repository dir on a browser request.

When exporting pages e.g. to PDF though, the image's URL was always
mapped into the static dir, making it impossible to export pages with
images stored in the repository itself.

avdv Fix fixURLs to employ the same logic as in the Wiki
When including an image in a wiki page, the server will look for it in
the static dir first, in the default static dir second and lastly in
the repository dir on a browser request.

When exporting pages e.g. to PDF though, the image's URL was always
mapped into the static dir, making it impossible to export pages with
images stored in the repository itself.
b63f5f2
John MacFarlane jgm merged commit 2a64312 into from February 04, 2013
John MacFarlane jgm closed this February 04, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 04, 2013
avdv Fix fixURLs to employ the same logic as in the Wiki
When including an image in a wiki page, the server will look for it in
the static dir first, in the default static dir second and lastly in
the repository dir on a browser request.

When exporting pages e.g. to PDF though, the image's URL was always
mapped into the static dir, making it impossible to export pages with
images stored in the repository itself.
b63f5f2
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 23 additions and 10 deletions. Show diff stats Hide diff stats

  1. 33  Network/Gitit/Export.hs
33  Network/Gitit/Export.hs
@@ -41,13 +41,15 @@ import Control.Exception (throwIO)
41 41
 import System.Environment (getEnvironment)
42 42
 import System.Exit (ExitCode(..))
43 43
 import System.IO (openTempFile)
44  
-import System.Directory (getCurrentDirectory, setCurrentDirectory, removeFile)
  44
+import System.Directory (getCurrentDirectory, setCurrentDirectory, removeFile,
  45
+                         doesFileExist)
45 46
 import System.Process (runProcess, waitForProcess)
46 47
 import Codec.Binary.UTF8.String (encodeString)
47 48
 import Text.HTML.SanitizeXSS
48 49
 import Text.Pandoc.Writers.RTF (writeRTFWithEmbeddedImages)
49 50
 import qualified Data.Text as T
50 51
 import Data.List (isPrefixOf)
  52
+import Paths_gitit (getDataFileName)
51 53
 
52 54
 defaultRespOptions :: WriterOptions
53 55
 defaultRespOptions = def { writerStandalone = True }
@@ -274,16 +276,27 @@ respondPDF page old_pndc = fixURLs page old_pndc >>= \pndc -> do
274 276
 -- images in the staticDir with their correct absolute file path.
275 277
 fixURLs :: String -> Pandoc -> GititServerPart Pandoc
276 278
 fixURLs page pndc = do
277  
-    curdir <- liftIO getCurrentDirectory
278 279
     cfg <- getConfig
279  
-
280  
-    let go (Image ils (url, title)) = Image ils (fixURL url, title)
281  
-        go x                        = x
282  
-
283  
-        fixURL ('/':url) = curdir </> staticDir cfg </> url
284  
-        fixURL url       = curdir </> repositoryPath cfg </> takeDirectory page </> url
285  
-
286  
-    return $ bottomUp go pndc
  280
+    defaultStatic <- liftIO $ getDataFileName $ "data" </> "static"
  281
+
  282
+    let static = staticDir cfg
  283
+    let repoPath = repositoryPath cfg
  284
+
  285
+    let go (Image ils (url, title)) = do
  286
+           fixedURL <- fixURL url
  287
+           return $ Image ils (fixedURL, title)
  288
+        go x                        = return x
  289
+
  290
+        fixURL ('/':url) = resolve url
  291
+        fixURL url       = resolve $ takeDirectory page </> url
  292
+
  293
+        resolve p = do
  294
+           sp <- doesFileExist $ static </> p
  295
+           dsp <- doesFileExist $ defaultStatic </> p
  296
+           return (if sp then static </> p
  297
+                   else (if dsp then defaultStatic </> p
  298
+                         else repoPath </> p))
  299
+    liftIO $ bottomUpM go pndc
287 300
 
288 301
 exportFormats :: Config -> [(String, String -> Pandoc -> Handler)]
289 302
 exportFormats cfg = if pdfExport cfg
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.