diff --git a/example-site/content-org/all-posts.org b/example-site/content-org/all-posts.org index 32068c6..3672025 100644 --- a/example-site/content-org/all-posts.org +++ b/example-site/content-org/all-posts.org @@ -242,7 +242,7 @@ ORG_ADD_CONTRIB = org-eldoc ox-extra org-mime :PROPERTIES: :EXPORT_FILE_NAME: menu-alist-meta-data-toml :EXPORT_DATE: 2017-07-18 -:EXPORT_HUGO_MENU: :name main :weight 80 :parent posts :identifier foo1 +:EXPORT_HUGO_MENU: :menu "something here" :weight 80 :parent posts :identifier foo1 :END: Testing the addition of /menu/ alist meta data to the TOML front matter. @@ -265,20 +265,36 @@ Rename or set an unique identifier. :PROPERTIES: :EXPORT_FILE_NAME: menu-alist-meta-data-toml-override-full :EXPORT_DATE: 2017-07-18 -:EXPORT_HUGO_MENU: :name test :weight 50 +:EXPORT_HUGO_MENU: :menu test :weight 50 :END: For this post, we see that no menu properties are inherited from the parent; only the menu properties set in his subtree are effective. ** Menu Meta Data in YAML Front Matter :yaml: :PROPERTIES: :EXPORT_HUGO_FRONT_MATTER_FORMAT: yaml +:END: +*** White space in menu entry +:PROPERTIES: :EXPORT_FILE_NAME: menu-meta-data-yaml2 -:EXPORT_DATE: 2017-07-18 -:EXPORT_HUGO_MENU: :name main :weight 25 :parent posts :identifier menu-yaml +:EXPORT_DATE: 2017-07-19 +:EXPORT_HUGO_MENU: :menu "something here" :weight 25 +:END: +Testing the addition of /menu/ meta data to the YAML front matter. +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 entry keyword. +*** White space in menu name +:PROPERTIES: +:EXPORT_FILE_NAME: menu-meta-data-yaml3 +:EXPORT_DATE: 2017-07-19 +:EXPORT_HUGO_MENU: :menu main :weight 25 :parent posts :name "Menu in YAML" :END: Testing the addition of /menu/ meta data to the YAML front matter. 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. * TODO Pre-Draft State :PROPERTIES: :EXPORT_FILE_NAME: draft-state-todo diff --git a/example-site/content-org/construct-hugo-front-matter-from-menu-meta-data.org b/example-site/content-org/construct-hugo-front-matter-from-menu-meta-data.org index ce91b67..ce261fa 100644 --- a/example-site/content-org/construct-hugo-front-matter-from-menu-meta-data.org +++ b/example-site/content-org/construct-hugo-front-matter-from-menu-meta-data.org @@ -1,6 +1,6 @@ #+HUGO_BASE_DIR: ../ #+HUGO_FRONT_MATTER_FORMAT: yaml -#+HUGO_MENU: :name main :parent posts +#+HUGO_MENU: :menu main :parent posts * Menu Meta Data in YAML Front Matter :menu:yaml: :PROPERTIES: diff --git a/example-site/content/posts/menu-alist-meta-data-toml-override-partial.md b/example-site/content/posts/menu-alist-meta-data-toml-override-partial.md index d39b4ef..e6268ba 100644 --- a/example-site/content/posts/menu-alist-meta-data-toml-override-partial.md +++ b/example-site/content/posts/menu-alist-meta-data-toml-override-partial.md @@ -3,7 +3,7 @@ title = "Overriding few menu properties" date = 2017-07-18 tags = ["menu"] draft = false -[menu.main] +[menu."something here"] parent = "posts" weight = 10 identifier = "ov-partial" diff --git a/example-site/content/posts/menu-alist-meta-data-toml.md b/example-site/content/posts/menu-alist-meta-data-toml.md index 1cc8978..dd26cab 100644 --- a/example-site/content/posts/menu-alist-meta-data-toml.md +++ b/example-site/content/posts/menu-alist-meta-data-toml.md @@ -1,9 +1,9 @@ +++ -title = "Menu Alist Meta Data in TOML Front Matter" +title = "Menu Meta Data in TOML Front Matter" date = 2017-07-18 tags = ["menu"] draft = false -[menu.main] +[menu."something here"] parent = "posts" weight = 80 identifier = "foo1" diff --git a/example-site/content/posts/menu-meta-data-yaml2.md b/example-site/content/posts/menu-meta-data-yaml2.md index 5c0c304..3396feb 100644 --- a/example-site/content/posts/menu-meta-data-yaml2.md +++ b/example-site/content/posts/menu-meta-data-yaml2.md @@ -1,13 +1,13 @@ --- -title : "Menu Meta Data in YAML Front Matter" -date : 2017-07-18 +title : "White space in menu entry" +date : 2017-07-19 tags : ["menu", "yaml"] draft : false menu : - main: - parent : "posts" + "something here": weight : 25 - identifier : "menu-yaml" --- Testing the addition of *menu* meta data to the YAML front matter. 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 entry keyword. diff --git a/example-site/content/posts/menu-meta-data-yaml3.md b/example-site/content/posts/menu-meta-data-yaml3.md new file mode 100644 index 0000000..1fab874 --- /dev/null +++ b/example-site/content/posts/menu-meta-data-yaml3.md @@ -0,0 +1,15 @@ +--- +title : "White space in menu name" +date : 2017-07-19 +tags : ["menu", "yaml"] +draft : false +menu : + main: + parent : "posts" + weight : 25 + name : "Menu in YAML" +--- + +Testing the addition of *menu* meta data to the YAML front matter. 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. diff --git a/ox-hugo.el b/ox-hugo.el index 731ae2c..b1f18b3 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -428,7 +428,7 @@ convert to an alist ((:name . \"foo\") (:weight . 80))." (let ((menu-alist (org-babel-parse-header-arguments menu-prop-str)) ret) ;; Hugo menu properties: https://gohugo.io/content-management/menus/ - (dolist (prop '(name url menu identifier pre post weight parent children)) + (dolist (prop '(menu name url identifier pre post weight parent)) ;children prop is probably read-only (when-let* ((key (intern (concat ":" (symbol-name prop)))) ;name -> :name (cell (assoc key menu-alist))) (push `(,prop . ,(cdr cell)) ret))) @@ -534,24 +534,29 @@ are \"toml\" and \"yaml\"." (menu-alist value) ;; Menu name needs to be non-nil to insert menu ;; info in front matter. - (menu-name (cdr (assoc 'name menu-alist))) - (menu-name-str "") + (menu-entry (cdr (assoc 'menu menu-alist))) + ;; Wrap the menu-entry with double quotes if it + ;; contains non-alphabetical characters. + (menu-entry (if (string-match-p "\\`[a-zA-Z]+\\'" menu-entry) + menu-entry + (org-hugo--wrap-string-in-quotes menu-entry))) + (menu-entry-str "") (menu-value-str "")) (message "[menu alist DBG] = %S" menu-alist) - (when menu-name - (setq menu-name-str (cond ((string= format "toml") - (format "[menu.%s]\n" menu-name)) - ((string= format "yaml") - (prog1 - (format "menu %s\n%s%s%s\n" sign indent menu-name sign) - (setq indent (concat indent indent)))) ;Double the indent for next use - (t - ""))) + (when menu-entry + (setq menu-entry-str (cond ((string= format "toml") + (format "[menu.%s]\n" menu-entry)) + ((string= format "yaml") + (prog1 + (format "menu %s\n%s%s%s\n" sign indent menu-entry sign) + (setq indent (concat indent indent)))) ;Double the indent for next use + (t + ""))) (dolist (menu-pair menu-alist) (let ((menu-key (symbol-name (car menu-pair))) (menu-value (cdr menu-pair))) - ;; (message "menu DBG: %S %S %S" menu-name menu-key menu-value) - (unless (string= "name" menu-key) + ;; (message "menu DBG: %S %S %S" menu-entry menu-key menu-value) + (unless (string= "menu" menu-key) (when menu-value (unless (string= menu-key "weight") (setq menu-value (org-hugo--wrap-string-in-quotes menu-value))) @@ -559,7 +564,7 @@ are \"toml\" and \"yaml\"." (concat menu-value-str (format "%s%s %s %s\n" indent menu-key sign menu-value))))))) - (setq menu-string (concat menu-name-str menu-value-str)))) + (setq menu-string (concat menu-entry-str menu-value-str)))) (setq front-matter (concat front-matter (format "%s %s %s\n" @@ -590,7 +595,8 @@ It does so only if `org-use-property-inheritance' is a list (or nil). Otherwise it just returns the value of ``org-use-property-inheritance'." (if (listp org-use-property-inheritance) - (let ((prop-list '("HUGO_TAGS" + (let ((prop-list '("HUGO_FRONT_MATTER_FORMAT" + "HUGO_TAGS" "HUGO_CATEGORIES" "HUGO_DRAFT" "HUGO_TYPE"