on master help sign in
Added UTF8 where nessecary.
commit673ed68b8fd41c9420d353e6efd11d5405e53360 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateMon 18 Jan 2010, 09:11 (17 years ago) parent8b668b3
4 files changed+28−24
hakyll.cabal+2−1 src/Network/Hakyll/SimpleServer.hs+11−10 src/Text/Hakyll/Page.hs+13−12 src/Text/Hakyll/Render/Internal.hs+2−1
hakyll.cabal+2−1
@@ -34,7 +34,8 @@ library
3434 mtl >= 1.1,
3535 old-locale >= 1,
3636 time >= 1,
37− parallel >= 2
37+ parallel >= 2,
38+ utf8-string >= 0.3
3839 exposed-modules: Text.Hakyll
3940 Text.Hakyll.Hakyll
4041 Text.Hakyll.Render
src/Network/Hakyll/SimpleServer.hs+11−10
@@ -8,7 +8,8 @@ import Prelude hiding (log)
88import Control.Monad (forever)
99import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
1010import Network
11−import System.IO
11+import System.IO (stderr, Handle, IOMode(..), openFile, hFileSize, hClose)
12+import qualified System.IO.UTF8 as U
1213import System.Directory (doesFileExist, doesDirectoryExist)
1314import Control.Concurrent (forkIO)
1415import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
@@ -21,7 +22,7 @@ import Text.Hakyll.Regex
2122
2223-- | Function to log from a chan.
2324log :: Chan String -> IO ()
24−log logChan = forever (readChan logChan >>= hPutStrLn stderr)
25+log logChan = forever (readChan logChan >>= U.hPutStrLn stderr)
2526
2627-- | General server configuration.
2728data ServerConfig = ServerConfig { documentRoot :: FilePath
@@ -47,7 +48,7 @@ instance Show Request where
4748-- headers and body.
4849readRequest :: Handle -> Server Request
4950readRequest handle = do
50− requestLine <- liftIO $ hGetLine handle
51+ requestLine <- liftIO $ U.hGetLine handle
5152 let [method, uri, version] = map trim $ splitRegex " " requestLine
5253 return $ Request { requestMethod = method
5354 , requestURI = uri
@@ -147,7 +148,7 @@ getMIMEHeader fileName =
147148 result = lookup (takeExtension fileName) [ (".css", "text/css")
148149 , (".gif", "image/gif")
149150 , (".htm", "text/html")
150− , (".html", "text/html")
151+ , (".html", "text/html; charset=utf8")
151152 , (".jpeg", "image/jpeg")
152153 , (".jpg", "image/jpeg")
153154 , (".js", "text/javascript")
@@ -171,21 +172,21 @@ respond handle = do
171172 -- Send the response back to the handle.
172173 liftIO $ putResponse response
173174 where
174− putResponse response = do hPutStr handle $ intercalate " "
175+ putResponse response = do U.hPutStr handle $ intercalate " "
175176 [ responseVersion response
176177 , show $ responseStatusCode response
177178 , responsePhrase response
178179 ]
179− hPutStr handle "\r\n"
180+ U.hPutStr handle "\r\n"
180181 mapM_ putHeader
181182 (M.toList $ responseHeaders response)
182− hPutStr handle "\r\n"
183− hPutStr handle $ responseBody response
184− hPutStr handle "\r\n"
183+ U.hPutStr handle "\r\n"
184+ U.hPutStr handle $ responseBody response
185+ U.hPutStr handle "\r\n"
185186 hClose handle
186187
187188 putHeader (key, value) =
188− hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
189+ U.hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
189190
190191-- | Start a simple http server on the given 'PortNumber', serving the given
191192-- directory.
src/Text/Hakyll/Page.hs+13−12
@@ -12,7 +12,8 @@ import Data.Maybe (fromMaybe)
1212import Control.Parallel.Strategies (rdeepseq, ($|))
1313import Control.Monad.Reader (liftIO)
1414import System.FilePath (takeExtension)
15−import System.IO
15+import System.IO (Handle, IOMode(..), openFile, hClose)
16+import qualified System.IO.UTF8 as U
1617
1718import Text.Pandoc
1819
@@ -68,7 +69,7 @@ renderFunction ext = writeHtmlString writerOptions
6869-- | Read metadata header from a file handle.
6970readMetaData :: Handle -> Hakyll [(String, String)]
7071readMetaData handle = do
71− line <- liftIO $ hGetLine handle
72+ line <- liftIO $ U.hGetLine handle
7273 if isDelimiter line
7374 then return []
7475 else do others <- readMetaData handle
@@ -91,18 +92,18 @@ cachePage page@(Page mapping) = do
9192
9293 writePageToCache = do
9394 handle <- openFile destination WriteMode
94− hPutStrLn handle "---"
95+ U.hPutStrLn handle "---"
9596 mapM_ (writePair handle) $ M.toList simpleMetaData
9697 mapM_ (writeSection handle) $ M.toList sectionMetaData
97− hPutStrLn handle "---"
98− hPutStr handle $ getBody page
98+ U.hPutStrLn handle "---"
99+ U.hPutStrLn handle $ getBody page
99100 hClose handle
100101
101− writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
102− hPutStrLn h ""
102+ writePair h (k, v) = do U.hPutStr h $ k ++ ": " ++ v
103+ U.hPutStrLn h ""
103104
104− writeSection h (k, v) = do hPutStrLn h $ "--- " ++ k
105− hPutStrLn h v
105+ writeSection h (k, v) = do U.hPutStrLn h $ "--- " ++ k
106+ U.hPutStrLn h v
106107
107108 destination = toCache $ getURL page
108109
@@ -116,13 +117,13 @@ readPage pagePath = do
116117
117118 -- Read file.
118119 handle <- liftIO $ openFile path ReadMode
119− line <- liftIO $ hGetLine handle
120+ line <- liftIO $ U.hGetLine handle
120121 (metaData, body) <-
121122 if isDelimiter line
122123 then do md <- readMetaData handle
123− b <- liftIO $ hGetContents handle
124+ b <- liftIO $ U.hGetContents handle
124125 return (md, b)
125− else do b <- liftIO $ hGetContents handle
126+ else do b <- liftIO $ U.hGetContents handle
126127 return ([], line ++ "\n" ++ b)
127128
128129 -- Render file
src/Text/Hakyll/Render/Internal.hs+2−1
@@ -16,6 +16,7 @@ import Data.List (isPrefixOf, foldl')
1616import Data.Char (isAlpha)
1717import Data.Maybe (fromMaybe)
1818import Control.Parallel.Strategies (rdeepseq, ($|))
19+import qualified System.IO.UTF8 as U
1920
2021import Text.Hakyll.Renderable
2122import Text.Hakyll.Page
@@ -89,6 +90,6 @@ writePage page = do
8990 context = additionalContext' `M.union` (M.singleton "root" $ toRoot url)
9091 makeDirectories destination
9192    -- Substitute $root here, just before writing.
92− liftIO $ writeFile destination $ finalSubstitute (getBody page) context
93+ liftIO $ U.writeFile destination $ finalSubstitute (getBody page) context
9394 where
9495 url = getURL page