Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/Generate/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ sandwich_ root moduleName javascript =
customHead
else
"<title>" <> name <> "</title>"

htmlTag = Lamdera.unsafe $ Lamdera.Live.lamderaHtmlLang root
in
[r|<!DOCTYPE HTML>
<html>
"<!DOCTYPE HTML>\n"
<> htmlTag
<> [r|
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, minimum-scale=1.0">
Expand Down
12 changes: 12 additions & 0 deletions extra/Lamdera/Live.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ lamderaLiveHead root = do
pure (False, "")


lamderaHtmlLang :: FilePath -> IO B.Builder
lamderaHtmlLang root = do
langM <- readUtf8Text $ root </> "html-lang"
pure $ maybe "<html>" toHtmlTag langM
where
toHtmlTag lang =
let trimmed = T.strip lang in
if T.null trimmed
then "<html>"
else "<html lang=\"" <> T.encodeUtf8Builder trimmed <> "\">"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should HTML-escape the value. Otherwise people will end up writing stuff like this in the file:

en" other-attribute="i want it" third="yes



lamderaLive :: BS.ByteString
lamderaLive =
$(bsToExp =<< runIO (Lamdera.Relative.readByteString "extra/dist/live.js"))