]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Resource/PageEntity.hs
misc changes
[Rakka.git] / Rakka / Resource / PageEntity.hs
index 8fd0ed4d4024b39cc851a6ec88b4441225ef8c8b..a9eff98ac6c1890741ca546d7e0028c935f157c5 100644 (file)
@@ -3,7 +3,9 @@ module Rakka.Resource.PageEntity
     )
     where
 
+import qualified Codec.Binary.UTF8.String as UTF8
 import           Control.Monad.Trans
+import qualified Data.ByteString.Lazy as L hiding (ByteString)
 import           Data.Char
 import qualified Data.Map as M
 import           Data.Maybe
@@ -81,7 +83,9 @@ handleRedirect env
                                                                 >>>
                                                                 xmlizePage
                                                                 >>>
-                                                                writeDocumentToString [ (a_indent, v_1) ]
+                                                                writeDocumentToString [ (a_indent         , v_1 )
+                                                                                      , (a_output_encoding, utf8)
+                                                                                      , (a_no_xml_pi      , v_0 ) ]
                                                               )
                                  output resultStr
 
@@ -116,9 +120,6 @@ entityToXHTML env
           let cssHref   = [uriToString id (mkObjectURI baseURI styleSheet) ""]
               scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI </> "js" }) ""]
 
-          feeds       <- arrIO0 (findFeeds (envStorage env)) -< ()
-          javaScripts <- arrIO0 (findJavaScripts (envStorage env)) -< ()
-
           pageTitle    <- listA (readSubPage env) -< (name, Just page, "PageTitle")
           leftSideBar  <- listA (readSubPage env) -< (name, Just page, "SideBar/Left")
           rightSideBar <- listA (readSubPage env) -< (name, Just page, "SideBar/Right")
@@ -145,14 +146,7 @@ entityToXHTML env
                            += sattr "type" "text/css"
                            += attr "href" (arr id >>> mkText)
                          )
-                      += ( constL feeds
-                           >>>
-                           eelem "link"
-                           += sattr "rel"   "alternate"
-                           += sattr "type"  "application/rss+xml"
-                           += attr  "title" (txt siteName <+> txt " - " <+> mkText)
-                           += attr  "href"  (arr (mkFeedURIStr baseURI) >>> mkText)
-                         )
+                      += mkFeedList env
                       += ( constL scriptSrc
                            >>>
                            eelem "script"
@@ -165,12 +159,7 @@ entityToXHTML env
                            += txt ("Rakka.isLocked=" ++ trueOrFalse isLocked ++ ";")
                            += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";")
                          )
-                      += ( constL javaScripts
-                           >>>
-                           eelem "script"
-                           += sattr "type" "text/javascript"
-                           += attr "src" (arr (mkObjectURIStr baseURI) >>> mkText)
-                         )
+                      += mkGlobalJSList env
                     )
                  += ( eelem "body"
                       += ( eelem "div"
@@ -371,9 +360,6 @@ pageListingToXHTML env
           let cssHref   = [uriToString id (mkObjectURI baseURI styleSheet) ""]
               scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI </> "js" }) ""]
 
-          feeds       <- arrIO0 (findFeeds (envStorage env)) -< ()
-          javaScripts <- arrIO0 (findJavaScripts (envStorage env)) -< ()
-
           pageTitle    <- listA (readSubPage env) -< (name, Nothing, "PageTitle")
           leftSideBar  <- listA (readSubPage env) -< (name, Nothing, "SideBar/Left")
           rightSideBar <- listA (readSubPage env) -< (name, Nothing, "SideBar/Right")
@@ -394,14 +380,7 @@ pageListingToXHTML env
                            += sattr "type" "text/css"
                            += attr "href" (arr id >>> mkText)
                          )
-                      += ( constL feeds
-                           >>>
-                           eelem "link"
-                           += sattr "rel"   "alternate"
-                           += sattr "type"  "application/rss+xml"
-                           += attr  "title" (txt siteName <+> txt " - " <+> mkText)
-                           += attr  "href"  (arr (mkFeedURIStr baseURI) >>> mkText)
-                         )
+                      += mkFeedList env
                       += ( constL scriptSrc
                            >>>
                            eelem "script"
@@ -413,12 +392,7 @@ pageListingToXHTML env
                            += txt ("Rakka.baseURI = \"" ++ uriToString id baseURI "" ++ "\";")
                            += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";")
                          )
