Skip to content

Commit

Permalink
Support summary splitter
Browse files Browse the repository at this point in the history
In Org:

    #+HUGO: more

converts to this in Markdown:

    <!--more-->

https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting
  • Loading branch information
kaushalmodi committed Jul 21, 2017
1 parent 99ec1b1 commit 8a0182f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
9 changes: 9 additions & 0 deletions example-site/content-org/all-posts.org
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions example-site/content/posts/summary-splitter.md
@@ -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).
47 changes: 32 additions & 15 deletions ox-hugo.el
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8a0182f

Please sign in to comment.