Closed emacsun closed 6 years ago
I am reusing the org babel parsing logic, where the parameters have to be alphabets, numbers or _.
I see that you are trying to add custom front-matter that are in the form of TOML tables.
That is not supported at the moment.
I briefly gave a thought to this limitation earlier, but there was no motivation to implement that, as it's a bit complicated.
Just explain the internals, ox-hugo
does not blindly take the arguments to EXPORT_HUGO_CUSTOM_FRONT_MATTER
and paste then in front-matter. It first converts it to an alist internally, and then translates that to TOML or YAML front-matter as per user preference.
So EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :summary "summary"
would internally convert to '((summary "summary") ..)
.
For supporting TOML tables, that logic becomes more complicated.. taking your example, and slightly modifying it:
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :summary "summary"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :image_preview "projects/bubbles.jpg"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :[header]
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :image "projects/Readingabook.jpg"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :foo "bar"
What if I want:
'((summary "summary")
(image_preview "projects/bubbles.jpg")
(header
(image "projects/Readingabook.jpg")
(foo "bar")))
vs
(note that below, foo
is outside header
))
'((summary "summary")
(image_preview "projects/bubbles.jpg")
(header
(image "projects/Readingabook.jpg"))
(foo "bar"))
??
So there's a complication managing nested front-matter variables.
It was complicated to supported the TOML tables for the inbuilt resources
front-matter.
Now I have to do something similar to support custom TOML tables :)
I don't know how to implement this yet.. hopefully I can quickly come up with a good solution.
@emacsun As a side, based on your example:
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :[header]
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :image "projects/Readingabook.jpg"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :caption "stay hungry, stay foolish"
it is better served with the inbuilt resources
support.
See few tests here: https://ox-hugo.scripter.co/test/tags/resources
I will definitely implement this feature, but if you can adapt to using resources, it's already supported by ox-hugo
, and I can lower the priority for this one.
Please let me know.
@emacsun I have added a test case in commit https://github.com/kaushalmodi/ox-hugo/commit/0b247eb7890da09ba9567bce18009c8e4a732b83 to explain what I meant by my previous comment; here is what it looks like: https://ox-hugo.scripter.co/test/posts/header-image-using-resources/.
Let me know if that approach can work for you.
@emacsun Well, it turned out a bit easier to implement than I earlier thought.
I have committed this feature which allows specifying nested maps in custom front-matter (with only 1 level of nesting though). Without setting a limit like this, I might need to implement a full-blown sexp to toml/yaml translator :P.
Based on your example, you would need to set the nested map for header
as follows:
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :header '((image . "projects/Readingabook.jpg") (caption . "stay hungry, stay foolish"))
Test page: https://ox-hugo.scripter.co/test/posts/custom-front-matter-with-nested-maps-toml/
Let me know if this resolves your issue.
@emacsun Not sure if you looked at the first commit that implemented this feature, but if you did, then I have just committed an improvement over that in https://github.com/kaushalmodi/ox-hugo/commit/0ad7d64d5e7c47caf1d24b04fe9cf43c5ec97e67. You do not need to suffix the nested map keys with {}
any more.
Dear @kaushalmodi :
Thank you for your reply.
Thanks again.
Recently, I am going to clean all my posts, the old address is http://zlearning.netlify.com/ . most of the posts are written in Chinese. With the new blog zcl.space , I want to control every post using ox-hugo and write new post using English. Right now, the blog zcl.space is under test and some sections are under construction. The repository of zcl.space is https://github.com/emacsun/ZHugo . I think every Emacser who manages his/her blog should give ox-hugo a try. It is really convenient and efficient.
With the new blog zcl.space , I want to control every post using ox-hugo and write new post using English.
👍
The repository of zcl.space is https://github.com/emacsun/ZHugo .
Thanks for sharing that.
I think every Emacser who manages his/her blog should give ox-hugo a try. It is really convenient and efficient.
Thanks for the kind words! :D I hope so too. But I think that the group of people using Hugo and using Org.. I mean proper Org, not just as a Markdown replacement, is very small.
You can close this issue once it is resolved for you.
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :header '((image . "projects/Readingabook.jpg") (caption . "stay hungry, stay foolish"))
this line works perfectly for me. I am ready to close this issue.
hi,
is there a way to do this when using the yaml
metadata format?
id like some nesting like
---
cover:
image: "/myimage.jpg"
---
but i can't really figure out how to do that, any help ?
@arjunkathuria I have moved your question to https://github.com/kaushalmodi/ox-hugo/issues/488.
Dear @kaushalmodi
I modify the function in the post https://ox-hugo.scripter.co/doc/org-capture-setup/
However , when I can capture a post in the Org file as :
** TODO fourth test :PROPERTIES: :EXPORT_FILE_NAME: fourth-test :EXPORT_DATE: <2018-03-01 Thu 00:10> :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :summary "summary" :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :image_preview "projects/bubbles.jpg" :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :[header] :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :image "projects/Readingabook.jpg" :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :caption "stay hungry, stay foolish" :END:
four test
The [header] in the exported markdown file disappeared. I need the [header] there.
+++ title = "fourth test" author = ["Eason Zhang"] date = 2018-03-01T00:10:00+08:00 lastmod = 2018-03-01T00:18:00+08:00 tags = ["project"] draft = true summary = "summary" image_preview = "projects/bubbles.jpg" image = "projects/Readingabook.jpg" caption = "stay hungry, stay foolish" +++
four test
appendix: I modify the function org-hugo-new-subtree-project-capture-template as : (defun org-hugo-new-subtree-project-capture-template () "Returns
org-capture' template string for new Hugo post. See
org-capture-templates' for more information." (let (;; http://www.holgerschurig.de/en/emacs-blog-from-org-to-hugo/ (date (format-time-string (org-time-stamp-format :inactive) (org-current-time))) (title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title (fname (org-hugo-slug title))) (mapconcat #'identity `( ,(concat " TODO " title) ":PROPERTIES:" ,(concat ":EXPORT_FILE_NAME: " fname) ,(concat ":EXPORT_DATE: " date) ;Enter current date and time ,(concat ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: " ":summary \"summary\"") ,(concat ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: " ":image_preview \"projects/project.jpg\"") ,(concat ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: " ":[header] ") ,(concat ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: " ":image \"projects/project_header.jpg\" " ) ,(concat ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: " ":caption \"stay hungry, stay foolish:smile:\" ") ":END:" "%?\n") ;Place the cursor here finally "\n")))May be the [header] has no value, so it will be optimized out. Do you have any comments? Thank you .