Skip to content
This repository
Browse code

Static files now served from root URL, not /_static/.

  • Loading branch information...
commit 7e41616b106c85d66fd125cf3828b0a4e9aa145f 1 parent ba4a959
John MacFarlane authored
26 Network/Gitit.hs
@@ -114,20 +114,16 @@ import Network.Gitit.State (getFileStore, getUser, getConfig)
114 114 import Network.Gitit.ContentTransformer
115 115 import Network.Gitit.Authentication (loginUserForm)
116 116 import Control.Monad.Reader
117   -import System.FilePath
118 117 import Prelude hiding (readFile)
119 118 import Codec.Binary.UTF8.String (decodeString)
  119 +import qualified Data.ByteString.Char8 as B
120 120
121 121 -- | Happstack handler for a gitit wiki.
122 122 wiki :: Config -> ServerPart Response
123 123 wiki conf = do
124 124 let static = staticDir conf
125   - let staticHandler = dir "_static" $ withExpiresHeaders $ msum
126   - [ dir "css" $ fileServeStrict [] (static </> "css")
127   - , dir "js" $ fileServeStrict [] (static </> "js")
128   - , ignoreFilters >> -- don't compress images, pdfs, etc.
129   - fileServeStrict [] static ]
130   - let handlers = [ debugHandler | debugMode conf] ++ (authHandler conf : wikiHandlers)
  125 + let staticHandler = withExpiresHeaders $ fileServeStrict' [] static
  126 + let handlers = [debugHandler | debugMode conf] ++ (authHandler conf : wikiHandlers)
131 127 let fs = filestoreFromConfig conf
132 128 let ws = WikiState { wikiConfig = conf, wikiFileStore = fs }
133 129 if compressResponses conf
@@ -135,6 +131,22 @@ wiki conf = do
135 131 else return ""
136 132 staticHandler `mplus` runHandler ws (withUser conf $ msum handlers)
137 133
  134 +-- | Like 'fileServeStrict', but if file is not found, fail instead of
  135 +-- returning a 404 error.
  136 +fileServeStrict' :: [FilePath] -> FilePath -> ServerPart Response
  137 +fileServeStrict' ps p = do
  138 + rq <- askRq
  139 + resp <- fileServeStrict ps p
  140 + if rsCode resp == 404 || last (rqUri rq) == '/'
  141 + then mzero -- pass through if not found or directory index
  142 + else do
  143 + mbContentType <- getHeaderM "Content-Type"
  144 + -- turn off compresion filter unless it's text
  145 + case mbContentType of
  146 + Just ct | B.pack "text/" `B.isPrefixOf` ct -> ignoreFilters
  147 + _ -> return ()
  148 + return resp
  149 +
138 150 wikiHandlers :: [Handler]
139 151 wikiHandlers =
140 152 [ -- redirect /wiki -> /wiki/ when gitit is being served at /wiki
2  Network/Gitit/ContentTransformer.hs
@@ -335,7 +335,7 @@ pandocToHtml pandocContents = do
335 335 return $ writeHtml defaultWriterOptions{
336 336 writerStandalone = False
337 337 , writerHTMLMathMethod = JsMath
338   - (Just $ base' ++ "/_static/js/jsMath/easy/load.js")
  338 + (Just $ base' ++ "/js/jsMath/easy/load.js")
339 339 , writerTableOfContents = toc
340 340 , writerLiterateHaskell = bird
341 341 } pandocContents
2  Network/Gitit/Initialize.hs
@@ -110,7 +110,7 @@ createRepoIfMissing conf = do
110 110 let defOpts = defaultWriterOptions{
111 111 writerStandalone = False
112 112 , writerHTMLMathMethod = JsMath
113   - (Just "/_static/js/jsMath/easy/load.js")
  113 + (Just "/js/jsMath/easy/load.js")
114 114 , writerLiterateHaskell = showLHSBirdTracks conf
115 115 }
116 116 -- note: we convert this (markdown) to the default page format
2  Network/Gitit/Layout.hs
@@ -68,7 +68,7 @@ defaultRenderPage templ layout htmlContents = do
68 68 let page = pgPageName layout
69 69 base' <- getWikiBase
70 70 let scripts = ["jquery.min.js", "jquery-ui.packed.js"] ++ pgScripts layout
71   - let scriptLink x = script ! [src (base' ++ "/_static/js/" ++ x),
  71 + let scriptLink x = script ! [src (base' ++ "/js/" ++ x),
72 72 thetype "text/javascript"] << noHtml
73 73 let javascriptlinks = renderHtmlFragment $ concatHtml $ map scriptLink scripts
74 74 let tabli tab = if tab == pgSelectedTab layout
2  README.markdown
Source Rendered
@@ -205,7 +205,7 @@ The `static` directory
205 205 If there is no wiki page or uploaded file corresponding to a request,
206 206 gitit always looks last in the `static` directory. So, for example,
207 207 a file `foo.jpg` in the `img` subdirectory of the `static` directory
208   -will be accessible at the url `/img/foo.jpg`. Pandoc creates three
  208 +will be accessible at the url `/img/foo.jpg`. Gitit creates three
209 209 subdirectories of `static`, `css`, `img`, and `js`, which include the
210 210 icons, stylesheets, and javascripts it uses.
211 211
2  data/templates/expire.st
... ... @@ -1,5 +1,5 @@
1 1 $if(usecache)$
2   -<script type="text/javascript" src="$base$/_static/js/jquery.hotkeys-0.7.9.min.js"></script>
  2 +<script type="text/javascript" src="$base$/js/jquery.hotkeys-0.7.9.min.js"></script>
3 3 <script type="text/javascript">
4 4 /* <![CDATA[ */
5 5 \$(document).bind("keydown", "ctrl+r", function() {
2  data/templates/logo.st
... ... @@ -1,3 +1,3 @@
1 1 <div id="logo">
2   - <a href="$base$/" title="Go to top page"><img src="$base$/_static/img/logo.png" /></a>
  2 + <a href="$base$/" title="Go to top page"><img src="$base$/img/logo.png" /></a>
3 3 </div>
14 data/templates/page.st
@@ -12,15 +12,15 @@
12 12 $endif$
13 13 <title>Wiki - $pagetitle$</title>
14 14 $if(printable)$
15   - <link href="$base$/_static/css/print.css" rel="stylesheet" media="all" type= "text/css" />
  15 + <link href="$base$/css/print.css" rel="stylesheet" media="all" type= "text/css" />
16 16 $else$
17   - <link href="$base$/_static/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
18   - <link href="$base$/_static/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
19   - <link href="$base$/_static/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
20   - <link href="$base$/_static/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
21   - <link href="$base$/_static/css/print.css" rel="stylesheet" media="print" type= "text/css" />
  17 + <link href="$base$/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
  18 + <link href="$base$/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
  19 + <link href="$base$/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
  20 + <link href="$base$/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
  21 + <link href="$base$/css/print.css" rel="stylesheet" media="print" type= "text/css" />
22 22 $endif$
23   - <!--[if IE]><link href="$base$/_static/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
  23 + <!--[if IE]><link href="$base$/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
24 24 </head>
25 25 <body>
26 26 <div id="doc3" class="yui-t1">

0 comments on commit 7e41616

Please sign in to comment.
Something went wrong with that request. Please try again.