Allow disabling title exports or setting them to empty

.. because you can.

Now the org-export-with-title option is respected.
master
Kaushal Modi 8 years ago
parent f5803c683a
commit 52453d6273
  1. 10
      doc/ox-hugo-manual.org
  2. 28
      ox-hugo.el
  3. 16
      test/site/content-org/all-posts.org
  4. 15
      test/site/content-org/single-posts/allow-empty-titles-1.org
  5. 17
      test/site/content-org/single-posts/disable-title-1.org
  6. 6
      test/site/content/posts/allow-empty-titles-1.md
  7. 7
      test/site/content/posts/allow-empty-titles-2.md
  8. 6
      test/site/content/posts/disable-title-1.md
  9. 7
      test/site/content/posts/disable-title-2.md
  10. 1
      test/site/content/posts/post-title-quotes.md
  11. 1
      test/site/content/posts/under-scores-in-title.md

@ -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

@ -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)

@ -292,7 +292,7 @@ in Markdown.
Above title would render to ~Version 0.1 <span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>~ 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

@ -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:

@ -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:

@ -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:`.

@ -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:`.

@ -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`.

@ -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`.

@ -1,6 +1,7 @@
+++
title = "Awesome title with \"quoted text\""
date = 2017-07-24
tags = ["title"]
draft = false
+++

@ -1,6 +1,7 @@
+++
title = "Under_scores_in_title"
date = 2017-07-28
tags = ["title"]
draft = false
+++

Loading…
Cancel
Save