mirror of
https://github.com/youwen5/blog.git
synced 2024-11-24 18:03:50 -08:00
fix: explicitly set utf-8 encoding in haskell
avoids invalid character encoding issues on some systems
This commit is contained in:
parent
dbf23c7e9b
commit
3043df6f92
1 changed files with 61 additions and 58 deletions
119
ssg/src/Main.hs
119
ssg/src/Main.hs
|
@ -5,6 +5,7 @@ import Data.List (isPrefixOf, isSuffixOf)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Slugger as Slugger
|
import qualified Data.Text.Slugger as Slugger
|
||||||
|
import qualified GHC.IO.Encoding as E
|
||||||
import Hakyll
|
import Hakyll
|
||||||
import System.FilePath (takeFileName)
|
import System.FilePath (takeFileName)
|
||||||
import Text.Pandoc (
|
import Text.Pandoc (
|
||||||
|
@ -76,74 +77,76 @@ config =
|
||||||
-- BUILD
|
-- BUILD
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = hakyllWith config $ do
|
main = do
|
||||||
forM_
|
E.setLocaleEncoding E.utf8
|
||||||
[ "CNAME"
|
hakyllWith config $ do
|
||||||
, "favicon.ico"
|
forM_
|
||||||
, "robots.txt"
|
[ "CNAME"
|
||||||
, "_config.yml"
|
, "favicon.ico"
|
||||||
, "images/*"
|
, "robots.txt"
|
||||||
, "out/*"
|
, "_config.yml"
|
||||||
, "fonts/*"
|
, "images/*"
|
||||||
]
|
, "out/*"
|
||||||
$ \f -> match f $ do
|
, "fonts/*"
|
||||||
|
]
|
||||||
|
$ \f -> match f $ do
|
||||||
|
route idRoute
|
||||||
|
compile copyFileCompiler
|
||||||
|
|
||||||
|
match "posts/*" $ do
|
||||||
|
let ctx = constField "type" "article" <> postCtx
|
||||||
|
|
||||||
|
route $ metadataRoute titleRoute
|
||||||
|
compile $
|
||||||
|
pandocCompilerCustom
|
||||||
|
>>= loadAndApplyTemplate "templates/post.html" ctx
|
||||||
|
>>= saveSnapshot "content"
|
||||||
|
>>= loadAndApplyTemplate "templates/default.html" ctx
|
||||||
|
|
||||||
|
match "index.html" $ do
|
||||||
route idRoute
|
route idRoute
|
||||||
compile copyFileCompiler
|
compile $ do
|
||||||
|
posts <- recentFirst =<< loadAll "posts/*"
|
||||||
|
|
||||||
match "posts/*" $ do
|
let indexCtx =
|
||||||
let ctx = constField "type" "article" <> postCtx
|
listField "posts" postCtx (return posts)
|
||||||
|
<> constField "root" mySiteRoot
|
||||||
|
<> constField "feedTitle" myFeedTitle
|
||||||
|
<> constField "siteName" mySiteName
|
||||||
|
<> defaultContext
|
||||||
|
|
||||||
route $ metadataRoute titleRoute
|
getResourceBody
|
||||||
compile $
|
>>= applyAsTemplate indexCtx
|
||||||
pandocCompilerCustom
|
>>= loadAndApplyTemplate "templates/default.html" indexCtx
|
||||||
>>= loadAndApplyTemplate "templates/post.html" ctx
|
|
||||||
>>= saveSnapshot "content"
|
|
||||||
>>= loadAndApplyTemplate "templates/default.html" ctx
|
|
||||||
|
|
||||||
match "index.html" $ do
|
match "templates/*" $
|
||||||
route idRoute
|
compile templateBodyCompiler
|
||||||
compile $ do
|
|
||||||
posts <- recentFirst =<< loadAll "posts/*"
|
|
||||||
|
|
||||||
let indexCtx =
|
create ["sitemap.xml"] $ do
|
||||||
listField "posts" postCtx (return posts)
|
route idRoute
|
||||||
<> constField "root" mySiteRoot
|
compile $ do
|
||||||
<> constField "feedTitle" myFeedTitle
|
posts <- recentFirst =<< loadAll "posts/*"
|
||||||
<> constField "siteName" mySiteName
|
|
||||||
<> defaultContext
|
|
||||||
|
|
||||||
getResourceBody
|
let pages = posts
|
||||||
>>= applyAsTemplate indexCtx
|
sitemapCtx =
|
||||||
>>= loadAndApplyTemplate "templates/default.html" indexCtx
|
constField "root" mySiteRoot
|
||||||
|
<> constField "siteName" mySiteName
|
||||||
|
<> listField "pages" postCtx (return pages)
|
||||||
|
|
||||||
match "templates/*" $
|
makeItem ("" :: String)
|
||||||
compile templateBodyCompiler
|
>>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx
|
||||||
|
|
||||||
create ["sitemap.xml"] $ do
|
create ["rss.xml"] $ do
|
||||||
route idRoute
|
route idRoute
|
||||||
compile $ do
|
compile (feedCompiler renderRss)
|
||||||
posts <- recentFirst =<< loadAll "posts/*"
|
|
||||||
|
|
||||||
let pages = posts
|
create ["atom.xml"] $ do
|
||||||
sitemapCtx =
|
route idRoute
|
||||||
constField "root" mySiteRoot
|
compile (feedCompiler renderAtom)
|
||||||
<> constField "siteName" mySiteName
|
|
||||||
<> listField "pages" postCtx (return pages)
|
|
||||||
|
|
||||||
makeItem ("" :: String)
|
create ["css/code.css"] $ do
|
||||||
>>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx
|
route idRoute
|
||||||
|
compile (makeStyle pandocHighlightStyle)
|
||||||
create ["rss.xml"] $ do
|
|
||||||
route idRoute
|
|
||||||
compile (feedCompiler renderRss)
|
|
||||||
|
|
||||||
create ["atom.xml"] $ do
|
|
||||||
route idRoute
|
|
||||||
compile (feedCompiler renderAtom)
|
|
||||||
|
|
||||||
create ["css/code.css"] $ do
|
|
||||||
route idRoute
|
|
||||||
compile (makeStyle pandocHighlightStyle)
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- COMPILER HELPERS
|
-- COMPILER HELPERS
|
||||||
|
|
Loading…
Reference in a new issue