Permalink
Browse files

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

  • Loading branch information...
1 parent ba4a959 commit 7e41616b106c85d66fd125cf3828b0a4e9aa145f @jgm committed Aug 22, 2009
View
26 Network/Gitit.hs
@@ -114,27 +114,39 @@ import Network.Gitit.State (getFileStore, getUser, getConfig)
import Network.Gitit.ContentTransformer
import Network.Gitit.Authentication (loginUserForm)
import Control.Monad.Reader
-import System.FilePath
import Prelude hiding (readFile)
import Codec.Binary.UTF8.String (decodeString)
+import qualified Data.ByteString.Char8 as B
-- | Happstack handler for a gitit wiki.
wiki :: Config -> ServerPart Response
wiki conf = do
let static = staticDir conf
- let staticHandler = dir "_static" $ withExpiresHeaders $ msum
- [ dir "css" $ fileServeStrict [] (static </> "css")
- , dir "js" $ fileServeStrict [] (static </> "js")
- , ignoreFilters >> -- don't compress images, pdfs, etc.
- fileServeStrict [] static ]
- let handlers = [ debugHandler | debugMode conf] ++ (authHandler conf : wikiHandlers)
+ let staticHandler = withExpiresHeaders $ fileServeStrict' [] static
+ let handlers = [debugHandler | debugMode conf] ++ (authHandler conf : wikiHandlers)
let fs = filestoreFromConfig conf
let ws = WikiState { wikiConfig = conf, wikiFileStore = fs }
if compressResponses conf
then compressedResponseFilter
else return ""
staticHandler `mplus` runHandler ws (withUser conf $ msum handlers)
+-- | Like 'fileServeStrict', but if file is not found, fail instead of
+-- returning a 404 error.
+fileServeStrict' :: [FilePath] -> FilePath -> ServerPart Response
+fileServeStrict' ps p = do
+ rq <- askRq
+ resp <- fileServeStrict ps p
+ if rsCode resp == 404 || last (rqUri rq) == '/'
+ then mzero -- pass through if not found or directory index
+ else do
+ mbContentType <- getHeaderM "Content-Type"
+ -- turn off compresion filter unless it's text
+ case mbContentType of
+ Just ct | B.pack "text/" `B.isPrefixOf` ct -> ignoreFilters
+ _ -> return ()
+ return resp
+
wikiHandlers :: [Handler]
wikiHandlers =
[ -- redirect /wiki -> /wiki/ when gitit is being served at /wiki
View
2 Network/Gitit/ContentTransformer.hs
@@ -335,7 +335,7 @@ pandocToHtml pandocContents = do
return $ writeHtml defaultWriterOptions{
writerStandalone = False
, writerHTMLMathMethod = JsMath
- (Just $ base' ++ "/_static/js/jsMath/easy/load.js")
+ (Just $ base' ++ "/js/jsMath/easy/load.js")
, writerTableOfContents = toc
, writerLiterateHaskell = bird
} pandocContents
View
2 Network/Gitit/Initialize.hs
@@ -110,7 +110,7 @@ createRepoIfMissing conf = do
let defOpts = defaultWriterOptions{
writerStandalone = False
, writerHTMLMathMethod = JsMath
- (Just "/_static/js/jsMath/easy/load.js")
+ (Just "/js/jsMath/easy/load.js")
, writerLiterateHaskell = showLHSBirdTracks conf
}
-- note: we convert this (markdown) to the default page format
View
2 Network/Gitit/Layout.hs
@@ -68,7 +68,7 @@ defaultRenderPage templ layout htmlContents = do
let page = pgPageName layout
base' <- getWikiBase
let scripts = ["jquery.min.js", "jquery-ui.packed.js"] ++ pgScripts layout
- let scriptLink x = script ! [src (base' ++ "/_static/js/" ++ x),
+ let scriptLink x = script ! [src (base' ++ "/js/" ++ x),
thetype "text/javascript"] << noHtml
let javascriptlinks = renderHtmlFragment $ concatHtml $ map scriptLink scripts
let tabli tab = if tab == pgSelectedTab layout
View
2 README.markdown
@@ -205,7 +205,7 @@ The `static` directory
If there is no wiki page or uploaded file corresponding to a request,
gitit always looks last in the `static` directory. So, for example,
a file `foo.jpg` in the `img` subdirectory of the `static` directory
-will be accessible at the url `/img/foo.jpg`. Pandoc creates three
+will be accessible at the url `/img/foo.jpg`. Gitit creates three
subdirectories of `static`, `css`, `img`, and `js`, which include the
icons, stylesheets, and javascripts it uses.
View
2 data/templates/expire.st
@@ -1,5 +1,5 @@
$if(usecache)$
-<script type="text/javascript" src="$base$/_static/js/jquery.hotkeys-0.7.9.min.js"></script>
+<script type="text/javascript" src="$base$/js/jquery.hotkeys-0.7.9.min.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
\$(document).bind("keydown", "ctrl+r", function() {
View
2 data/templates/logo.st
@@ -1,3 +1,3 @@
<div id="logo">
- <a href="$base$/" title="Go to top page"><img src="$base$/_static/img/logo.png" /></a>
+ <a href="$base$/" title="Go to top page"><img src="$base$/img/logo.png" /></a>
</div>
View
14 data/templates/page.st
@@ -12,15 +12,15 @@
$endif$
<title>Wiki - $pagetitle$</title>
$if(printable)$
- <link href="$base$/_static/css/print.css" rel="stylesheet" media="all" type= "text/css" />
+ <link href="$base$/css/print.css" rel="stylesheet" media="all" type= "text/css" />
$else$
- <link href="$base$/_static/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/print.css" rel="stylesheet" media="print" type= "text/css" />
+ <link href="$base$/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/css/print.css" rel="stylesheet" media="print" type= "text/css" />
$endif$
- <!--[if IE]><link href="$base$/_static/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
+ <!--[if IE]><link href="$base$/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
</head>
<body>
<div id="doc3" class="yui-t1">

0 comments on commit 7e41616

Please sign in to comment.