-                      += ( constL javaScripts
-                           >>>
-                           eelem "script"
-                           += sattr "type" "text/javascript"
-                           += attr "src" (arr (mkObjectURIStr baseURI) >>> mkText)
-                         )
+                      += mkGlobalJSList env
                     )
                  += ( eelem "body"
                       += ( eelem "div"
@@ -500,9 +474,6 @@ notFoundToXHTML env
           let cssHref   = [uriToString id (mkObjectURI baseURI styleSheet) ""]
               scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI </> "js" }) ""]
 
-          feeds       <- arrIO0 (findFeeds (envStorage env)) -< ()
-          javaScripts <- arrIO0 (findJavaScripts (envStorage env)) -< ()
-
           pageTitle    <- listA (readSubPage env) -< (name, Nothing, "PageTitle")
           leftSideBar  <- listA (readSubPage env) -< (name, Nothing, "SideBar/Left")
           rightSideBar <- listA (readSubPage env) -< (name, Nothing, "SideBar/Right")
@@ -523,14 +494,7 @@ notFoundToXHTML env
                            += sattr "type" "text/css"
                            += attr "href" (arr id >>> mkText)
                          )
-                      += ( constL feeds
-                           >>>
-                           eelem "link"
-                           += sattr "rel"   "alternate"
-                           += sattr "type"  "application/rss+xml"
-                           += attr  "title" (txt siteName <+> txt " - " <+> mkText)
-                           += attr  "href"  (arr (mkFeedURIStr baseURI) >>> mkText)
-                         )
+                      += mkFeedList env
                       += ( constL scriptSrc
                            >>>
                            eelem "script"
@@ -542,12 +506,7 @@ notFoundToXHTML env
                            += txt ("Rakka.baseURI = \"" ++ uriToString id baseURI "" ++ "\";")
                            += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";")
                          )
-                      += ( constL javaScripts
-                           >>>
-                           eelem "script"
-                           += sattr "type" "text/javascript"
-                           += attr "src" (arr (mkObjectURIStr baseURI) >>> mkText)
-                         )
+                      += mkGlobalJSList env
                     )
                  += ( eelem "body"
                       += ( eelem "div"
@@ -603,6 +562,20 @@ handleDelete env name
          setStatus status
 
 
+mkFeedList :: (ArrowIO a, ArrowXml a) => Environment -> a b XmlTree
+mkFeedList env
+    = proc _ -> do SiteName siteName <- getSysConfA (envSysConf env) -< ()
+                   BaseURI  baseURI  <- getSysConfA (envSysConf env) -< ()
+
+                   feed <- unlistA <<< arrIO0 (findFeeds $ envStorage env) -< ()
+                   
+                   ( eelem "link"
+                     += sattr "rel"   "alternate"
+                     += sattr "type"  "application/rss+xml"
+                     += attr  "title" (txt siteName <+> txt " - " <+> mkText)
+                     += attr  "href"  (arr (mkFeedURIStr baseURI) >>> mkText) ) -<< feed
+
+
 findFeeds :: Storage -> IO [PageName]
 findFeeds sto
     = do cond <- newCondition
@@ -613,6 +586,30 @@ findFeeds sto
          return (map hpPageName $ srPages result)
 
 
+mkGlobalJSList :: (ArrowIO a, ArrowXml a, ArrowChoice a) => Environment -> a b XmlTree
+mkGlobalJSList env
+    = proc _ -> do BaseURI baseURI  <- getSysConfA (envSysConf env) -< ()
+
+                   scriptName <- unlistA <<< arrIO0 (findJavaScripts $ envStorage env) -< ()
+                   pageM      <- getPageA (envStorage env) -< (scriptName, Nothing)
+
+                   case pageM of
+                     Nothing -> none -< ()
+                     Just page
+                         | isEntity page
+                             -> ( if entityIsBinary page then
+                                      ( eelem "script"
+                                        += sattr "type" "text/javascript"
+                                        += attr "src" (arr (mkObjectURIStr baseURI . pageName) >>> mkText) )
+                                  else
+                                      ( eelem "script"
+                                        += sattr "type" "text/javascript"
+                                        += (arr (UTF8.decode . L.unpack . entityContent) >>> mkText) )
+                                ) -<< page
+                         | otherwise
+                             -> none -< ()
+
+
 findJavaScripts :: Storage -> IO [PageName]
 findJavaScripts sto
     = do cond <- newCondition