Kaushal Modi 8 years ago
parent 0ef84a2c4b
commit bdc20fb5bc
  1. 47
      ox-hugo.el
  2. 12
      test/site/content-org/suppress-lastmod-period-non-zero.org
  3. 14
      test/site/content/posts/suppress-lastmod-non-zero-but-date-unset.md

@ -1365,35 +1365,36 @@ cannot be formatted in Hugo-compatible format."
(org-hugo--plist-get-true-p info :hugo-auto-set-lastmod)) (org-hugo--plist-get-true-p info :hugo-auto-set-lastmod))
(let* ((curr-time (org-current-time)) (let* ((curr-time (org-current-time))
(lastmod-str (format-time-string date-fmt curr-time))) (lastmod-str (format-time-string date-fmt curr-time)))
;; (message "[ox-hugo suppress-lastmod] current-time = %S (decoded = %S)"
;; curr-time (decode-time curr-time))
;; (message "[ox-hugo suppress-lastmod] lastmod-str = %S"
;; lastmod-str )
(if (= 0.0 org-hugo-suppress-lastmod-period) (if (= 0.0 org-hugo-suppress-lastmod-period)
(progn (progn
;; (message "[ox-hugo suppress-lastmod] not suppressed") ;; (message "[ox-hugo suppress-lastmod] not suppressed")
lastmod-str) lastmod-str)
(let* ((suppress-period (if (< 0.0 org-hugo-suppress-lastmod-period) (let ((date-str (org-string-nw-p (org-hugo--get-date info date-fmt))))
org-hugo-suppress-lastmod-period
(- org-hugo-suppress-lastmod-period)))
(date-str (org-hugo--get-date info date-fmt))
(date-time (apply #'encode-time
(mapcar (lambda (el) (or el 0))
(parse-time-string date-str))))
;; It's safe to assume that
;; `current-time' will always be
;; >= the post date.
(delta (float-time
(time-subtract curr-time date-time))))
;; (message "[ox-hugo suppress-lastmod] current-time = %S (decoded = %S)"
;; curr-time (decode-time curr-time))
;; (message "[ox-hugo suppress-lastmod] lastmod-str = %S"
;; lastmod-str )
;; (message "[ox-hugo suppress-lastmod] date-str = %S" ;; (message "[ox-hugo suppress-lastmod] date-str = %S"
;; date-str) ;; date-str)
;; (message "[ox-hugo suppress-lastmod] date-time = %S (decoded = %S)" (when date-str
;; date-time (decode-time date-time)) (let* ((date-time (apply #'encode-time
;; (message "[ox-hugo suppress-lastmod] suppress-period = %S" (mapcar (lambda (el) (or el 0))
;; suppress-period) (parse-time-string date-str))))
;; (message "[ox-hugo suppress-lastmod] delta = %S" delta) ;; It's safe to assume that
(when (>= delta suppress-period) ;; `current-time' will always
lastmod-str))))) ;; be >= the post date.
(delta (float-time
(time-subtract curr-time date-time)))
(suppress-period (if (< 0.0 org-hugo-suppress-lastmod-period)
org-hugo-suppress-lastmod-period
(- org-hugo-suppress-lastmod-period))))
;; (message "[ox-hugo suppress-lastmod] date-time = %S (decoded = %S)"
;; date-time (decode-time date-time))
;; (message "[ox-hugo suppress-lastmod] delta = %S" delta)
;; (message "[ox-hugo suppress-lastmod] suppress-period = %S"
;; suppress-period)
(when (>= delta suppress-period)
lastmod-str)))))))
;; Else.. do nothing. ;; Else.. do nothing.
(t (t
nil))) nil)))

@ -31,6 +31,18 @@ days) in Local Variables.
The export date is set to be the same as the "current date" (so the The export date is set to be the same as the "current date" (so the
delta is 0). delta is 0).
** Suppress lastmod non-zero, but date unset :date:unset:
:PROPERTIES:
:EXPORT_FILE_NAME: suppress-lastmod-non-zero-but-date-unset
:END:
#+begin_description
Ensure that nil value of parsed DATE is also handled in the "suppress
lastmod" logic.
#+end_description
Test for the bug-fix when ~date-str~ (internal variable) could be
/nil/.
[[https://github.com/kaushalmodi/ox-hugo/pull/197#issuecomment-421533876][Ref]]
** Unsuppress lastmod ** Unsuppress lastmod
:PROPERTIES: :PROPERTIES:
:EXPORT_DATE: 2100-12-10 :EXPORT_DATE: 2100-12-10

@ -0,0 +1,14 @@
+++
title = "Suppress lastmod non-zero, but date unset"
description = """
Ensure that nil value of parsed DATE is also handled in the "suppress
lastmod" logic.
"""
tags = ["suppress", "lastmod", "nonzero", "autoset", "date", "unset"]
draft = false
+++
Test for the bug-fix when `date-str` (internal variable) could be
_nil_.
[Ref](https://github.com/kaushalmodi/ox-hugo/pull/197#issuecomment-421533876)
Loading…
Cancel
Save