on master help sign in
Added UTF8 where nessecary.
673ed68Jasper Van der Jeugt
hakyll.cabal+2−1
@@ -34,7 +34,8 @@ library
34 mtl >= 1.1,
34 mtl >= 1.1,
35 old-locale >= 1,
35 old-locale >= 1,
36 time >= 1,
36 time >= 1,
37− parallel >= 2
37+ parallel >= 2,
38+ utf8-string >= 0.3
38 exposed-modules: Text.Hakyll
39 exposed-modules: Text.Hakyll
39 Text.Hakyll.Hakyll
40 Text.Hakyll.Hakyll
40 Text.Hakyll.Render
41 Text.Hakyll.Render
src/Network/Hakyll/SimpleServer.hs+11−10
@@ -8,7 +8,8 @@ import Prelude hiding (log)
8import Control.Monad (forever)
8import Control.Monad (forever)
9import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
9import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
10import Network
10import Network
11−import System.IO
11+import System.IO (stderr, Handle, IOMode(..), openFile, hFileSize, hClose)
12+import qualified System.IO.UTF8 as U
12import System.Directory (doesFileExist, doesDirectoryExist)
13import System.Directory (doesFileExist, doesDirectoryExist)
13import Control.Concurrent (forkIO)
14import Control.Concurrent (forkIO)
14import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
15import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
@@ -21,7 +22,7 @@ import Text.Hakyll.Regex
21
22
22-- | Function to log from a chan.
23-- | Function to log from a chan.
23log :: Chan String -> IO ()
24log :: Chan String -> IO ()
24−log logChan = forever (readChan logChan >>= hPutStrLn stderr)
25+log logChan = forever (readChan logChan >>= U.hPutStrLn stderr)
25
26
26-- | General server configuration.
27-- | General server configuration.
27data ServerConfig = ServerConfig { documentRoot :: FilePath
28data ServerConfig = ServerConfig { documentRoot :: FilePath
@@ -47,7 +48,7 @@ instance Show Request where
47-- headers and body.
48-- headers and body.
48readRequest :: Handle -> Server Request
49readRequest :: Handle -> Server Request
49readRequest handle = do
50readRequest handle = do
50− requestLine <- liftIO $ hGetLine handle
51+ requestLine <- liftIO $ U.hGetLine handle
51 let [method, uri, version] = map trim $ splitRegex " " requestLine
52 let [method, uri, version] = map trim $ splitRegex " " requestLine
52 return $ Request { requestMethod = method
53 return $ Request { requestMethod = method
53 , requestURI = uri
54 , requestURI = uri
@@ -147,7 +148,7 @@ getMIMEHeader fileName =
147 result = lookup (takeExtension fileName) [ (".css", "text/css")
148 result = lookup (takeExtension fileName) [ (".css", "text/css")
148 , (".gif", "image/gif")
149 , (".gif", "image/gif")
149 , (".htm", "text/html")
150 , (".htm", "text/html")
150− , (".html", "text/html")
151+ , (".html", "text/html; charset=utf8")
151 , (".jpeg", "image/jpeg")
152 , (".jpeg", "image/jpeg")
152 , (".jpg", "image/jpeg")
153 , (".jpg", "image/jpeg")
153 , (".js", "text/javascript")
154 , (".js", "text/javascript")
@@ -171,21 +172,21 @@ respond handle = do
171 -- Send the response back to the handle.
172 -- Send the response back to the handle.
172 liftIO $ putResponse response
173 liftIO $ putResponse response
173 where
174 where
174− putResponse response = do hPutStr handle $ intercalate " "
175+ putResponse response = do U.hPutStr handle $ intercalate " "
175 [ responseVersion response
176 [ responseVersion response
176 , show $ responseStatusCode response
177 , show $ responseStatusCode response
177 , responsePhrase response
178 , responsePhrase response
178 ]
179 ]
179− hPutStr handle "\r\n"
180+ U.hPutStr handle "\r\n"
180 mapM_ putHeader
181 mapM_ putHeader
181 (M.toList $ responseHeaders response)
182 (M.toList $ responseHeaders response)
182− hPutStr handle "\r\n"
183+ U.hPutStr handle "\r\n"
183− hPutStr handle $ responseBody response
184+ U.hPutStr handle $ responseBody response
184− hPutStr handle "\r\n"
185+ U.hPutStr handle "\r\n"
185 hClose handle
186 hClose handle
186
187
187 putHeader (key, value) =
188 putHeader (key, value) =
188− hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
189+ U.hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
189
190
190-- | Start a simple http server on the given 'PortNumber', serving the given
191-- | Start a simple http server on the given 'PortNumber', serving the given
191-- directory.
192-- directory.
src/Text/Hakyll/Page.hs+13−12
@@ -12,7 +12,8 @@ import Data.Maybe (fromMaybe)
12import Control.Parallel.Strategies (rdeepseq, ($|))
12import Control.Parallel.Strategies (rdeepseq, ($|))
13import Control.Monad.Reader (liftIO)
13import Control.Monad.Reader (liftIO)
14import System.FilePath (takeExtension)
14import System.FilePath (takeExtension)
15−import System.IO
15+import System.IO (Handle, IOMode(..), openFile, hClose)
16+import qualified System.IO.UTF8 as U
16
17
17import Text.Pandoc
18import Text.Pandoc
18
19
@@ -68,7 +69,7 @@ renderFunction ext = writeHtmlString writerOptions
68-- | Read metadata header from a file handle.
69-- | Read metadata header from a file handle.
69readMetaData :: Handle -> Hakyll [(String, String)]
70readMetaData :: Handle -> Hakyll [(String, String)]
70readMetaData handle = do
71readMetaData handle = do
71− line <- liftIO $ hGetLine handle
72+ line <- liftIO $ U.hGetLine handle
72 if isDelimiter line
73 if isDelimiter line
73 then return []
74 then return []
74 else do others <- readMetaData handle
75 else do others <- readMetaData handle
@@ -91,18 +92,18 @@ cachePage page@(Page mapping) = do
91
92
92 writePageToCache = do
93 writePageToCache = do
93 handle <- openFile destination WriteMode
94 handle <- openFile destination WriteMode
94− hPutStrLn handle "---"
95+ U.hPutStrLn handle "---"
95 mapM_ (writePair handle) $ M.toList simpleMetaData
96 mapM_ (writePair handle) $ M.toList simpleMetaData
96 mapM_ (writeSection handle) $ M.toList sectionMetaData
97 mapM_ (writeSection handle) $ M.toList sectionMetaData
97− hPutStrLn handle "---"
98+ U.hPutStrLn handle "---"
98− hPutStr handle $ getBody page
99+ U.hPutStrLn handle $ getBody page
99 hClose handle
100 hClose handle
100
101
101− writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
102+ writePair h (k, v) = do U.hPutStr h $ k ++ ": " ++ v
102− hPutStrLn h ""
103+ U.hPutStrLn h ""
103
104
104− writeSection h (k, v) = do hPutStrLn h $ "--- " ++ k
105+ writeSection h (k, v) = do U.hPutStrLn h $ "--- " ++ k
105− hPutStrLn h v
106+ U.hPutStrLn h v
106
107
107 destination = toCache $ getURL page
108 destination = toCache $ getURL page
108
109
@@ -116,13 +117,13 @@ readPage pagePath = do
116
117
117 -- Read file.
118 -- Read file.
118 handle <- liftIO $ openFile path ReadMode
119 handle <- liftIO $ openFile path ReadMode
119− line <- liftIO $ hGetLine handle
120+ line <- liftIO $ U.hGetLine handle
120 (metaData, body) <-
121 (metaData, body) <-
121 if isDelimiter line
122 if isDelimiter line
122 then do md <- readMetaData handle
123 then do md <- readMetaData handle
123− b <- liftIO $ hGetContents handle
124+ b <- liftIO $ U.hGetContents handle
124 return (md, b)
125 return (md, b)
125− else do b <- liftIO $ hGetContents handle
126+ else do b <- liftIO $ U.hGetContents handle
126 return ([], line ++ "\n" ++ b)
127 return ([], line ++ "\n" ++ b)
127
128
128 -- Render file
129 -- Render file
src/Text/Hakyll/Render/Internal.hs+2−1
@@ -16,6 +16,7 @@ import Data.List (isPrefixOf, foldl')
16import Data.Char (isAlpha)
16import Data.Char (isAlpha)
17import Data.Maybe (fromMaybe)
17import Data.Maybe (fromMaybe)
18import Control.Parallel.Strategies (rdeepseq, ($|))
18import Control.Parallel.Strategies (rdeepseq, ($|))
19+import qualified System.IO.UTF8 as U
19
20
20import Text.Hakyll.Renderable
21import Text.Hakyll.Renderable
21import Text.Hakyll.Page
22import Text.Hakyll.Page
@@ -89,6 +90,6 @@ writePage page = do
89 context = additionalContext' `M.union` (M.singleton "root" $ toRoot url)
90 context = additionalContext' `M.union` (M.singleton "root" $ toRoot url)
90 makeDirectories destination
91 makeDirectories destination
91    -- Substitute $root here, just before writing.
92    -- Substitute $root here, just before writing.
92− liftIO $ writeFile destination $ finalSubstitute (getBody page) context
93+ liftIO $ U.writeFile destination $ finalSubstitute (getBody page) context
93 where
94 where
94 url = getURL page
95 url = getURL page