]> gitweb @ CieloNegro.org - Rakka.git/blob - Rakka/Page.hs
wrote Loader.DefaultPage but not tested yet
[Rakka.git] / Rakka / Page.hs
1 module Rakka.Page
2     ( PageName
3     , Page(..)
4     , encodePageName
5     )
6     where
7
8 import           Data.ByteString.Base (LazyByteString)
9 import qualified Data.ByteString.Char8 as C8
10 import           Data.Encoding
11 import           Data.Encoding.UTF8
12 import           Network.HTTP.Lucu
13 import           Network.URI
14
15
16 type PageName = String
17
18
19 data Page
20     = Redirect PageName
21     | Page {
22         pageType      :: MIMEType
23       , pageIsTheme   :: Bool     -- text/css 以外では無意味
24       , pageIsFeed    :: Bool     -- text/x-rakka 以外では無意味
25       , pageIsLocked  :: Bool
26       , pageIsBoring  :: Bool
27       , pageSummary   :: Maybe String
28       , pageOtherLang :: [(String, PageName)]
29       , pageContent   :: LazyByteString
30       }
31
32
33 -- UTF-8 に encode してから 0x20 - 0x7E の範圍を除いて URI escape する。
34 encodePageName :: PageName -> FilePath
35 encodePageName = escapeURIString shouldEscape . C8.unpack . encode UTF8 
36     where
37       shouldEscape :: Char -> Bool
38       shouldEscape c
39           | c >= ' ' && c <= '~' = False
40           | otherwise            = True