{-|
Module: IHP.PageHead.ControllerFunctions
Description: Manage the @<title>@ and @<meta>@ tags of your HTML pages
Copyright: (c) digitally induced GmbH, 2021
-}
module IHP.PageHead.ControllerFunctions
( setTitle
, setDescription
, setOGTitle
, setOGType
, setOGDescription
, setOGUrl
, setOGImage
) where

import IHP.Prelude
import IHP.PageHead.Types
import IHP.Controller.Context

-- | Sets the page title. Can be accessed using '{pageTitle}' inside your @Layout.hs@.
--
-- Example:
--
-- > action ShowProjectAction { projectId } = do
-- >     project <- fetch projectId
-- >     setTitle (get #title project)
-- >
--
-- Inside your layout use it like:
--
-- > defaultLayout :: Html -> Html
-- > defaultLayout inner = [hsx|
-- > <head>
-- >     <title>{pageTitle}</title>
-- > </head>
-- > |]
--
setTitle :: (?context :: ControllerContext) => Text -> IO ()
setTitle :: Text -> IO ()
setTitle Text
title = PageTitle -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> PageTitle
PageTitle Text
title)

setDescription :: (?context :: ControllerContext) => Text -> IO ()
setDescription :: Text -> IO ()
setDescription Text
description = PageDescription -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> PageDescription
PageDescription Text
description)

setOGTitle :: (?context :: ControllerContext) => Text -> IO ()
setOGTitle :: Text -> IO ()
setOGTitle Text
title = OGTitle -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> OGTitle
OGTitle Text
title)

setOGType :: (?context :: ControllerContext) => Text -> IO ()
setOGType :: Text -> IO ()
setOGType Text
type_ = OGType -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> OGType
OGType Text
type_)

setOGDescription :: (?context :: ControllerContext) => Text -> IO ()
setOGDescription :: Text -> IO ()
setOGDescription Text
description = OGDescription -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> OGDescription
OGDescription Text
description)

setOGUrl :: (?context :: ControllerContext) => Text -> IO ()
setOGUrl :: Text -> IO ()
setOGUrl Text
url = OGUrl -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> OGUrl
OGUrl Text
url)

setOGImage :: (?context :: ControllerContext) => Text -> IO ()
setOGImage :: Text -> IO ()
setOGImage Text
image = OGImage -> IO ()
forall value.
(?context::ControllerContext, Typeable value) =>
value -> IO ()
putContext (Text -> OGImage
OGImage Text
image)