1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 03:04:53 +09:00

Use path segment in HighlightStyleR, addStylesheet doesn't support query params

This commit is contained in:
fr33domlover 2019-05-27 19:54:11 +00:00
parent e02a0fa4db
commit eb514b8c3f
5 changed files with 19 additions and 15 deletions

View file

@ -20,7 +20,7 @@
/favicon.ico FaviconR GET /favicon.ico FaviconR GET
/robots.txt RobotsR GET /robots.txt RobotsR GET
/highlight.css HighlightStyleR GET /highlight/#Text/style.css HighlightStyleR GET
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
-- Federation -- Federation

View file

@ -363,14 +363,9 @@ postRepoDevR shr rp dev = do
Just "DELETE" -> deleteRepoDevR shr rp dev Just "DELETE" -> deleteRepoDevR shr rp dev
_ -> notFound _ -> notFound
getHighlightStyleR :: Handler TypedContent getHighlightStyleR :: Text -> Handler TypedContent
getHighlightStyleR = do getHighlightStyleR styleName =
styleName <- do case lookup (unpack styleName) highlightingStyles of
ms <- lookupGetParam "style"
case ms of
Nothing -> getsYesod $ appHighlightStyle . appSettings
Just s -> return $ unpack s
case lookup styleName highlightingStyles of
Nothing -> notFound Nothing -> notFound
Just style -> Just style ->
return $ TypedContent typeCss $ toContent $ styleToCss style return $ TypedContent typeCss $ toContent $ styleToCss style

View file

@ -85,8 +85,11 @@ getDarcsRepoSource repository user repo dir = do
dirs = zip parent (tail $ inits parent) dirs = zip parent (tail $ inits parent)
defaultLayout $ do defaultLayout $ do
ms <- lookupGetParam "style" ms <- lookupGetParam "style"
let mparam = ("style",) <$> ms style <-
addStylesheetAttrs HighlightStyleR $ maybeToList mparam case ms of
Nothing -> getsYesod $ appHighlightStyle . appSettings
Just s -> return s
addStylesheet $ HighlightStyleR style
$(widgetFile "repo/source-darcs") $(widgetFile "repo/source-darcs")
getDarcsRepoHeadChanges :: ShrIdent -> RpIdent -> Handler TypedContent getDarcsRepoHeadChanges :: ShrIdent -> RpIdent -> Handler TypedContent

View file

@ -95,8 +95,11 @@ getGitRepoSource repository user repo ref dir = do
dirs = zip parent (tail $ inits parent) dirs = zip parent (tail $ inits parent)
defaultLayout $ do defaultLayout $ do
ms <- lookupGetParam "style" ms <- lookupGetParam "style"
let mparam = ("style",) <$> ms style <-
addStylesheetAttrs HighlightStyleR $ maybeToList mparam case ms of
Nothing -> getsYesod $ appHighlightStyle . appSettings
Just s -> return s
addStylesheet $ HighlightStyleR style
$(widgetFile "repo/source-git") $(widgetFile "repo/source-git")
getGitRepoHeadChanges :: Repo -> ShrIdent -> RpIdent -> Handler TypedContent getGitRepoHeadChanges :: Repo -> ShrIdent -> RpIdent -> Handler TypedContent

View file

@ -43,6 +43,9 @@ import Text.Pandoc.Highlighting
import Yesod.Default.Config2 (applyEnvValue, configSettingsYml) import Yesod.Default.Config2 (applyEnvValue, configSettingsYml)
import Yesod.Default.Util (WidgetFileSettings, widgetFileNoReload, import Yesod.Default.Util (WidgetFileSettings, widgetFileNoReload,
widgetFileReload) widgetFileReload)
import qualified Data.Text as T
import Yesod.Mail.Send (MailSettings) import Yesod.Mail.Send (MailSettings)
-- | Runtime settings to configure this application. These settings can be -- | Runtime settings to configure this application. These settings can be
@ -158,7 +161,7 @@ data AppSettings = AppSettings
-- | Default color scheme for syntax highlighting of code blocks inside -- | Default color scheme for syntax highlighting of code blocks inside
-- documentes rendered with pandoc. -- documentes rendered with pandoc.
, appHighlightStyle :: String , appHighlightStyle :: Text
} }
instance FromJSON AppSettings where instance FromJSON AppSettings where
@ -214,7 +217,7 @@ instance FromJSON AppSettings where
s <- o .:? "highlight-style" .!= "zenburn" s <- o .:? "highlight-style" .!= "zenburn"
case lookup s highlightingStyles of case lookup s highlightingStyles of
Nothing -> fail $ "Highlighting style " ++ s ++ " not found" Nothing -> fail $ "Highlighting style " ++ s ++ " not found"
Just _ -> return s Just _ -> return $ T.pack s
return AppSettings {..} return AppSettings {..}
where where