kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
879 stars 133 forks source link

do you have a plan for supporting "Maps of maps or TOML tables of tables" #325

Closed msteamc closed 4 years ago

msteamc commented 4 years ago

Dear Sir,

  Sorry to bother you, but do you have a play for supporting "Maps of maps or TOML tables of tables"

  I am using a hugo theme "academic" which require a maps of maps for the "docs" type output.

A example is listed as

[menu]
  [menu.signalsandsystems]
  parent = "chapter 1 advanced problems"
  weight = 2.0

I use the "begin_src" block, but it did not work.

Thank you very much.

msteamc commented 4 years ago

I walkaround this problem by using the methods mentioned here:

https://github.com/gcushen/hugo-academic/issues/682

In summary, two steps:

  1. define [[main.menu]] in menus.toml as
[[main.menu]]
  name = "Teaching"
  url= "/courses/"
  1. use
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :menu.signalsandsystems '((parent . "chapter 4 advanced problems") (weight . "1") )

in the property of subtree, and the front-matter will be exported as

[menu.signalsandsystems]
  parent = "chapter 3 advanced problems"
  weight = 2.0

Sir, If you find it difficult to support toml table, I am ok with the method metioned above.

Now, I am happy.

kaushalmodi commented 4 years ago

Hello, I don't plan to add support for "TOML tables of tables". It's mainly because even if I got it working as Org properties, the end format will be less readable than an actual TOML table.

So the best way is to use the special begin_src block as explained with examples in https://ox-hugo.scripter.co/doc/custom-front-matter/#front-matter-extra.

Please try out that approach. If it doesn't work, please give me a minimal reproducible Org file that can show that problem.

Also ensure that you are using the latest ox-hugo from MELPA.

msteamc commented 4 years ago

thank you sir. I have got it done. thanks for ur hard work and this handy tool.

kaushalmodi commented 4 years ago

Thanks. But please don't call me "sir". That's a bit too formal. Just "Kaushal" is fine :)

msteamc commented 4 years ago

OK. :)

I found that using the latest melpa version ox-hugo, the begin src does not work. very strange.

Actual Behavior

I use the begin_src and end_src block to export tomal tables of table as you mentioned in the manual https://ox-hugo.scripter.co/doc/custom-front-matter/

But no extra font matter export as expected

How to Reproduce the Issue

My Org-version is 9.2.6 and ox-hugo is the same as 20200122 which is now avaiable at melpa Emacs 26.3 I use spacemace at the master branch which is stable.

Example Org File

** TODO test 2
   :PROPERTIES:
   :EXPORT_FILE_NAME: index
   :LATEX_TITLE: test 2
   :EXPORT_HUGO_SECTION: project
   :EXPORT_HUGO_BUNDLE: test-2
   :EXPORT_DESCRIPTION: summary of this test.
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :url_pdf "#"
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :url_code "#"
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :url_dataset "#"
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :url_video "#"
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :external_link "/courses/example/"
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :projects '("signals and systems")
   :EXPORT_HUGO_CUSTOM_FRONT_MATTER: :image '((caption . " [**Watch**](https://youtube.com)") (preview_only . "true"))
   :END:
   :LOGBOOK:
   CLOCK: [2020-01-29 Wed 16:39]--[2020-01-29 Wed 16:50] =>  0:11
   :END:
 <2020-01-29 Wed 16:39>

#+begin_src toml :front_matter_extra t

[[links]]
icon = "youtube"
icon_pack = "fab"
name = "Watch It"
url = "/courses/example/"

[[links]]
icon = "instagram"
icon_pack = "fab"
name = "Inst"
url = "/courses/example/"

[[links]]
icon = "weibo"
icon_pack = "fab"
name = "Weibo"
url = "/courses/example/"

[[links]]
icon = "wechat"
icon_pack = "fab"
name = "Wechat"
url = "/courses/example/"
#+end_src

Thanks for your help.

kaushalmodi commented 4 years ago

@msteamc That test Org file is generating this for me:

