Skip to content

Commit

Permalink
Ensure that the title front-matter value is always double-quoted
Browse files Browse the repository at this point in the history
Fixes #350 .
  • Loading branch information
kaushalmodi committed Apr 20, 2020
1 parent bbb848f commit 7800cbc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,7 @@ to ((name . \"foo\") (weight . 80))."
valid-menu-alist))

(defun org-hugo--get-sanitized-title (info)
"Return sanitized version of an Org headline TITLE.
"Return sanitized version of an Org headline TITLE as a string.
INFO is a plist used as a communication channel.
Expand All @@ -3064,7 +3064,10 @@ If the extracted document title is nil, and exporting the title
is disabled, return nil.
If the extracted document title is non-nil, return it after
removing all markup characters."
removing all markup characters.
Also double-quote the title if it doesn't already contain any
double-quotes."
(let ((title (when (plist-get info :with-title)
(plist-get info :title))))
(when title
Expand Down Expand Up @@ -3092,7 +3095,14 @@ removing all markup characters."
(setq title (replace-regexp-in-string "---\\([^-]\\)" "\\1" title)) ;EM DASH
(setq title (replace-regexp-in-string "--\\([^-]\\)" "\\1" title)) ;EN DASH

(setq title (replace-regexp-in-string "\\.\\.\\." "" title)))) ;HORIZONTAL ELLIPSIS
(setq title (replace-regexp-in-string "\\.\\.\\." "" title)) ;HORIZONTAL ELLIPSIS

;; Double-quote the title so that even if the title contains
;; just numbers or a date, it still gets rendered as a string
;; type in Hugo. Do this only if the title doesn't already
;; contain double-quotes.
(unless (string-match "\"" title)
(setq title (format "\"%s\"" title)))))
title))

(defun org-hugo--replace-underscores-with-spaces (str)
Expand Down
9 changes: 9 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,15 @@ happen in post titles ({{{hugoissue(4175)}}}).
:END:
- All the Org markup characters are removed.
- The "markup characters" not doing actual markup are retained.
** 2020-04-19
:PROPERTIES:
:EXPORT_FILE_NAME: title-with-just-date-chars
:END:
#+begin_description
Test the case where the title contains only the date, making it look
like a Hugo TOML date field.
#+end_description
{{{oxhugoissue(350)}}}
* Excluded post :noexport:
:PROPERTIES:
:EXPORT_FILE_NAME: excluded-post
Expand Down
11 changes: 11 additions & 0 deletions test/site/content/posts/title-with-just-date-chars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
+++
title = "2020-04-19"
description = """
Test the case where the title contains only the date, making it look
like a Hugo TOML date field.
"""
tags = ["title"]
draft = false
+++

`ox-hugo` Issue #[350](https://github.com/kaushalmodi/ox-hugo/issues/350)

0 comments on commit 7800cbc

Please sign in to comment.