1--------------------------------------------------------------------------------
2-- | Module used for CSS compression. The compression is currently in a simple
3-- state, but would typically reduce the number of bytes by about 25%.
4module Hakyll.Web.CompressCss
10--------------------------------------------------------------------------------
11import Control.Applicative ((<$>))
12import Data.Char (isSpace)
13import Data.List (isPrefixOf)
16--------------------------------------------------------------------------------
17import Hakyll.Core.Compiler
18import Hakyll.Core.Item
19import Hakyll.Core.Util.String
22--------------------------------------------------------------------------------
23-- | Compiler form of 'compressCss'
24compressCssCompiler :: Compiler (Item String)
25compressCssCompiler = fmap compressCss <$> getResourceString
28--------------------------------------------------------------------------------
29-- | Compress CSS to speed up your site.
30compressCss :: String -> String
31compressCss = compressSeparators . stripComments . compressWhitespace
34--------------------------------------------------------------------------------
35-- | Compresses certain forms of separators.
36compressSeparators :: String -> String
38 replaceAll "; *}" (const "}") .
39 replaceAll " *([{};:]) *" (take 1 . dropWhile isSpace) .
40 replaceAll ";+" (const ";")
43--------------------------------------------------------------------------------
44-- | Compresses all whitespace.
45compressWhitespace :: String -> String
46compressWhitespace = replaceAll "[ \t\n\r]+" (const " ")
49--------------------------------------------------------------------------------
50-- | Function that strips CSS comments away.
51stripComments :: String -> String
54 | isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
55 | otherwise = head str : stripComments (drop 1 str)
59 | isPrefixOf "*/" str' = drop 2 str'
60 | otherwise = eatComments $ drop 1 str'
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list