+++
title = "ox-hugo Issue 325 test"
description = "summary of this test."
tags = ["front-matter", "extra", "verbatim", "src-block"]
draft = false
url_pdf = "#"
url_code = "#"
url_dataset = "#"
url_video = "#"
external_link = "/courses/example/"
projects = ["signals and systems"]
[image]
  caption = " [**Watch**](https://youtube.com)"
  preview_only = true

[[links]]
icon = "youtube"
icon_pack = "fab"
name = "Watch It"
url = "/courses/example/"

[[links]]
icon = "instagram"
icon_pack = "fab"
name = "Inst"
url = "/courses/example/"

[[links]]
icon = "weibo"
icon_pack = "fab"
name = "Weibo"
url = "/courses/example/"

[[links]]
icon = "wechat"
icon_pack = "fab"
name = "Wechat"
url = "/courses/example/"
+++

<span class="timestamp-wrapper"><span class="timestamp">&lt;2020-01-29 Wed 16:39&gt;</span></span>
kaushalmodi commented 4 years ago

You can ignore the tags = ["front-matter", "extra", "verbatim", "src-block"] portion as the tags got inherited from the parent sections in the ox-hugo test file.

Do you have the default front-matter type set to YAML by any chance? If so, the TOML extra front matter format will not work. You will need the extra front matter src block in YAML format instead.

kaushalmodi commented 4 years ago

You can see the Hugo rendered version of that test on https://ox-hugo.scripter.co/test/issues/325/.

If you scroll down a bit, you will see the Page Params (Debug) section list all the extra toml front-matter.

Here is the ox-hugo exported Markdown: https://raw.githubusercontent.com/kaushalmodi/ox-hugo/master/test/site/content/issues/325/index.md

msteamc commented 4 years ago

the value org-hugo--fm-yaml is nil.

do I have so set it as "toml"

Here is the output of org-hugo-debug-info

** =ox-hugo= defcustoms
|org-hugo-section                                      |"posts"|
|org-hugo-use-code-for-kbd                             |nil|
|org-hugo-preserve-filling                             |t|
|org-hugo-delete-trailing-ws                           |t|
|org-hugo-prefer-hyphen-in-tags                        |t|
|org-hugo-allow-spaces-in-tags                         |t|
|org-hugo-tag-processing-functions                     |(org-hugo--tag-processing-fn-replace-with-spaces-maybe org-hugo--tag-processing-fn-replace-with-hyphens-maybe)|
|org-hugo-auto-set-lastmod                             |nil|
|org-hugo-export-with-toc                              |nil|
|org-hugo-export-with-section-numbers                  |nil|
|org-hugo-front-matter-format                          |"toml"|
|org-hugo-default-static-subdirectory-for-externals    |"ox-hugo"|
|org-hugo-external-file-extensions-allowed-for-copying |("jpg" "jpeg" "tiff" "png" "svg" "gif" "mp4" "pdf" "odt" "doc" "ppt" "xls" "docx" "pptx" "xlsx")|
|org-hugo-date-format                                  |"%Y-%m-%dT%T%z"|
|org-hugo-paired-shortcodes                            |""|
|org-hugo-langs-no-descr-in-code-fences                |nil|
|org-hugo-suppress-lastmod-period                      |0.0|
|org-hugo-front-matter-format                          |"toml"|
kaushalmodi commented 4 years ago

Can you may be share the repo with Org source or create a dummy one that I can clone to reproduce the issue?

Also, for your example Org snippet you posted, can you also post the exported Markdown?

msteamc commented 4 years ago

Here is the minimum work example for org file, and the exported markdown is followed.

** DONE signals and systems
:PROPERTIES:
:EXPORT_FILE_NAME: index
:LATEX_TITLE: signals and systems
:EXPORT_HUGO_SECTION: project
:EXPORT_HUGO_BUNDLE: course-signals-and-systems-basic-problmes
:EXPORT_DESCRIPTION: solutions to the basic problems in chapter 1 of signals and systems
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :external_link /courses/signalsandsystems/
:END:
:LOGBOOK:
CLOCK: [2020-01-30 Thu 22:11]--[2020-01-30 Thu 22:12] =>  0:01
:END:
<2020-01-30 Thu 22:11>

