diff --git a/docs/guide/yaml-config.md b/docs/guide/yaml-config.md index 5695c1cb5..8bb06024e 100644 --- a/docs/guide/yaml-config.md +++ b/docs/guide/yaml-config.md @@ -21,6 +21,9 @@ Notice how this page's sidebar colorscheme has [changed to green]{.greenery}? Vi - `page.image`: The image to use for the page. This is used for the [[ogp]] meta tag `og:image` meta tag. If not specified, the first image in the page is used. Relative URLs are automatically rewritten to absolute URLs if `page.siteUrl` is non-empty. +- `date`: The note timestamp. This is used to order note chronologically, such as for the timeline [[query|query]]. + The value can be set from the filename if it begins with `YYYY-MM-DD`, which is useful for including the date in the note URL. + In case of conflict, the date from the YAML configuration takes priority. ## Examples diff --git a/emanote/CHANGELOG.md b/emanote/CHANGELOG.md index afeb51c3f..951f49bc4 100644 --- a/emanote/CHANGELOG.md +++ b/emanote/CHANGELOG.md @@ -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 diff --git a/emanote/emanote.cabal b/emanote/emanote.cabal index c3c68929c..6f3b8cd9a 100644 --- a/emanote/emanote.cabal +++ b/emanote/emanote.cabal @@ -1,6 +1,6 @@ cabal-version: 2.4 name: emanote -version: 1.3.17.1 +version: 1.3.18.0 license: AGPL-3.0-only copyright: 2022 Sridhar Ratnakumar maintainer: srid@srid.ca diff --git a/emanote/src/Emanote/Model/Note.hs b/emanote/src/Emanote/Model/Note.hs index 3c81c6648..ebdcd7f39 100644 --- a/emanote/src/Emanote/Model/Note.hs +++ b/emanote/src/Emanote/Model/Note.hs @@ -10,6 +10,7 @@ import Control.Monad.Logger (MonadLogger) import Control.Monad.Writer (MonadWriter (tell), WriterT, runWriterT) import Data.Aeson qualified as Aeson import Data.Aeson.Optics qualified as AO +import Data.Char (isDigit) import Data.Default (Default (def)) import Data.IxSet.Typed (Indexable (..), IxSet, ixFun, ixList) import Data.IxSet.Typed qualified as Ix @@ -29,7 +30,7 @@ import Network.URI.Slug (Slug) import Optics.Core ((%), (.~)) import Optics.TH (makeLenses) import Relude -import System.FilePath (()) +import System.FilePath (takeFileName, ()) import Text.Pandoc (readerExtensions, runPure) import Text.Pandoc.Builder qualified as B import Text.Pandoc.Definition (Pandoc (..)) @@ -37,6 +38,7 @@ import Text.Pandoc.Extensions import Text.Pandoc.Readers.Org (readOrg) import Text.Pandoc.Scripting (ScriptingEngine) import Text.Pandoc.Walk qualified as W +import Text.Parsec qualified as P import UnliftIO.Directory (doesPathExist) data Feed = Feed @@ -316,7 +318,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 $ toText $ mconcat [year, "-", month, "-", day] parseNoteOrg :: (MonadWriter [Text] m) => Text -> m (Pandoc, Aeson.Value) parseNoteOrg s =