-
Notifications
You must be signed in to change notification settings - Fork 2
/
Index.elm
126 lines (114 loc) · 5.2 KB
/
Index.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
module Index exposing (htmlToReinject, index)
import Html.String exposing (..)
import Html.String.Attributes exposing (..)
import Html.String.Extra exposing (..)
import Main
import Starter.ConfMeta
import Starter.FileNames
import Starter.Flags
import Starter.Icon
import Starter.SnippetCss
import Starter.SnippetHtml
import Starter.SnippetJavascript
index : Starter.Flags.Flags -> Html msg
index flags =
let
relative =
Starter.Flags.toRelative flags
fileNames =
Starter.FileNames.fileNames flags.version flags.commit
in
html
[ lang "en" ]
[ head []
([]
++ [ meta [ charset "utf-8" ] []
, title_ [] [ text flags.nameLong ]
, meta [ name "author", content flags.author ] []
, meta [ name "description", content flags.description ] []
, meta [ name "viewport", content "width=device-width, initial-scale=1, shrink-to-fit=no" ] []
, meta [ httpEquiv "x-ua-compatible", content "ie=edge" ] []
, link [ rel "icon", href (Starter.Icon.iconFileName relative 64) ] []
, link [ rel "apple-touch-icon", href (Starter.Icon.iconFileName relative 152) ] []
, style_ []
[ text <| """
body
{ background-color: """ ++ Starter.Flags.toThemeColor flags ++ """
; font-family: 'IBM Plex Sans', helvetica, sans-serif
; margin: 0px;
}""" ]
]
++ Starter.SnippetHtml.messagesStyle
++ Starter.SnippetHtml.pwa
{ commit = flags.commit
, relative = relative
, themeColor = Starter.Flags.toThemeColor flags
, version = flags.version
}
++ Starter.SnippetHtml.previewCards
{ commit = flags.commit
, flags = flags
, mainConf = Main.conf
, version = flags.version
}
)
, body [] <| htmlToReinject flags
]
htmlToReinject : Starter.Flags.Flags -> List (Html.String.Html msg)
htmlToReinject flags =
let
relative =
Starter.Flags.toRelative flags
fileNames =
Starter.FileNames.fileNames flags.version flags.commit
in
[]
-- Friendly message in case Javascript is disabled
++ (if flags.env == "dev" then
Starter.SnippetHtml.messageYouNeedToEnableJavascript
else
Starter.SnippetHtml.messageEnableJavascriptForBetterExperience
)
-- Initializing "window.ElmStarter"
++ [ script [] [ textUnescaped <| Starter.SnippetJavascript.metaInfo flags ] ]
-- Loading Elm code
++ [ script [ src (relative ++ fileNames.outputCompiledJsProd) ] [] ]
-- Elm finished to load, de-activating the "Loading..." message
-- ++ Starter.SnippetHtml.messageLoadingOff
-- Loading utility for pretty console formatting
++ Starter.SnippetHtml.prettyConsoleFormatting relative flags.env
-- Signature "Made with ❤ and Elm"
++ [ Html.String.Extra.script [] [ Html.String.textUnescaped Starter.SnippetJavascript.signature ] ]
-- Let's start Elm!
++ [ Html.String.Extra.script []
[ Html.String.textUnescaped
("""
// Need to remove this node otherwise Elm doesn't work
// because it seems that Elm detect that a similar part
// of the DOM already exists and it trys to hydrate, but
// the code is buggy.
// Infact, not removing this node, the links in the
// application reload the browser also if they are
// internal.
var node = document.getElementById('elm');
if (node) { node.remove(); }
window.ElmApp = Elm.Main.init(
{ flags:
// From package.jspn
{ starter : """
++ Starter.SnippetJavascript.metaInfoData flags
++ """
// Others
, width: window.innerWidth
, height: window.innerHeight
, languages: window.navigator.userLanguages || window.navigator.languages || []
, locationHref: location.href
}
}
);"""
++ Starter.SnippetJavascript.portChangeMeta
)
]
]
-- Register the Service Worker, we are a PWA!
++ [ Html.String.Extra.script [] [ Html.String.textUnescaped (Starter.SnippetJavascript.registerServiceWorker relative) ] ]