Skip to content

Commit

Permalink
Set note time when the path begin with a timestamp
Browse files Browse the repository at this point in the history
This change simplifies timeline creation by setting the date metadata
from the filename when it begins with `YYYY-MM-DD-`.
  • Loading branch information
TristanCacqueray committed Sep 30, 2024
1 parent 40607a2 commit f62b727
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion emanote/src/Emanote/Model/Note.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import Text.Pandoc.Scripting (ScriptingEngine)
import Text.Pandoc.Walk qualified as W
import UnliftIO.Directory (doesPathExist)

import System.FilePath (takeFileName)
import Text.Parsec qualified as P

data Feed = Feed
{ _feedEnable :: Bool
, _feedTitle :: Maybe Text
Expand Down Expand Up @@ -316,7 +319,19 @@ parseNote scriptingEngine pluginBaseDir r src@(_, fp) s = do
parseNoteMarkdown scriptingEngine pluginBaseDir fp s
R.LMLRoute_Org _ -> do
parseNoteOrg s
pure $ mkNoteWith r (Just src) doc meta errs
let metaWithDateFromPath = case P.parse dateParser mempty (takeFileName fp) of
Left _ -> meta
Right date -> SData.modifyAeson (pure "date") (Just . fromMaybe (Aeson.String date)) meta
pure $ mkNoteWith r (Just src) doc metaWithDateFromPath errs
where
dateParser = do
year <- replicateM 4 P.digit
_ <- P.char '-'
month <- replicateM 2 P.digit
_ <- P.char '-'
day <- replicateM 2 P.digit
_ <- P.char '-'
pure $ T.pack $ mconcat [year, "-", month, "-", day]

parseNoteOrg :: (MonadWriter [Text] m) => Text -> m (Pandoc, Aeson.Value)
parseNoteOrg s =
Expand Down

0 comments on commit f62b727

Please sign in to comment.