You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.6 KiB

4 years ago
  1. +++
  2. title = "Section Menu"
  3. description = "Display a contextual site-wide navigation with links."
  4. categories = ["navigation"]
  5. tags = ["links", "taxonomy"]
  6. features = ["code highlighter", "snippets", "section menu"]
  7. notes = [
  8. "review 'fuzzy-search' examples if modified"
  9. ]
  10. [[copyright]]
  11. owner = "Josh Habdas"
  12. date = "2019"
  13. license = "agpl-3.0-or-later"
  14. +++
  15. After Dark uses Hugo's {{< external href="https://gohugo.io/templates/menu-templates/#section-menu-for-lazy-bloggers" text="Section Menu for “Lazy” Bloggers" />}} to create a site-wide navigational aid. The section menu is disabled by default.
  16. {{< hackcss-card header="Interactive Example" >}}
  17. {{< navmenu >}}
  18. {{< /hackcss-card >}}
  19. Enable it from `menu.main` layout config in your site configuration:
  20. ```toml
  21. [params.layout.menu.main]
  22. hidden = true # set `false` or remove to show section menu
  23. ```
  24. With the menu enabled navigation links will begin appearing automatically on a per-section basis whenever {{< external href="https://gohugo.io/getting-started/usage/#draft-future-and-expired-content" text="Published Content" />}} is available within that section.
  25. ## Customizing
  26. Adjust link names and menu positions by adding the following code block to your {{< external href="https://gohugo.io/getting-started/configuration/" text="Site Configuration" />}} and modifying it to meet your needs:
  27. ```toml
  28. [[menu.main]]
  29. name = "Home"
  30. weight = 1
  31. identifier = "home"
  32. url = "/"
  33. [[menu.main]]
  34. name = "Posts"
  35. weight = 2
  36. identifier = "post"
  37. url = "/post/"
  38. ```
  39. Exclude menu items by identifier:
  40. ```toml
  41. [params.layout.menu.main]
  42. exclude = ["home", "post"] # exclude homepage and blog postings
  43. ```
  44. Decorate links with SVG icons using `pre` and `post`:
  45. ```toml
  46. [[menu.main]]
  47. name = "Search"
  48. identifier = "search"
  49. url = "/search/"
  50. post = "<svg aria-hidden=\"true\" class=\"i-search\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\" fill=\"none\" stroke=\"currentcolor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"3\"><circle cx=\"14\" cy=\"14\" r=\"12\" /><path d=\"M23 23 L30 30\" /></svg>"
  51. ```
  52. Link to stand-alone pages using {{< external href="https://gohugo.io/content-management/front-matter/" text="Front Matter" />}} menu setting:
  53. ```toml
  54. title = "About"
  55. menu = "main"
  56. ```
  57. Change the link title to differentiate from page:
  58. ```toml
  59. title = "About Us"
  60. menu = "main"
  61. linktitle = "About"
  62. ```
  63. Position items using {{< external "https://gohugo.io/variables/menus/#menu-entry-variables" "Menu Entry Variables" />}} for more control:
  64. ```toml
  65. title = "About Us"
  66. [menu.main]
  67. name = "About"
  68. weight = 5
  69. ```
  70. Provide your own config settings for use in [Custom Layouts]({{< relref "custom-layouts" >}}):
  71. ```toml
  72. [params.layout.menu.main.custom]
  73. social_icons = ["telegram", "mastodon", "matrix"]
  74. ```
  75. And access them via your customized `navmenu.html`, if present:
  76. ```go-html-template
  77. {{ range .settings.custom.social_icons }}
  78. {{ partial "social-links.html" . }}
  79. {{ end }}
  80. ```
  81. Create a second menu immediately after the first:
  82. ```toml
  83. [[menu.main]]
  84. name = "Posts"
  85. weight = 2
  86. identifier = "post"
  87. url = "/post/"
  88. [[menu.utility]]
  89. name = "Email"
  90. weight = 1
  91. identifier = "email"
  92. url = "mailto:d0x3d@posteo.com"
  93. ```
  94. And position it to the right using [Custom Styles]({{< relref "custom-styles" >}}):
  95. ```css
  96. .hack > header {
  97. display: grid;
  98. grid-template-columns: 1fr minmax(min-content, auto);
  99. column-gap: 20px;
  100. grid-template-areas: "nav nav";
  101. }
  102. ```
  103. See {{< external href="https://gohugo.io/content-management/menus/" text="Menus in Hugo" />}} for additional capabilities. For help with CSS Grid Layout get your feet wet at {{< external "https://cssgridgarden.com" />}}.