From 0807f42df47655476ec93351dacd25b5aaec0bac Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 26 Jan 2018 15:09:00 -0500 Subject: [PATCH] Derive publish/expiry-dates from SCHEDULED/DEADLINE time stamps This will work only for subtree-based exports as the SCHEDULED and DEADLINE properties can be added only to subtrees. --- doc/ox-hugo-manual.org | 64 ++++++++++--------- ox-hugo.el | 10 ++- test/site/content-org/all-posts.org | 20 ++++++ .../content/posts/expiry-date-deadline.md | 12 ++++ .../content/posts/publish-date-scheduled.md | 12 ++++ 5 files changed, 88 insertions(+), 30 deletions(-) create mode 100644 test/site/content/posts/expiry-date-deadline.md create mode 100644 test/site/content/posts/publish-date-scheduled.md diff --git a/doc/ox-hugo-manual.org b/doc/ox-hugo-manual.org index 00c09b64..c7728545 100644 --- a/doc/ox-hugo-manual.org +++ b/doc/ox-hugo-manual.org @@ -732,40 +732,46 @@ subtree* i.e. an Org subtree that has the =EXPORT_FILE_NAME= property set. #+CAPTION: Hugo front-matter translation for subtree-based exports #+ATTR_HTML: :class sane-table -|------------------------------------+------------------------------------+-------------------------------------------------------------------------| -| Hugo front-matter (TOML) | Org | Org description | -|------------------------------------+------------------------------------+-------------------------------------------------------------------------| -| =title = "foo"= | =* foo= | Subtree heading | -| =date = 2017-09-11T14:32:00-04:00= | =CLOSED: [2017-09-11 Mon 14:32]= | Auto-inserted =CLOSED= subtree property when switch to Org *DONE* state | -| =date = 2017-07-24= | =:EXPORT_DATE: 2017-07-24= | Subtree property | -| =lastmod = = | =:EXPORT_HUGO_AUTO_SET_LASTMOD: t= | Subtree property | -| =lastmod = = | =#+HUGO_AUTO_SET_LASTMOD: t= | Org keyword | -| =tags = ["toto", "zulu"]= | =* foo :toto:zulu:= | Subtree heading tags | -| =categories = ["x", "y"]= | =* foo :@x:@y:= | Subtree heading tags with =@= prefix | -| =draft = true= | =* TODO foo= | Subtree heading Org Todo state set to =TODO= (or =DRAFT=) | -| =draft = false= | =* foo= | Subtree heading Org Todo state *not* set to =TODO= (or =DRAFT=) | -| =weight = 123= | =:EXPORT_HUGO_WEIGHT: auto= | When set to =auto=, weight is auto-calculated | -| =weight = 123= (in =[menu.foo]=) | =:EXPORT_HUGO_MENU: :menu foo= | Menu weight is auto-calculated unless specified | -|------------------------------------+------------------------------------+-------------------------------------------------------------------------| +|-------------------------------------------+----------------------------------------+----------------------------------------------------------------------------| +| Hugo front-matter (TOML) | Org | Org description | +|-------------------------------------------+----------------------------------------+----------------------------------------------------------------------------| +| =title = "foo"= | =* foo= | Subtree heading | +| =date = 2017-09-11T14:32:00-04:00= | =CLOSED: [2017-09-11 Mon 14:32]= | Auto-inserted =CLOSED= subtree property when switch to Org *DONE* state | +| =date = 2017-07-24= | =:EXPORT_DATE: 2017-07-24= | Subtree property | +| =publishdate = 2018-01-26T00:00:00-05:00= | =SCHEDULED: <2018-01-26 Fri>= | Auto-inserted =SCHEDULED= subtree property using default =C-c C-s= binding | +| =publishdate = 2018-01-26T00:00:00-05:00= | =:EXPORT_HUGO_PUBLISHDATE: 2018-01-26:= | Subtree property | +| =expirydate = 2999-01-01T00:00:00-05:00= | =DEADLINE: <2999-01-01 Tue>= | Auto-inserted =DEADLINE= subtree property using default =C-c C-d= binding | +| =expirydate = 2999-01-01T00:00:00-05:00= | =:EXPORT_HUGO_EXPIRYDATE: 2999-01-01:= | Subtree property | +| =lastmod = = | =:EXPORT_HUGO_AUTO_SET_LASTMOD: t= | Subtree property | +| =lastmod = = | =#+HUGO_AUTO_SET_LASTMOD: t= | Org keyword | +| =tags = ["toto", "zulu"]= | =* foo :toto:zulu:= | Subtree heading tags | +| =categories = ["x", "y"]= | =* foo :@x:@y:= | Subtree heading tags with =@= prefix | +| =draft = true= | =* TODO foo= | Subtree heading Org Todo state set to =TODO= (or =DRAFT=) | +| =draft = false= | =* foo= | Subtree heading Org Todo state *not* set to =TODO= (or =DRAFT=) | +| =weight = 123= | =:EXPORT_HUGO_WEIGHT: auto= | When set to =auto=, weight is auto-calculated | +| =weight = 123= (in =[menu.foo]=) | =:EXPORT_HUGO_MENU: :menu foo= | Menu weight is auto-calculated unless specified | +|-------------------------------------------+----------------------------------------+----------------------------------------------------------------------------| ***** Notes - Precedence for =date= parsing: =CLOSED= subtree property /more than/ =EXPORT_DATE= subtree property /more than/ =#+DATE:= keyword. **** For file-based exports #+CAPTION: Hugo front-matter translation for file-based exports #+ATTR_HTML: :class sane-table -|----------------------------------+--------------------------------------| -| Hugo front-matter (TOML) | Org | -|----------------------------------+--------------------------------------| -| =title = "foo"= | =#+TITLE: foo= | -| =date = 2017-07-24= | =#+DATE: 2017-07-24= | -| =lastmod = = | =#+HUGO_AUTO_SET_LASTMOD: t= | -| =tags = ["toto", "zulu"]= | =#+HUGO_TAGS: toto zulu= | -| =categories = ["x", "y"]= | =#+HUGO_CATEGORIES: x y= | -| =draft = true= | =#+HUGO_DRAFT: true= | -| =draft = false= | =#+HUGO_DRAFT: false= (default) | -| =weight = 123= | =#+HUGO_WEIGHT: 123= | -| =weight = 123= (in =[menu.foo]=) | =#+HUGO_MENU: :menu foo :weight 123= | -|----------------------------------+--------------------------------------| +|-------------------------------------------+--------------------------------------| +| Hugo front-matter (TOML) | Org | +|-------------------------------------------+--------------------------------------| +| =title = "foo"= | =#+TITLE: foo= | +| =date = 2017-07-24= | =#+DATE: 2017-07-24= | +| =publishdate = 2018-01-26T00:00:00-05:00= | =#+HUGO_PUBLISHDATE: 2018-01-26= | +| =expirydate = 2999-01-01T00:00:00-05:00= | =#+HUGO_EXPIRYDATE: 2999-01-01= | +| =lastmod = = | =#+HUGO_AUTO_SET_LASTMOD: t= | +| =tags = ["toto", "zulu"]= | =#+HUGO_TAGS: toto zulu= | +| =categories = ["x", "y"]= | =#+HUGO_CATEGORIES: x y= | +| =draft = true= | =#+HUGO_DRAFT: true= | +| =draft = false= | =#+HUGO_DRAFT: false= (default) | +| =weight = 123= | =#+HUGO_WEIGHT: 123= | +| =weight = 123= (in =[menu.foo]=) | =#+HUGO_MENU: :menu foo :weight 123= | +|-------------------------------------------+--------------------------------------| ***** Notes - The auto weight calculation for posts and menu items works *only* for subtree exports. For the file-based export flow, one needs to @@ -1381,7 +1387,7 @@ See `org-capture-templates' for more information." Above capture will auto-insert a heading prefixed with =TODO=. With =org-log-done= set to ='time=, on changing the =TODO= state to the -=DONE= state (=C-c C-t=), a /Special Property/ called =CLOSED= will be +=DONE= state (=C-c C-t=), a [[https://orgmode.org/manual/Special-properties.html][/Special Property/]] called =CLOSED= will be auto-inserted below the heading. Below is an example. #+BEGIN_EXAMPLE ,*** DONE Narrowing the Author column in Magit :org:log: diff --git a/ox-hugo.el b/ox-hugo.el index 61ef1684..8ccdc3ef 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1086,13 +1086,21 @@ cannot be formatted in Hugo-compatible format." ;; headline to "DONE" state, (org-entry-get (point) "CLOSED") ;; Else get the date from the subtree property, - ;; `EXPORT_DATE' if available + ;; `EXPORT_DATE' if available, (org-string-nw-p (org-export-data (plist-get info date-key) info)) ;; Else try to get it from the #+DATE keyword in ;; the Org file. (org-string-nw-p (org-export-get-date info hugo-date-fmt)))) + ((and (equal date-key :hugo-publishdate) + ;; Get the date from the "SCHEDULED" property. + (org-entry-get (point) "SCHEDULED")) + (org-entry-get (point) "SCHEDULED")) + ((and (equal date-key :hugo-expirydate) + ;; Get the date from the "DEADLINE" property. + (org-entry-get (point) "DEADLINE")) + (org-entry-get (point) "DEADLINE")) (t ;:hugo-lastmod, :hugo-publishdate, :hugo-expirydate (org-string-nw-p (org-export-data (plist-get info date-key) info))))) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 66f15cfe..96c67a02 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -3363,6 +3363,16 @@ binding. :END: The =publishdate= for this post is Hugo-compatible i.e. [[https://tools.ietf.org/html/rfc3339#section-5.8][RFC3339-compliant]]. +*** Publish date set using SCHEDULED :scheduled: +SCHEDULED: <2018-01-26 Fri> +:PROPERTIES: +:EXPORT_FILE_NAME: publish-date-scheduled +:END: +If a subtree has the =SCHEDULED= [[https://orgmode.org/manual/Special-properties.html][Special Property]] set, set the +=publishdate= front-matter to the scheduled date. + +By default, =C-c C-s= in Org adds the =SCHEDULED= property to the +current subtree. ** Expiry Date :expirydate: *** Expiry date set using Org time stamp :PROPERTIES: @@ -3378,6 +3388,16 @@ binding. :END: The =expirydate= for this post is Hugo-compatible i.e. [[https://tools.ietf.org/html/rfc3339#section-5.8][RFC3339-compliant]]. +*** Expiry date set using DEADLINE :deadline: +DEADLINE: <2999-01-01 Tue> +:PROPERTIES: +:EXPORT_FILE_NAME: expiry-date-deadline +:END: +If a subtree has the =DEADLINE= [[https://orgmode.org/manual/Special-properties.html][Special Property]] set, set the +=expirydate= front-matter to the deadline date. + +By default, =C-c C-d= in Org adds the =DEADLINE= property to the +current subtree. * Preserve filling option :filling: ** Filling is preserved :PROPERTIES: diff --git a/test/site/content/posts/expiry-date-deadline.md b/test/site/content/posts/expiry-date-deadline.md new file mode 100644 index 00000000..16440df9 --- /dev/null +++ b/test/site/content/posts/expiry-date-deadline.md @@ -0,0 +1,12 @@ ++++ +title = "Expiry date set using DEADLINE" +expiryDate = 2999-01-01T00:00:00+00:00 +tags = ["dates", "expirydate", "deadline"] +draft = false ++++ + +If a subtree has the `DEADLINE` [Special Property](https://orgmode.org/manual/Special-properties.html) set, set the +`expirydate` front-matter to the deadline date. + +By default, `C-c C-d` in Org adds the `DEADLINE` property to the +current subtree. diff --git a/test/site/content/posts/publish-date-scheduled.md b/test/site/content/posts/publish-date-scheduled.md new file mode 100644 index 00000000..11683050 --- /dev/null +++ b/test/site/content/posts/publish-date-scheduled.md @@ -0,0 +1,12 @@ ++++ +title = "Publish date set using SCHEDULED" +publishDate = 2018-01-26T00:00:00+00:00 +tags = ["dates", "publishdate", "scheduled"] +draft = false ++++ + +If a subtree has the `SCHEDULED` [Special Property](https://orgmode.org/manual/Special-properties.html) set, set the +`publishdate` front-matter to the scheduled date. + +By default, `C-c C-s` in Org adds the `SCHEDULED` property to the +current subtree.