Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom HTML head #149

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

georgefst
Copy link
Contributor

This is a proof-of-concept breaking version. I'm not quite sure what a good API would look like.

I have found this useful, particularly for specifying stylesheets.

@georgefst
Copy link
Contributor Author

An alternative, which I'm using for now, is to modify the head imperatively with jsaddle-dom. For example, these are essentially equivalent:

main = debugOr
    (Just $ encodeUtf8 $ TL.pack "<link rel='stylesheet' href='style.css'/>")
    port
    start
    app
main = debugOr
    Nothing -- passing `Nothing` here is the same as using the old version of `debugOr`
    port
    (insertStylesheet "style.css" >> start)
    app
  where
    insertStylesheet stylesheetUrl = do
        Just doc <- currentDocument
        Just headEl <- getHead doc
        linkEl <- unsafeCastTo HTMLLinkElement =<< createElement doc "link"
        setRel linkEl "stylesheet"
        setHref linkEl stylesheetUrl
        appendChild_ headEl linkEl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant