Skip to content

Commit 5ad69b4

Browse files
committed
doc: How to set the menu front-matter
Fixes #166.
1 parent 6c6c0ba commit 5ad69b4

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed

doc/ox-hugo-manual.org

+203
Original file line numberDiff line numberDiff line change
@@ -4507,6 +4507,209 @@ This feature has language support too. If the ~#+language~ keyword is
45074507
set to a language code other than ~en~ (example: ~de~), the
45084508
translations of the element type names get exported. The translations
45094509
are based on the ~org-export-dictionary~ variable from ~ox.el~.
4510+
*** Menu Front-matter
4511+
:PROPERTIES:
4512+
:EXPORT_FILE_NAME: menu-front-matter
4513+
:END:
4514+
#+begin_description
4515+
Support for exporting to ~menu~ front-matter.
4516+
#+end_description
4517+
In Hugo, the global ~site~ variable contains a dictionary called
4518+
~Menus~. Within ~Menus~, a /Menu Name/ is used to reference a
4519+
collection or slice of /Menu Entries/. Each of those /Menu Entries/
4520+
are associated with a /Page/. One can visualize the relationship of
4521+
those objects in this manner:
4522+
4523+
#+name: code__hugo_menu_entry_visualization
4524+
#+caption: Visualization of Hugo Menu Entries
4525+
#+begin_src text
4526+
site
4527+
Menus
4528+
| +--------------+
4529+
+-- "Menu Name 1" --> | Menu Entry 1 +----> Page 1
4530+
| +--------------+
4531+
| | Menu Entry 2 +----> Page 2
4532+
| +--------------+
4533+
| | .. +----> ..
4534+
| +--------------+
4535+
|
4536+
| +--------------+
4537+
+-- "Menu Name 2" --> | Menu Entry a +----> Page a
4538+
| +--------------+
4539+
| | Menu Entry b +----> Page b
4540+
| +--------------+
4541+
. | .. +----> ..
4542+
+--------------+
4543+
#+end_src
4544+
4545+
So on each /Page/, the user can specify the keys of the associated
4546+
/Menu Entry/ using the ~menu~ front-matter.
4547+
4548+
#+begin_note
4549+
A /Menu Entry/ is uniquely associated with a /Page/.
4550+
#+end_note
4551+
4552+
Here are the valid keys for that ~menu~ config as derived from the
4553+
[[https://gohugo.io/variables/menus/#menu-entry-variables][Menu Entry Variables]] documentation:
4554+
4555+
#+name: tab__menu_config_keys
4556+
#+caption: Menu Entry /keys/ and associated variables accessible from Hugo template
4557+
|------------------+-------------------------------+-----------------------------------------------------------------------------------------|
4558+
| Menu Entry /Key/ | Menu Entry /Variable/ | Brief Description |
4559+
|------------------+-------------------------------+-----------------------------------------------------------------------------------------|
4560+
| ~[menu.NAME]~ | ~.Menu~ | Name of the Menu containing the current Menu Entry |
4561+
| ~url~ | ~.URL~ | /URL/ that this Menu Entry points to, defaults to page's ~.RelPermalink~ |
4562+
| ~identifier~ | ~.Identifier~ | /Identifier/ is the unique string used to identify this Menu Entry |
4563+
| ~name~ | ~.Name~ | /Name/ of this Menu Entry, defaults to page's ~.LinkTitle~ |
4564+
| ~pre~ | ~.Pre~ | HTML string that can be used to /prefix/ the Menu Entry ~.Name~ |
4565+
| ~post~ | ~.Post~ | HTML string that can be used to /postfix/ the Menu Entry ~.Name~ |
4566+
| ~weight~ | ~.Weight~ | /Weight/ for this Menu Entry, used for sorting menus in a sidebar |
4567+
| ~parent~ | ~.Parent~ | Name or Identifier of this Menu Entry's /Parent/ Menu Entry |
4568+
| ~title~ | ~.Title~ (this is a function) | Used to set this Menu Entry's link's ~title~ attribute, defaults to page's ~.LinkTitle~ |
4569+
|------------------+-------------------------------+-----------------------------------------------------------------------------------------|
4570+
**** ~:EXPORT_HUGO_MENU:~ and ~#+hugo_menu:~
4571+
In Org mode, these Menu Entry keys are specified using the
4572+
~:EXPORT_HUGO_MENU:~ property (subtree-based exports) or
4573+
~#+hugo_menu:~ keyword (file-based exports). They are set in this
4574+
/property list/ form:
4575+
4576+
#+begin_src org
4577+
:EXPORT_HUGO_MENU: :menu <menu name> <:key 1> <val 1> <:key 2> <val 2> ..
4578+
#+end_src
4579+
4580+
The ~:menu~ key is mandatory because that's used to specify the
4581+
current Page's Menu Entry's parent Menu name.
4582+
4583+
The rest of the property list keys map directly with the Menu Entry
4584+
keys shown below:
4585+
4586+
#+name: tab__menu_front_matter_keys
4587+
#+caption: ~menu~ Front Matter keys
4588+
|--------------------------------------------+-------------------------+-----------------------------------------------------------|
4589+
| ~:EXPORT_HUGO_MENU:~ or ~#+hugo_menu:~ key | Menu Entry Front-matter | Note |
4590+
|--------------------------------------------+-------------------------+-----------------------------------------------------------|
4591+
| ~:menu VAL~ | ~[menu.VAL]~ | *mandatory* |
4592+
| ~:identifier VAL~ | ~identifier = VAL~ | Gets auto-set to the /sanitized/ post title if not set |
4593+
| ~:weight VAL~ | ~weight = VAL~ | Gets auto-set based on post subtree's location if not set |
4594+
| ~:url VAL~ | ~url = VAL~ | /optional/ |
4595+
| ~:pre VAL~ | ~pre = VAL~ | /optional/ |
4596+
| ~:name VAL~ | ~name = VAL~ | /optional/ |
4597+
| ~:post VAL~ | ~post = VAL~ | /optional/ |
4598+
| ~:parent VAL~ | ~parent = VAL~ | /optional/ |
4599+
| ~:title VAL~ | ~title = VAL~ | /optional/ |
4600+
|--------------------------------------------+-------------------------+-----------------------------------------------------------|
4601+
***** General use example
4602+
For subtree-based exports, it would be common to specify the container
4603+
Menu name in a parent subtree and let that value trickle down to the
4604+
nest post subtrees as a result of Org property inheritance.
4605+
4606+
It would look something like this:
4607+
4608+
#+name: code__common_menu_setting
4609+
#+caption: Common style of setting the ~menu~ front-matter
4610+
#+begin_src org
4611+
,* Posts under the ~main~ Menu
4612+
:PROPERTIES:
4613+
:EXPORT_HUGO_MENU: :menu main
4614+
:END:
4615+
,** Post 1
4616+
:PROPERTIES:
4617+
:EXPORT_FILE_NAME: post-1
4618+
:END:
4619+
,** Post 2
4620+
:PROPERTIES:
4621+
:EXPORT_FILE_NAME: post-2
4622+
:END:
4623+
#+end_src
4624+
4625+
When these posts are exported, the ~menu~ front-matter in them will
4626+
look something like this:
4627+
4628+
#+name: code__common_menu_setting_post_1_fm
4629+
#+caption: ~menu~ in "Post 1" front-matter
4630+
#+begin_src toml
4631+
[menu]
4632+
[menu.main]
4633+
weight = 3001
4634+
identifier = "post-1"
4635+
#+end_src
4636+
4637+
#+name: code__common_menu_setting_post_2_fm
4638+
#+caption: ~menu~ in "Post 2" front-matter
4639+
#+begin_src toml
4640+
[menu]
4641+
[menu.main]
4642+
weight = 3002
4643+
identifier = "post-2"
4644+
#+end_src
4645+
4646+
Note that the ~weight~ and ~identifier~ were set automatically by
4647+
~ox-hugo~ as they were not specified.
4648+
***** Example where more ~menu~ keys are specified
4649+
For a post with the below property (subtree-based export):
4650+
#+begin_src org
4651+
:EXPORT_HUGO_MENU: :menu "something here" :weight 80 :parent posts :identifier foo1
4652+
#+end_src
4653+
4654+
, the ~menu~ in the exported front-matter will look like below:
4655+
#+begin_src toml
4656+
[menu]
4657+
[menu."something here"]
4658+
parent = "posts"
4659+
weight = 80
4660+
identifier = "foo1"
4661+
#+end_src
4662+
**** Overriding Menu Entry keys
4663+
#+begin_note
4664+
This feature is applicable only to subtree-based flow.
4665+
#+end_note
4666+
Use the ~:EXPORT_HUGO_MENU_OVERRIDE:~ property if you need to override
4667+
only some of the inherited Menu Entry keys.
4668+
4669+
Here's an example Org snippet:
4670+
4671+
#+name: code__hugo_menu_override_org
4672+
#+caption: Example of using ~:EXPORT_HUGO_MENU_OVERRIDE:~
4673+
#+begin_src org
4674+
,* Parent subtree
4675+
:PROPERTIES:
4676+
:EXPORT_HUGO_MENU: :menu "something here" :parent posts
4677+
:END:
4678+
,** Post 1
4679+
:PROPERTIES:
4680+
:EXPORT_FILE_NAME: foo
4681+
:EXPORT_HUGO_MENU_OVERRIDE: :identifier "abc" :weight 100
4682+
:END:
4683+
,** Post 2
4684+
:PROPERTIES:
4685+
:EXPORT_FILE_NAME: bar
4686+
:EXPORT_HUGO_MENU_OVERRIDE: :weight 1
4687+
:END:
4688+
#+end_src
4689+
4690+
With above, "Post 1" ~menu~ front-matter will be exported as:
4691+
4692+
#+name: code__hugo_menu_override_post_1
4693+
#+caption: ~menu~ in "Post 1" front-matter with overridden ~identifier~ and ~weight~ values
4694+
#+begin_src toml
4695+
[menu]
4696+
[menu."something here"]
4697+
parent = "posts"
4698+
weight = 100
4699+
identifier = "abc"
4700+
#+end_src
4701+
4702+
, and "Post 2" ~menu~ front-matter will be exported as:
4703+
4704+
#+name: code__hugo_menu_override_post_2
4705+
#+caption: ~menu~ in "Post 2" front-matter with overridden ~weight~ value
4706+
#+begin_src toml
4707+
[menu]
4708+
[menu."something here"]
4709+
identifier = "post-2"
4710+
parent = "posts"
4711+
weight = 1
4712+
#+end_src
45104713
** Meta
45114714
:PROPERTIES:
45124715
:EXPORT_HUGO_MENU: :menu "7.meta"

0 commit comments

Comments
 (0)