#+begin_src toml :front_matter_extra t
[[links]]
icon = "youtube"
icon_pack = "fab"
name = "Watch It"
url = "/courses/example/"

[[links]]
icon = "instagram"
icon_pack = "fab"
name = "Inst"
url = "/courses/example/"

[[links]]
icon = "weibo"
icon_pack = "fab"
name = "Weibo"
url = "/courses/example/"

[[links]]
icon = "wechat"
icon_pack = "fab"
name = "Wechat"

url = "/courses/example/"
#+end_src

Right now, the begin_src block still does not work.

and the exported markdown file

+++
title = "signals and systems"
author = ["Eason"]
summary = "solutions to the basic problems in chapter 1 of signals and systems"
lastmod = 2020-01-31T07:15:00+08:00
tags = ["course"]
draft = false
external_link = "/courses/signalsandsystems/"
+++

Right now, the begin\_src block still does not work.
msteamc commented 4 years ago

I noticed that your exported markdown file use description = and mine summary. does it matter? I use #+hugo_front_matter_key_replace: description>summary at the top. and :EXPORT_DESCRIPTION: in the subtree property.

This is the only difference I can find. However, I do not think it is the problem.

kaushalmodi commented 4 years ago

That is indeed very odd. Unfortunately, I cannot fix the issue unless I can reproduce it on my end.

Do you want to clone the ox-hugo repo, eval the ox-hugo.el file from the cloned version, and then retry exporting your subtree?

If that also doesn't work, open the all-posts.org in the ox-hugo tests dir (see https://github.com/kaushalmodi/ox-hugo/commit/a80b250987bc770600c424a10b3bca6ff7282e3c) and export that exact subtree.

You need need to (require 'org-id) to export from the test file.

kaushalmodi commented 4 years ago

However, I do not think it is the problem.

That's correct. That shouldn't matter.

kaushalmodi commented 4 years ago

Also try putting that subtree in a new Org file (with the minimum required #+hugo_base_dir) and exporting from there.

msteamc commented 4 years ago

Before I clone the repo and installed it, I delete ox-hugo from list-packages. Then I restart emacs, because ox-hugo is a must for my emacs config. Spacemacs check that ox-hugo is missing, so it re-install it automatically. However, something wrong happened:

From the message buffer:


Checking /Users/chaolongzhang/.emacs.d/elpa/ox-hugo-20200122.2049...
Done (Total of 2 files compiled, 2 failed, 2 skipped)
File mode specification error: (void-function org-flag-region) [3 times]
File mode specification error: (void-function org-strip-quotes)

Next I will set spacemacs not install ox-hugo automatically and install it by cloning it by hand as you suggested.

msteamc commented 4 years ago

after cloning the repo to local, eval ox-hugo.el, the begin_src and end_src block still cannot export to the front of markdown.

Maybe it is the org that block it. I will check my settings of org. I suspect the language does not support.

kaushalmodi commented 4 years ago

@msteamc

File mode specification error: (void-function org-flag-region) [3 times] File mode specification error: (void-function org-strip-quotes)

ox-hugo is not using any of those functions. You might have your emacs config in a bad state. As I don't use Spacemacs, I cannot help much with the debug.

The best bet is always to comment your config in halves and see where the error originates from. You probably have a mix of old/new versions of org-mode and ox-hugo installed on your machine.

If you know how to load packages in an emacs -Q session, I would recommend doing that to narrow down to the root cause of this particular issue where you cannot export the extra front-matter src blocks.

msteamc commented 4 years ago

I give up debug my org config. However, I realize the same effect by adding

:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :[links] '( (icon . "youtube") (icon_pack . "fab")  (name . "Watch it")  (url . "/course/example/" ) )

and the exported front matter is:

[[links]]
  icon = "youtube"
  icon_pack = "fab"
  name = "Watch it"
  url = "/course/example/"
kaushalmodi commented 4 years ago

@msteamc Sorry, I cannot help if I cannot reproduce the issue. That workaround will cause you some trouble if you try to export a proper table of tables i.e. multiple [[links]].

If someday you have time, try to reproduce the issue from an emacs -Q session.