-
Notifications
You must be signed in to change notification settings - Fork 6
/
site.hs
92 lines (72 loc) · 2.67 KB
/
site.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{-# LANGUAGE OverloadedStrings #-}
import Hakyll
import Control.Applicative ((<$>))
import qualified Data.ByteString.Lazy.Char8 as LazyByte
import qualified Data.Text as Txt
import qualified Data.Text.Encoding as Encoding
import Text.Regex.TDFA ((=~))
import Text.Jasmine
----- JFlex hakyll site script -----
main :: IO ()
main = hakyll $ do
match ("img/*" .||. "css/*.min.css" .||. "js/*.min.js" .||. "fonts/*" .||. "release/*") $ do
route idRoute
compile copyFileCompiler
match ("files/*") $ do
route $ gsubRoute "files/" (const "")
compile copyFileCompiler
match ("files/fig/*") $ do
route $ gsubRoute "files/fig/" (const "fig/")
compile copyFileCompiler
match ("docs/*") $ do
route $ gsubRoute "docs/" (const "")
compile copyFileCompiler
match "js/*.js" $ do
route idRoute
compile compressJsCompiler
match "css/*.css" $ do
route idRoute
compile compressCssCompiler
match "pages/*.md" $ do
route $ setExtension "html" `composeRoutes`
gsubRoute "pages/" (const "")
compile $ do
body <- getResourceBody
filtered <- return $ fmap issueFilter body
renderPandoc filtered
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
-- raw html include, does not apply issue filter
match "pages/*.html" $ do
route $ gsubRoute "pages/" (const "")
compile $ getResourceBody
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
match "templates/*" $ compile templateCompiler
-- pages/installing.md was removed in favor of the user manual
create ["installing.html"] $ do
route idRoute
compile $ makeItem $ Redirect "manual.html#Installing"
-----------------------
issueFilter :: String -> String
issueFilter markdown = substAll "#[0-9]{1,4}[^0-9]" subst markdown
where
subst :: String -> String
subst match =
let lst = [last match]
num = tail (init match)
url = "https://github.com/jflex-de/jflex/issues/"
in "[#" ++ num ++ "](" ++ url ++ num ++ ")" ++ lst
substAll :: String -> (String -> String) -> String -> String
substAll expr subst input =
let
(before, match, after) = input =~ expr
in
if not (null match)
then before ++ subst match ++ substAll expr subst after
else input
compressJsCompiler :: Compiler (Item String)
compressJsCompiler = fmap jasmin <$> getResourceString
jasmin :: String -> String
jasmin src = LazyByte.unpack $ minify $
LazyByte.fromChunks [(Encoding.encodeUtf8 $ Txt.pack src)]