Support summary splitter

In Org:

    #+HUGO: more

converts to this in Markdown:

    <!--more-->

https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting
master
Kaushal Modi 9 years ago
parent 99ec1b1bbe
commit 8a0182f5bc
  1. 9
      example-site/content-org/all-posts.org
  2. 12
      example-site/content/posts/summary-splitter.md
  3. 47
      ox-hugo.el

@ -392,6 +392,15 @@ Here the front matter format is set to YAML using the
=HUGO_FRONT_MATTER_FORMAT= key in property drawer.
Here there is white space in menu name property.
* Post body
** Summary Splitter
:PROPERTIES:
:EXPORT_FILE_NAME: summary-splitter
:EXPORT_DATE: 2017-07-21
:END:
Here is the summary.
#+HUGO: more
Here is text after the [[https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting][summary splitter]].
* TODO Pre-Draft State
:PROPERTIES:
:EXPORT_FILE_NAME: draft-state-todo

@ -0,0 +1,12 @@
+++
title = "Summary Splitter"
date = 2017-07-21
tags = []
draft = false
+++
Here is the summary.
<!--more-->
Here is text after the [summary splitter](https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting).

@ -107,8 +107,9 @@ directory where all Hugo posts should go by default."
(lambda (a s v _b)
(org-hugo-export-as-md a s v)))))
:translate-alist '((headline . org-hugo-headline)
(src-block . org-hugo-src-block)
(link . org-hugo-link))
(keyword . org-hugo-keyword)
(link . org-hugo-link)
(src-block . org-hugo-src-block))
:filters-alist '((:filter-body . org-hugo-body-filter))
;; KEY KEYWORD OPTION DEFAULT BEHAVIOR
@ -286,19 +287,21 @@ section as a string."
(let ((level-mark (make-string (+ loffset level) ?#)))
(concat "\n" level-mark " " title " " anchor "\n\n"))))
;;;; Source Blocks
(defun org-hugo-src-block (src-block _contents info)
"Convert SRC-BLOCK element to Hugo-compatible element.
If the HUGO_CODE_FENCE property is set to t (default), the
Markdown style triple-backquoted code blocks are created.
Otherwise, the code block is wrapped in Hugo `highlight'
shortcode."
(if (string= "t" (org-export-data (plist-get info :hugo-code-fence) info))
(org-blackfriday-src-block src-block nil info)
(let* ((lang (org-element-property :language src-block))
(code (org-export-format-code-default src-block info)))
(format "{{< highlight %s>}}\n%s{{< /highlight >}}\n" lang code))))
;;;; Keyword
(defun org-hugo-keyword (keyword contents info)
"Transcode a KEYWORD element into Hugo-compatible Markdown format.
CONTENTS is nil. INFO is a plist used as a communication
channel."
(let ((kwd (org-element-property :key keyword))
(value (org-element-property :value keyword)))
(cond
((and (equal "HUGO" kwd) ;Hugo summary splitting
(stringp value)
(string-match-p "\\`\\s-*more\\s-*\\'" value))
;; https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting
"<!--more-->")
(t
(org-md-keyword keyword contents info)))))
;;;; Links
(defun org-hugo-link (link contents info)
@ -436,6 +439,20 @@ INFO is a plist used as a communication channel."
(concat "/" (file-name-as-directory (plist-get info :hugo-static-images)) file-name))
path)))
;;;; Source Blocks
(defun org-hugo-src-block (src-block _contents info)
"Convert SRC-BLOCK element to Hugo-compatible element.
If the HUGO_CODE_FENCE property is set to t (default), the
Markdown style triple-backquoted code blocks are created.
Otherwise, the code block is wrapped in Hugo `highlight'
shortcode."
(if (string= "t" (org-export-data (plist-get info :hugo-code-fence) info))
(org-blackfriday-src-block src-block nil info)
(let* ((lang (org-element-property :language src-block))
(code (org-export-format-code-default src-block info)))
(format "{{< highlight %s>}}\n%s{{< /highlight >}}\n" lang code))))
;;; Filter Functions

Loading…
Cancel
Save