summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/Hakyll/SimpleServer.hs21
-rw-r--r--src/Text/Hakyll/Page.hs25
-rw-r--r--src/Text/Hakyll/Render/Internal.hs3
3 files changed, 26 insertions, 23 deletions
diff --git a/src/Network/Hakyll/SimpleServer.hs b/src/Network/Hakyll/SimpleServer.hs
index e26924b..fbce349 100644
--- a/src/Network/Hakyll/SimpleServer.hs
+++ b/src/Network/Hakyll/SimpleServer.hs
@@ -8,7 +8,8 @@ import Prelude hiding (log)
import Control.Monad (forever)
import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
import Network
-import System.IO
+import System.IO (stderr, Handle, IOMode(..), openFile, hFileSize, hClose)
+import qualified System.IO.UTF8 as U
import System.Directory (doesFileExist, doesDirectoryExist)
import Control.Concurrent (forkIO)
import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
@@ -21,7 +22,7 @@ import Text.Hakyll.Regex
-- | Function to log from a chan.
log :: Chan String -> IO ()
-log logChan = forever (readChan logChan >>= hPutStrLn stderr)
+log logChan = forever (readChan logChan >>= U.hPutStrLn stderr)
-- | General server configuration.
data ServerConfig = ServerConfig { documentRoot :: FilePath
@@ -47,7 +48,7 @@ instance Show Request where
-- headers and body.
readRequest :: Handle -> Server Request
readRequest handle = do
- requestLine <- liftIO $ hGetLine handle
+ requestLine <- liftIO $ U.hGetLine handle
let [method, uri, version] = map trim $ splitRegex " " requestLine
return $ Request { requestMethod = method
, requestURI = uri
@@ -147,7 +148,7 @@ getMIMEHeader fileName =
result = lookup (takeExtension fileName) [ (".css", "text/css")
, (".gif", "image/gif")
, (".htm", "text/html")
- , (".html", "text/html")
+ , (".html", "text/html; charset=utf8")
, (".jpeg", "image/jpeg")
, (".jpg", "image/jpeg")
, (".js", "text/javascript")
@@ -171,21 +172,21 @@ respond handle = do
-- Send the response back to the handle.
liftIO $ putResponse response
where
- putResponse response = do hPutStr handle $ intercalate " "
+ putResponse response = do U.hPutStr handle $ intercalate " "
[ responseVersion response
, show $ responseStatusCode response
, responsePhrase response
]
- hPutStr handle "\r\n"
+ U.hPutStr handle "\r\n"
mapM_ putHeader
(M.toList $ responseHeaders response)
- hPutStr handle "\r\n"
- hPutStr handle $ responseBody response
- hPutStr handle "\r\n"
+ U.hPutStr handle "\r\n"
+ U.hPutStr handle $ responseBody response
+ U.hPutStr handle "\r\n"
hClose handle
putHeader (key, value) =
- hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
+ U.hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
-- | Start a simple http server on the given 'PortNumber', serving the given
-- directory.
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index f2664e2..bd15ad1 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -12,7 +12,8 @@ import Data.Maybe (fromMaybe)
import Control.Parallel.Strategies (rdeepseq, ($|))
import Control.Monad.Reader (liftIO)
import System.FilePath (takeExtension)
-import System.IO
+import System.IO (Handle, IOMode(..), openFile, hClose)
+import qualified System.IO.UTF8 as U
import Text.Pandoc
@@ -68,7 +69,7 @@ renderFunction ext = writeHtmlString writerOptions
-- | Read metadata header from a file handle.
readMetaData :: Handle -> Hakyll [(String, String)]
readMetaData handle = do
- line <- liftIO $ hGetLine handle
+ line <- liftIO $ U.hGetLine handle
if isDelimiter line
then return []
else do others <- readMetaData handle
@@ -91,18 +92,18 @@ cachePage page@(Page mapping) = do
writePageToCache = do
handle <- openFile destination WriteMode
- hPutStrLn handle "---"
+ U.hPutStrLn handle "---"
mapM_ (writePair handle) $ M.toList simpleMetaData
mapM_ (writeSection handle) $ M.toList sectionMetaData
- hPutStrLn handle "---"
- hPutStr handle $ getBody page
+ U.hPutStrLn handle "---"
+ U.hPutStrLn handle $ getBody page
hClose handle
- writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
- hPutStrLn h ""
+ writePair h (k, v) = do U.hPutStr h $ k ++ ": " ++ v
+ U.hPutStrLn h ""
- writeSection h (k, v) = do hPutStrLn h $ "--- " ++ k
- hPutStrLn h v
+ writeSection h (k, v) = do U.hPutStrLn h $ "--- " ++ k
+ U.hPutStrLn h v
destination = toCache $ getURL page
@@ -116,13 +117,13 @@ readPage pagePath = do
-- Read file.
handle <- liftIO $ openFile path ReadMode
- line <- liftIO $ hGetLine handle
+ line <- liftIO $ U.hGetLine handle
(metaData, body) <-
if isDelimiter line
then do md <- readMetaData handle
- b <- liftIO $ hGetContents handle
+ b <- liftIO $ U.hGetContents handle
return (md, b)
- else do b <- liftIO $ hGetContents handle
+ else do b <- liftIO $ U.hGetContents handle
return ([], line ++ "\n" ++ b)
-- Render file
diff --git a/src/Text/Hakyll/Render/Internal.hs b/src/Text/Hakyll/Render/Internal.hs
index d4c1697..b6810bb 100644
--- a/src/Text/Hakyll/Render/Internal.hs
+++ b/src/Text/Hakyll/Render/Internal.hs
@@ -16,6 +16,7 @@ import Data.List (isPrefixOf, foldl')
import Data.Char (isAlpha)
import Data.Maybe (fromMaybe)
import Control.Parallel.Strategies (rdeepseq, ($|))
+import qualified System.IO.UTF8 as U
import Text.Hakyll.Renderable
import Text.Hakyll.Page
@@ -89,6 +90,6 @@ writePage page = do
context = additionalContext' `M.union` (M.singleton "root" $ toRoot url)
makeDirectories destination
    -- Substitute $root here, just before writing.
- liftIO $ writeFile destination $ finalSubstitute (getBody page) context
+ liftIO $ U.writeFile destination $ finalSubstitute (getBody page) context
where
url = getURL page