Created
July 12, 2021 18:45
-
-
Save pete-murphy/df23a0e30784dbf10864324c09684721 to your computer and use it in GitHub Desktop.
Set title and meta tag from Halogen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where -- Overwritten by Try PureScript | |
import Prelude | |
import Data.Foldable as Foldable | |
import Data.Maybe (Maybe(..)) | |
import Effect (Effect) | |
import Effect.Class (class MonadEffect, liftEffect) | |
import Halogen as H | |
import Halogen.HTML as HH | |
import Halogen.Aff as HA | |
import Halogen.VDom.Driver (runUI) | |
import Halogen.Hooks as Hooks | |
import Web.DOM.Element as Element | |
import Web.DOM.ParentNode as ParentNode | |
import Web.DOM.ParentNode (QuerySelector(..)) | |
import Web.HTML as HTML | |
import Web.HTML.HTMLDocument as HTMLDocument | |
import Web.HTML.Window as Window | |
main :: Effect Unit | |
main = | |
HA.runHalogenAff do | |
body <- HA.awaitBody | |
void $ runUI hookComponent Nothing body | |
hookComponent | |
:: forall unusedQuery unusedInput unusedOutput m | |
. MonadEffect m | |
=> H.Component unusedQuery unusedInput unusedOutput m | |
hookComponent = Hooks.component \_ _ -> Hooks.do | |
Hooks.useLifecycleEffect do | |
liftEffect do | |
document <- HTML.window >>= Window.document | |
HTMLDocument.setTitle "Hello" document | |
maybeEl <- ParentNode.querySelector | |
(QuerySelector "meta[name=\"description\"]") | |
(HTMLDocument.toParentNode document) | |
Foldable.for_ maybeEl (Element.setAttribute "content" "Whatever you want") | |
pure Nothing | |
Hooks.pure $ | |
HH.text "Hello!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment