From 52453d62730c7e0842aa61f95118f55dda70718b Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 1 Dec 2017 14:44:19 -0500 Subject: [PATCH] Allow disabling title exports or setting them to empty .. because you can. Now the org-export-with-title option is respected. --- doc/ox-hugo-manual.org | 10 +++---- ox-hugo.el | 28 +++++++++++-------- test/site/content-org/all-posts.org | 16 ++++++++++- .../single-posts/allow-empty-titles-1.org | 15 ++++++++++ .../single-posts/disable-title-1.org | 17 +++++++++++ .../content/posts/allow-empty-titles-1.md | 6 ++++ .../content/posts/allow-empty-titles-2.md | 7 +++++ test/site/content/posts/disable-title-1.md | 6 ++++ test/site/content/posts/disable-title-2.md | 7 +++++ test/site/content/posts/post-title-quotes.md | 1 + .../content/posts/under-scores-in-title.md | 1 + 11 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 test/site/content-org/single-posts/allow-empty-titles-1.org create mode 100644 test/site/content-org/single-posts/disable-title-1.org create mode 100644 test/site/content/posts/allow-empty-titles-1.md create mode 100644 test/site/content/posts/allow-empty-titles-2.md create mode 100644 test/site/content/posts/disable-title-1.md create mode 100644 test/site/content/posts/disable-title-2.md diff --git a/doc/ox-hugo-manual.org b/doc/ox-hugo-manual.org index d177a0f..f7a238f 100644 --- a/doc/ox-hugo-manual.org +++ b/doc/ox-hugo-manual.org @@ -323,15 +323,15 @@ The common =ox-hugo= export bindings are: A /valid Hugo post subtree/ is an Org subtree has the =EXPORT_FILE_NAME= property set. - - If the file is intended to be exported as a whole i.e. it must have - the #+TITLE keyword set, export the whole Org file a Hugo post in - Markdown. + - If the file is intended to be exported as a whole i.e. it must + have the =#+TITLE= keyword set, export the whole Org file a Hugo + post in Markdown. - =C-c C-e H A= :: Export *all* "What I Mean" - If the Org file has one or more 'valid Hugo post subtrees', export them to Hugo posts in Markdown. - If the file is intended to be exported as a whole (no 'valid Hugo - post subtrees' at all) i.e. it must have the #+TITLE keyword set, - export the whole Org file a Hugo post in Markdown. + post subtrees' at all) i.e. it must have the =#+TITLE= keyword + set, export the whole Org file a Hugo post in Markdown. **** For only the one-post-per-file flow - =C-c C-e H h= :: Export the Org file to a Hugo post in Markdown. *** Customization Options diff --git a/ox-hugo.el b/ox-hugo.el index 1bbfdf6..c6db697 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1671,15 +1671,20 @@ to ((name . \"foo\") (weight . 80))." - Remove bold, italics, monospace Markdown markup characters. - Do not escape underscore characters in the title. +If exporting title is disabled by setting `org-export-with-title' +to nil or using the OPTIONS keyword e.g. \"title:nil\", return +nil. + INFO is a plist used as a communication channel." - (let* ((title (org-export-data (plist-get info :title) info)) - ;; Sanitize title.. cannot do bold, italics, monospace in title - (title (replace-regexp-in-string "\\\\?`" "" title)) - (title (replace-regexp-in-string "\\`__?\\|\\`\\*\\*?\\|__?\\'\\|\\*\\*?\\'" "" title)) - (title (replace-regexp-in-string " __?\\|__? \\| \\*\\*?\\|\\*\\*? " " " title)) - ;; Do not escape underscores in title - (title (replace-regexp-in-string "\\\\_" "_" title))) - title)) + (when (plist-get info :with-title) + (let* ((title (org-export-data (plist-get info :title) info)) + ;; Sanitize title.. cannot do bold, italics, monospace in title + (title (replace-regexp-in-string "\\\\?`" "" title)) + (title (replace-regexp-in-string "\\`__?\\|\\`\\*\\*?\\|__?\\'\\|\\*\\*?\\'" "" title)) + (title (replace-regexp-in-string " __?\\|__? \\| \\*\\*?\\|\\*\\*? " " " title)) + ;; Do not escape underscores in title + (title (replace-regexp-in-string "\\\\_" "_" title))) + title))) (defun org-hugo--transform-org-tags (tag-list info &optional no-prefer-hyphen) "Transform Org TAG-LIST for use in Hugo tags and categories. @@ -2484,13 +2489,14 @@ approach)." err msg) (if valid-subtree-found (setq msg "Point is not in a valid Hugo post subtree; move to one and try again") - (let* ((info (org-export-get-environment 'hugo)) - (title (car (plist-get info :title)))) + (let ((title (save-excursion + (goto-char (point-min)) + (re-search-forward "^#\\+TITLE:" nil :noerror)))) (if title (setq do-export t) (setq err t) (setq msg (concat "The file neither contains a valid Hugo post subtree, " - "nor has the #+TITLE keyword set"))))) + "nor has the #+TITLE keyword"))))) (unless do-export (let ((error-fn (if (or (not err) noerror) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index a34a1be..9c53367 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -292,7 +292,7 @@ in Markdown. Above title would render to ~Version 0.1 <2017-10-11 Wed>~ in Markdown. -* Title in Front Matter +* Title in Front Matter :title: ** Awesome title with "quoted text" :PROPERTIES: :EXPORT_FILE_NAME: post-title-quotes @@ -306,6 +306,20 @@ Testing a post with double quotes in the title. :END: Ensure that the underscores in =title= string of front matter do not get escaped.. =foo_bar= must not become =foo\_bar=. +** Allow empty titles :empty: +:PROPERTIES: +:EXPORT_FILE_NAME: allow-empty-titles-2 +:EXPORT_TITLE: +:END: +This post will be exported without =title= in the front-matter because +it is explicitly set to /empty/ using =:EXPORT_TITLE:=. +** Disable exporting title :disable: +:PROPERTIES: +:EXPORT_OPTIONS: title:nil +:EXPORT_FILE_NAME: disable-title-2 +:END: +This post will be exported without =title= in the front-matter because +it is disabled using =:EXPORT_OPTIONS: title:nil=. * Description meta-data with "quoted text" :PROPERTIES: :EXPORT_FILE_NAME: post-description-quotes diff --git a/test/site/content-org/single-posts/allow-empty-titles-1.org b/test/site/content-org/single-posts/allow-empty-titles-1.org new file mode 100644 index 0000000..b753920 --- /dev/null +++ b/test/site/content-org/single-posts/allow-empty-titles-1.org @@ -0,0 +1,15 @@ +#+HUGO_BASE_DIR: ../../ + +#+TITLE: +#+FILETAGS: empty title + +This post will be exported without =title= in the front-matter because +it is explicitly set to /empty/ using =#+TITLE:=. + +* Footnotes +* COMMENT Local Variables :ARCHIVE: +# Local Variables: +# fill-column: 70 +# eval: (auto-fill-mode 1) +# eval: (add-hook 'after-save-hook #'org-hugo-export-wim-to-md-after-save :append :local) +# End: diff --git a/test/site/content-org/single-posts/disable-title-1.org b/test/site/content-org/single-posts/disable-title-1.org new file mode 100644 index 0000000..7522ca2 --- /dev/null +++ b/test/site/content-org/single-posts/disable-title-1.org @@ -0,0 +1,17 @@ +#+HUGO_BASE_DIR: ../../ + +#+TITLE: Disable exporting title +#+OPTIONS: title:nil + +#+FILETAGS: disable title + +This post will be exported without =title= in the front-matter because +it is disabled using =#+OPTIONS: title:nil=. + +* Footnotes +* COMMENT Local Variables :ARCHIVE: +# Local Variables: +# fill-column: 70 +# eval: (auto-fill-mode 1) +# eval: (add-hook 'after-save-hook #'org-hugo-export-wim-to-md-after-save :append :local) +# End: diff --git a/test/site/content/posts/allow-empty-titles-1.md b/test/site/content/posts/allow-empty-titles-1.md new file mode 100644 index 0000000..99e9ee3 --- /dev/null +++ b/test/site/content/posts/allow-empty-titles-1.md @@ -0,0 +1,6 @@ ++++ +draft = false ++++ + +This post will be exported without `title` in the front-matter because +it is explicitly set to _empty_ using `#+TITLE:`. diff --git a/test/site/content/posts/allow-empty-titles-2.md b/test/site/content/posts/allow-empty-titles-2.md new file mode 100644 index 0000000..7e9ba94 --- /dev/null +++ b/test/site/content/posts/allow-empty-titles-2.md @@ -0,0 +1,7 @@ ++++ +tags = ["title", "empty"] +draft = false ++++ + +This post will be exported without `title` in the front-matter because +it is explicitly set to _empty_ using `:EXPORT_TITLE:`. diff --git a/test/site/content/posts/disable-title-1.md b/test/site/content/posts/disable-title-1.md new file mode 100644 index 0000000..a668028 --- /dev/null +++ b/test/site/content/posts/disable-title-1.md @@ -0,0 +1,6 @@ ++++ +draft = false ++++ + +This post will be exported without `title` in the front-matter because +it is disabled using `#+OPTIONS: title:nil`. diff --git a/test/site/content/posts/disable-title-2.md b/test/site/content/posts/disable-title-2.md new file mode 100644 index 0000000..f6aa990 --- /dev/null +++ b/test/site/content/posts/disable-title-2.md @@ -0,0 +1,7 @@ ++++ +tags = ["title", "disable"] +draft = false ++++ + +This post will be exported without `title` in the front-matter because +it is disabled using `:EXPORT_OPTIONS: title:nil`. diff --git a/test/site/content/posts/post-title-quotes.md b/test/site/content/posts/post-title-quotes.md index 59cc689..a63dd34 100644 --- a/test/site/content/posts/post-title-quotes.md +++ b/test/site/content/posts/post-title-quotes.md @@ -1,6 +1,7 @@ +++ title = "Awesome title with \"quoted text\"" date = 2017-07-24 +tags = ["title"] draft = false +++ diff --git a/test/site/content/posts/under-scores-in-title.md b/test/site/content/posts/under-scores-in-title.md index 7267612..e53b16d 100644 --- a/test/site/content/posts/under-scores-in-title.md +++ b/test/site/content/posts/under-scores-in-title.md @@ -1,6 +1,7 @@ +++ title = "Under_scores_in_title" date = 2017-07-28 +tags = ["title"] draft = false +++