Turned the main page definition into a markdown file.
authorsabadev <saba@sabadev.xyz>
Wed, 17 Mar 2021 19:16:58 +0000 (15:16 -0400)
committersabadev <dev@sabadev.xyz>
Tue, 13 Apr 2021 01:16:25 +0000 (21:16 -0400)
src/Server.hs

index bc53f56..30a52bd 100644 (file)
@@ -22,11 +22,9 @@ apiProxy = Proxy
 
 type Api = Page :<|> Themes
 type Page = MainPage :<|> BlogPost
--- TODO Turn MainPage into another BlogPost, and instead have some index.md file that I can look for.
--- Perhaps have a config.json file to specify the index.md file and the static directory location.
 type MainPage = ThemeParam :> Get '[HTML] (Html ())
-type BlogPost = "blog" :> ThemeParam :> Capture "id" BlogId :> Get '[HTML] (Html ())
-type Themes = DarkTheme :<|> LightTheme
+type BlogPost = ThemeParam :> Capture "id" BlogId :> Get '[HTML] (Html ())
+type Themes = "style" :> (DarkTheme :<|> LightTheme)
 type DarkTheme = "dark" :> Get '[CSS] C.Css
 type LightTheme = "light" :> Get '[CSS] C.Css
 type ThemeParam = QueryParam "light" Bool
@@ -42,7 +40,7 @@ page :: Server Page
 page = mainPage :<|> blogPost
 
 mainPage :: UseLightTheme -> Handler (Html ())
-mainPage useLight = htmlContainer useLight $ h1_ $ toHtml siteTitle
+mainPage = flip blogPost "index"
 
 blogPost :: UseLightTheme -> BlogId -> Handler (Html ())
 blogPost useLight = htmlContainer useLight . renderBlog <=< findBlogPost
@@ -90,7 +88,7 @@ makeLink :: UseLightTheme -> T.Text -> T.Text
 makeLink useLight link = let lightThemeOn = useLightTheme useLight in if lightThemeOn then link <> "?light=true" else link <> "?light=false"
 
 blogLink :: T.Text -> Maybe T.Text
-blogLink = pure . (<>) "/blog/" <=< T.stripSuffix markdownExtension
+blogLink = T.stripSuffix markdownExtension
 
 siteTitle :: T.Text
 siteTitle = "My Site"
@@ -105,4 +103,4 @@ useLightTheme :: UseLightTheme -> Bool
 useLightTheme = fromMaybe False
 
 getTheme :: UseLightTheme -> T.Text
-getTheme theme = let lightThemeOn = useLightTheme theme in if lightThemeOn then "/light" else "/dark"
+getTheme theme = let lightThemeOn = useLightTheme theme in if lightThemeOn then "/style/light" else "/style/dark"