mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-20 07:51:55 +01:00
Allow change badge's label and style
This commit is contained in:
parent
353ecd9903
commit
2decb3516e
@ -31,16 +31,29 @@ getPackageBadgeR pname branch = do
|
|||||||
Entity sid _ <- maybe notFound pure =<< lookupSnapshot snapName
|
Entity sid _ <- maybe notFound pure =<< lookupSnapshot snapName
|
||||||
mVersion <- do mSnapPackage <- lookupSnapshotPackage sid (unPackageName pname)
|
mVersion <- do mSnapPackage <- lookupSnapshotPackage sid (unPackageName pname)
|
||||||
pure (Version . snapshotPackageVersion . entityVal <$> mSnapPackage)
|
pure (Version . snapshotPackageVersion . entityVal <$> mSnapPackage)
|
||||||
respond typeSvg $ renderStackageBadge snapName mVersion
|
|
||||||
|
|
||||||
renderStackageBadge :: SnapName -> Maybe Version -> LByteString
|
mLabel <- lookupGetParam "label"
|
||||||
renderStackageBadge (badgeLabel -> label) = \case
|
mStyle <- lookupGetParam "style"
|
||||||
Nothing -> renderBadge (flat & right .~ lightgray) label "not available"
|
|
||||||
Just (Version x) -> renderBadge flat label x
|
|
||||||
|
|
||||||
badgeLabel :: SnapName -> Text
|
respond typeSvg $ case mStyle of
|
||||||
badgeLabel (SNNightly _) = "stackage nightly"
|
Just "plastic" -> renderStackageBadge plastic mLabel snapName mVersion
|
||||||
badgeLabel (SNLts x _) = "stackage lts-" <> tshow x
|
Just "flat-square" -> renderStackageBadge flatSquare mLabel snapName mVersion
|
||||||
|
_ -> renderStackageBadge flat mLabel snapName mVersion
|
||||||
|
|
||||||
|
renderStackageBadge :: (Badge b, HasRightColor b)
|
||||||
|
=> b -- ^ Style
|
||||||
|
-> Maybe Text -- ^ Label
|
||||||
|
-> SnapName
|
||||||
|
-> Maybe Version
|
||||||
|
-> LByteString
|
||||||
|
renderStackageBadge style mLabel snapName = \case
|
||||||
|
Nothing -> renderBadge (style & right .~ lightgray) badgeLabel "not available"
|
||||||
|
Just (Version x) -> renderBadge style badgeLabel x
|
||||||
|
where
|
||||||
|
badgeLabel = fromMaybe "stackage" mLabel <> " " <> badgeSnapName snapName
|
||||||
|
|
||||||
|
badgeSnapName (SNNightly _) = "nightly"
|
||||||
|
badgeSnapName (SNLts x _) = "lts-" <> tshow x
|
||||||
|
|
||||||
packagePage :: Maybe (SnapName, Version)
|
packagePage :: Maybe (SnapName, Version)
|
||||||
-> PackageName
|
-> PackageName
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user