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 9caa7a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions emanote/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Lua filters: filter paths will now be looked up in all layers now.
- Live server now uses Tailwind 3 ([\#503](https://github.com/srid/emanote/pull/503))
- Enable auto identifier for org files ([\#502](https://github.com/srid/emanote/pull/502))
- Support date metadata from the filename when it begins with YYYY-MM-DD ([\#552](https://github.com/srid/emanote/pull/552)).
- Bug fixes:
- Emanote no longer crashes when run on an empty directory ([\#487](https://github.com/srid/emanote/issues/487))
- Stork search fixes
Expand Down
18 changes: 17 additions & 1 deletion emanote/src/Emanote/Model/Note.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import Text.Pandoc.Scripting (ScriptingEngine)
import Text.Pandoc.Walk qualified as W
import UnliftIO.Directory (doesPathExist)

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

data Feed = Feed
{ _feedEnable :: Bool
, _feedTitle :: Maybe Text
Expand Down Expand Up @@ -316,7 +320,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.satisfy (not . isDigit)
pure $ T.pack $ mconcat [year, "-", month, "-", day]

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

0 comments on commit 9caa7a9

Please # to comment.