mirror of
https://github.com/srid/rib.git
synced 2024-11-30 03:45:00 +03:00
Rib.Simple: add isDraft
This commit is contained in:
parent
7605251218
commit
bad66f9588
@ -15,7 +15,7 @@ import Lucid
|
||||
import qualified Rib.App as App
|
||||
import Rib.Pandoc (getPandocMetaHTML, getPandocMetaValue, highlightingCss, pandoc2Html)
|
||||
import qualified Rib.Settings as S
|
||||
import Rib.Simple (Page (..), Post (..))
|
||||
import Rib.Simple (Page (..), Post (..), isDraft)
|
||||
import qualified Rib.Simple as Simple
|
||||
|
||||
data PostCategory
|
||||
@ -56,7 +56,9 @@ renderPage page = with html_ [lang_ "en"] $ do
|
||||
postList progPosts
|
||||
with h2_ [class_ "ui header"] "Other notes"
|
||||
postList otherPosts
|
||||
Page_Post post ->
|
||||
Page_Post post -> do
|
||||
when (isDraft post) $
|
||||
with div_ [class_ "ui warning message"] "This is a draft"
|
||||
with article_ [class_ "post"] $
|
||||
toHtmlRaw $ pandoc2Html $ _post_doc post
|
||||
with a_ [class_ "ui green right ribbon label", href_ "https://www.srid.ca"] "Sridhar Ratnakumar"
|
||||
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
title: "Nix tutorial for Haskellers"
|
||||
description: How to develop *Haskell* projects using *Nix*
|
||||
category: Programming
|
||||
category: 'Programming'
|
||||
---
|
||||
|
||||
The goal of this article is to get you comfortable managing simple Haskell
|
||||
|
27
example/content/inbox.md
Normal file
27
example/content/inbox.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
title: Random stuff I collect
|
||||
draft: 'True'
|
||||
description: This stuff is hidden if not private
|
||||
---
|
||||
|
||||
## Article ideas
|
||||
|
||||
- Github CI for OSS haskell projects
|
||||
- Lens and friends
|
||||
- mtl
|
||||
- string types
|
||||
- personal nix cache
|
||||
|
||||
## Project ideas
|
||||
|
||||
- [ ] Invoice generator
|
||||
|
||||
### Rib
|
||||
|
||||
- [ ] Drafts
|
||||
- [ ] Tasks
|
||||
- [ ] Simplify `Settings` (seems gobbled together)
|
||||
|
||||
#### Rib, for journaling
|
||||
|
||||
- [ ] Render Seinfeld diary view of good/bad/etc.
|
@ -2,7 +2,6 @@
|
||||
|
||||
module Rib.Pandoc where
|
||||
|
||||
import Control.Monad
|
||||
import Data.Maybe
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
@ -38,7 +37,9 @@ getPandocMetaRaw k p =
|
||||
|
||||
-- Like getPandocMetaRaw but expects the value to be of Haskell syntax
|
||||
getPandocMetaValue :: Read a => String -> Pandoc -> Maybe a
|
||||
getPandocMetaValue k = readMaybe <=< getPandocMetaRaw k
|
||||
getPandocMetaValue k doc = do
|
||||
s <- getPandocMetaRaw k doc
|
||||
pure $ fromMaybe (error $ "Invalid metadata value for key: " <> k) $ readMaybe s
|
||||
|
||||
-- | Get the YAML metadata, parsing it to Pandoc doc and then to HTML
|
||||
getPandocMetaHTML :: String -> Pandoc -> Maybe Text
|
||||
|
@ -8,8 +8,6 @@ import Development.Shake
|
||||
import Lucid (Html)
|
||||
|
||||
-- | Settings for building a static site.
|
||||
--
|
||||
-- TODO: When settings change it should invalidate Shake cache. How do we do it?
|
||||
data Settings page = Settings
|
||||
{ renderPage :: page -> Html ()
|
||||
-- ^ Lucid widget for the page
|
||||
|
@ -7,12 +7,14 @@
|
||||
module Rib.Simple
|
||||
( Page(..)
|
||||
, Post(..)
|
||||
, isDraft
|
||||
, simpleBuildRules
|
||||
, settings
|
||||
) where
|
||||
|
||||
import Control.Monad
|
||||
import Data.Aeson (FromJSON, ToJSON)
|
||||
import Data.Maybe
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics (Generic)
|
||||
@ -22,7 +24,7 @@ import Development.Shake.FilePath
|
||||
import Lucid
|
||||
import Text.Pandoc (Pandoc)
|
||||
|
||||
import Rib.Pandoc (parsePandoc)
|
||||
import Rib.Pandoc (getPandocMetaValue, parsePandoc)
|
||||
import Rib.Server (getHTMLFileUrl)
|
||||
import qualified Rib.Settings as S
|
||||
|
||||
@ -39,6 +41,9 @@ data Post = Post
|
||||
}
|
||||
deriving (Generic, Eq, Ord, Show, FromJSON, ToJSON)
|
||||
|
||||
isDraft :: Post -> Bool
|
||||
isDraft = fromMaybe False . getPandocMetaValue "draft" . _post_doc
|
||||
|
||||
-- Build rules for the simplest site possible.
|
||||
--
|
||||
-- Just posts and static files.
|
||||
@ -65,9 +70,10 @@ simpleBuildRules staticFilePatterns postFilePatterns S.Settings {..} = do
|
||||
pure post
|
||||
|
||||
-- Generate the main table of contents
|
||||
-- TODO: Support `draft` property
|
||||
liftIO $ renderToFile (destDir </> "index.html") $
|
||||
renderPage $ Page_Index posts
|
||||
let publicPosts = filter (not . isDraft) posts
|
||||
indexHtml = destDir </> "index.html"
|
||||
liftIO $ renderToFile indexHtml $
|
||||
renderPage $ Page_Index publicPosts
|
||||
|
||||
|
||||
settings :: S.Settings Page
|
||||
|
Loading…
Reference in New Issue
Block a user