@@ -54,14 +54,14 @@ loadFontAsBase64 fontPath = do
5454 let base64Text = TE. decodeUtf8 $ Base64. encode fontBytes
5555 return base64Text
5656 case result of
57- Left (_ :: SomeException ) -> return Nothing
57+ Left (_ :: SomeException ) -> return Nothing -- TODO handle this situation properly
5858 Right base64 -> return $ Just base64
5959
6060-- TODO split this one into fetching and rendering
6161renderAll :: Blogroll -> IO ()
6262renderAll blogroll = do
6363 let urls = blogroll. urls
64- fontBase64 <- loadFontAsBase64 " IBMPlexSans-Regular.woff2 "
64+ fontBase64 <- loadFontAsBase64 blogroll . pathToFontFile
6565 faviconMap <- fetchAllFavicons urls
6666 let faviconCss = generateFaviconCss faviconMap
6767 feeds <- mapConcurrently fetchFeed urls
@@ -87,87 +87,98 @@ renderAll blogroll = do
8787
8888renderHtml :: [FeedEntry ] -> Text -> Text -> Maybe Text -> Text
8989renderHtml entries pageTitle faviconCss maybeFontBase64 =
90- TL. toStrict $ renderText $ doctype_ <> html_ (do
91- head_ (do
92- meta_ [name_ " viewport" , content_ " width=device-width, initial-scale=1.0" ]
93- title_ " RSS Reader"
94- style_ [] (toHtmlRaw $ generateStyles faviconCss maybeFontBase64))
95- body_ (do
96- h1_ (toHtml pageTitle)
97- ul_ (do
98- mapM_ renderEntry entries
99- li_ (a_ [href_ " all.html" ] " See all" ))))
90+ let css = generateStyles maybeFontBase64 <> faviconCss
91+ in TL. toStrict $
92+ renderText $
93+ doctype_
94+ <> html_
95+ ( do
96+ head_
97+ ( do
98+ meta_ [name_ " viewport" , content_ " width=device-width, initial-scale=1.0" ]
99+ title_ " RSS Reader"
100+ style_ [] (toHtmlRaw css)
101+ )
102+ body_
103+ ( do
104+ h1_ (toHtml pageTitle)
105+ ul_
106+ ( do
107+ mapM_ renderEntry entries
108+ li_ (a_ [href_ " all.html" ] " See all" )
109+ )
110+ )
111+ )
100112 where
101- generateStyles :: Text -> Maybe Text -> Text
102- generateStyles css maybeFontB64 =
113+ generateStyles :: Maybe Text -> Text
114+ generateStyles maybeFontB64 =
103115 let fontFace = case maybeFontB64 of
104116 Just fontBase64 ->
105117 " " " @font-face {
106- font-family: 'IBM Plex Sans ';
107- src: url(data:font/woff2;base64," " "
118+ font-family: 'A Very Nice Font ';
119+ src: url(data:font/woff2;base64," " "
108120 <> fontBase64
109121 <> " " " ) format('woff2');
110- font-weight: 400;
111- }" " "
112- Nothing ->
113- " " " @font-face {
114- font-family: 'IBM Plex Sans';
115- src: url('IBMPlexSans-Regular.woff2') format('woff2');
116- font-weight: 400;
117- }" " "
122+ font-weight: 400;
123+ }" " "
124+ Nothing -> " " -- we don't have font, so no style here
118125 in fontFace
119126 <> " " "
120- body {
121- font-family: 'IBM Plex Sans' , -apple-system, sans-serif;
122- max-width: 800px ;
123- margin: 0 auto ;
124- color: #333 ;
125- display: flex ;
126- flex-flow: column ;
127- align-content: center ;
128- }
129- h1 {
130- color: #2c3e50;
131- border-bottom: 2px solid #3498db ;
132- padding -bottom: 10px ;
133- }
134- ul {
135- list-style: none;
136- padding: 0 ;
137- margin-top : 0
138- }
139- li {
140- padding-left: 8px;
141- padding-bottom : 8px;
142- }
143- a {
144- color: #2980b9;
145- text-decoration: none ;
146- font-weight: 500 ;
147- }
148- a:hover {
149- text-decoration: underline;
150- }
151- .date {
152- color: #7f8c8d;
153- font-size: 0.6em ;
154- }
155- .source {
156- color: #95a5a6;
157- font-size: 0.8em ;
158- padding-left : 0.5em ;
159- }
160- " " "
161- <> css
127+ body {
128+ font-family: 'A Very Nice Font', Helvetica, Arial, system-ui , -apple-system, sans-serif;
129+ font-weigth: 400 ;
130+ max-width: 800px ;
131+ margin: 0 auto ;
132+ color: #333 ;
133+ display: flex ;
134+ flex-flow: column ;
135+ align-content: center;
136+ }
137+ h1 {
138+ color: #2c3e50 ;
139+ border -bottom: 2px solid #3498db ;
140+ padding-bottom: 10px;
141+ }
142+ ul {
143+ list-style: none ;
144+ padding : 0;
145+ margin-top: 0
146+ }
147+ li {
148+ padding-left : 8px;
149+ padding-bottom: 8px;
150+ }
151+ a {
152+ color: #2980b9 ;
153+ text-decoration: none ;
154+ font-weight: 500;
155+ }
156+ a:hover {
157+ text-decoration: underline;
158+ }
159+ .date {
160+ color: #7f8c8d ;
161+ font-size: 0.6em;
162+ }
163+ .source {
164+ color: #95a5a6 ;
165+ font-size : 0.8em ;
166+ padding-left: 0.5em;
167+ }
168+ " " "
162169
163170 renderEntry :: FeedEntry -> Html ()
164171 renderEntry entry =
165- li_ (do
166- div_ (do
167- a_
168- [ href_ (T. pack $ show $ entryLink entry),
169- class_ (generateDomainCssClass (extractDomain entry. entrySiteUrl))
170- ]
171- (toHtml $ entryTitle entry)
172- span_ [class_ " source" ] (toHtml $ " (" <> extractDomain entry. entrySiteUrl <> " )" ))
173- div_ [class_ " date" ] (toHtml $ T. pack $ formatTime defaultTimeLocale " %Y-%m-%d" entry. entryDate))
172+ li_
173+ ( do
174+ div_
175+ ( do
176+ a_
177+ [ href_ (T. pack $ show $ entryLink entry),
178+ class_ (generateDomainCssClass (extractDomain entry. entrySiteUrl))
179+ ]
180+ (toHtml $ entryTitle entry)
181+ span_ [class_ " source" ] (toHtml $ " (" <> extractDomain entry. entrySiteUrl <> " )" )
182+ )
183+ div_ [class_ " date" ] (toHtml $ T. pack $ formatTime defaultTimeLocale " %Y-%m-%d" entry. entryDate)
184+ )
0 commit comments