kaushalmodi / ox-hugo

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

Support maps of maps in front matter (theme Academic) #226

Closed andreas-h closed 2 years ago

andreas-h commented 5 years ago

I'm using the Academic Theme. They have a way of combing the homepage from several .md files, one could look like this, e.g.:

+++
# About/Biography widget.
widget = "about"
active = true
date = 2016-04-20T00:00:00

# Order that this section will appear in.
weight = 5

# List your academic interests.
[interests]
  interests = [
    "Artificial Intelligence",
    "Computational Linguistics",
    "Information Retrieval"
  ]

# List your qualifications (such as academic degrees).
[[education.courses]]
  course = "PhD in Artificial Intelligence"
  institution = "Stanford University"
  year = 2012

[[education.courses]]
  course = "MEng in Artificial Intelligence"
  institution = "Massachusetts Institute of Technology"
  year = 2009

[[education.courses]]
  course = "BSc in Artificial Intelligence"
  institution = "Massachusetts Institute of Technology"
  year = 2008

+++

# Biography

Lena Smith is a professor of artificial intelligence at the Stanford AI Lab. Her research interests include distributed robotics, mobile computing and programmable matter. She leads the Robotic Neurobiology group, which develops self-reconfiguring robots, systems of self-organizing robots, and mobile sensor networks.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate. 

How can I get ox-hugo to create these lists (like [interests = ...] and [[education.courses]] ...) which both span over several lines, in the front matter of the exported Markdown?

kaushalmodi commented 5 years ago

So the day has finally come. Someone actually needs this feature? :P

This is a known limitation. See https://ox-hugo.scripter.co/doc/custom-front-matter/#maps-of-single-and-list-values: "Maps of maps are not supported.".

I didn't implement that because I wasn't sure if all the effort needed in designing this complicated feature would be worth it.

But now I'll think of a user-friendly way of entering this table meta data in Org that would translate to that TOML table.

I will work on this, but this feature is not a high priority.

kaushalmodi commented 5 years ago

How can I get ox-hugo to create these lists (like [interests = ...] and [[education.courses]] ...) which both span over several lines, in the front matter of the exported Markdown?

Just to be clear, if you look at that link I pasted, the "interests" front-matter setting is already supported.

But the "education.courses", which is a TOML table of tables, is not yet.

kaushalmodi commented 5 years ago

@andreas-h Hello, I thought a bit more about this. While I won't have time implementing a full-fledged parsing of maps of maps type front-matter, I have added a brute-force solution that would work for any kind of front-matter in https://github.com/kaushalmodi/ox-hugo/commit/ca0e602f7ede31313e028223965bd8aca99252c6.

See https://ox-hugo.scripter.co/doc/custom-front-matter/#front-matter-extra for details.

Here's a test case: https://ox-hugo.scripter.co/test/posts/front-matter-toml-toml-extra/ (see the Markdown source link in there for ox-hugo generated front-matter + content).

Here's the source of that test from the test suite:

** Extra Front-matter                              :extra:verbatim:src_block:
:PROPERTIES:
:EXPORT_HUGO_WEIGHT: 5
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :widget "about"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :active "true"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :interests '((interests . ("Artificial Intelligence" "Computational Linguistics" "Information Retrieval")))
:END:
*** TOML Front-matter                                                  :toml:
:PROPERTIES:
:EXPORT_HUGO_FRONT_MATTER_FORMAT: toml
:END:
**** Extra Front-matter (TOML, TOML extra)                       :toml_extra:
:PROPERTIES:
:EXPORT_FILE_NAME: front-matter-toml-toml-extra
:END:
{{{oxhugoissue(226)}}}

The ~#+begin_src toml :front_matter_extra t~ TOML block here will get
appended to the TOML front-matter.
#+begin_src toml :front_matter_extra t
# List your qualifications (such as academic degrees).
[[education.courses]]
  course = "PhD in Artificial Intelligence"
  institution = "Stanford University"
  year = 2012

[[education.courses]]
  course = "MEng in Artificial Intelligence"
  institution = "Massachusetts Institute of Technology"
  year = 2009

[[education.courses]]
  course = "BSc in Artificial Intelligence"
  institution = "Massachusetts Institute of Technology"
  year = 2008
#+end_src

#+begin_src toml
# this TOML block will export to the Markdown body
#+end_src
andreas-h commented 5 years ago

Hey, @kaushalmodi , that's so great - thanks a lot! This actually solves all my needs :-)

kaushalmodi commented 2 years ago

I'll close this issue because, I haven't felt a real need to implement this feature in these many years (and it would be very complicated if I attempted to do it).

Also front matter extra already solves the need.

So I'll close this issue.

Thanks!