Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@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 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
@jgm jgm merged commit 2a64312 into jgm:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 4, 2013
  1. @avdv

    Fix fixURLs to employ the same logic as in the Wiki

    avdv authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 10 deletions.
  1. +23 −10 Network/Gitit/Export.hs
View
33 Network/Gitit/Export.hs
@@ -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
Something went wrong with that request. Please try again.