10 import Data.ByteString.Base (LazyByteString)
11 import qualified Data.ByteString.Char8 as C8
13 import Data.Encoding.UTF8
14 import Network.HTTP.Lucu
16 import Subversion.Types
20 type PageName = String
26 , redirDest :: PageName
27 , redirRevision :: Maybe RevNum
28 , redirLastMod :: CalendarTime
32 , pageType :: MIMEType
33 , pageIsTheme :: Bool -- text/css 以外では無意味
34 , pageIsFeed :: Bool -- text/x-rakka 以外では無意味
35 , pageIsLocked :: Bool
36 , pageIsBoring :: Bool
37 , pageRevision :: Maybe RevNum
38 , pageLastMod :: CalendarTime
39 , pageSummary :: Maybe String
40 , pageOtherLang :: [(String, PageName)]
41 , pageContent :: LazyByteString
45 -- UTF-8 に encode してから 0x20 - 0x7E の範圍を除いて URI escape する。
46 encodePageName :: PageName -> FilePath
47 encodePageName = escapeURIString shouldEscape . C8.unpack . encode UTF8
49 shouldEscape :: Char -> Bool
51 | c >= ' ' && c <= '~' = False
55 -- URI unescape して UTF-8 から decode する。
56 decodePageName :: FilePath -> PageName
57 decodePageName = decode UTF8 . C8.pack . unEscapeString
60 mkPageURI :: URI -> PageName -> URI
61 mkPageURI baseURI name
62 | uriPath baseURI == "" = baseURI { uriPath = "/" ++ encoded }
63 | uriPath baseURI == "/" = baseURI { uriPath = "/" ++ encoded }
64 | last (uriPath baseURI) == '/' = baseURI { uriPath = uriPath baseURI ++ encoded }
65 | otherwise = baseURI { uriPath = uriPath baseURI ++ "/" ++ encoded }
67 encoded = encodePageName name