Comments (12)
Hi, i had the same problem, and ended up changing the menu creation to .Site.Menus
Hugo Docs
it changes a bit on the page, but i like it better this way.
Menu changed to this (line 16)
<ul class="topics">
{{ $page := . }}
{{ range .Site.Menus.main }}
<li class="dd-item {{ if eq $page.RelPermalink .URL }}active{{ end }} {{if in $page.RelPermalink .URL }}parent{{ end }}"
data-nav-id="{{.URL}}">
<a href="{{.URL}}">
<span>
{{ .Pre }}
{{ .Name }}
{{ if .Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"> {{ end }} </i>
</span>
</a>
{{ if .HasChildren }}
<ul>
{{ range .Children}}
<li class="dd-item {{ if eq $page.RelPermalink .URL }}active{{ end }}" data-nav-id="{{.URL}}">
<a href="{{.URL}}">
<span>{{ .Name }} {{ if .Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"></i> {{ end }} </span>
</a>
</li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
</ul>
since i do not like having the menu defined on config.toml
my content page header changed to this
---
title : "Title to show"
next: /sobre/intro
chapter: true
menu:
main:
identifier : "Unique_ID_OF_PAGE"
weight: 5
name : "Title to show"
pre : '<b>1.</b>'
---
and the child's (we can have unlimited levels, using the identifier
and the parent
, however the menu design only show 2 levels for now)
---
title: What is this Hugo theme ?
prev: /sobre
next: /sobre/requesitos
menu:
main:
identifier : "Unique_ID_OF_PAGE"
parent: 'Unique_ID_OF_PARENT'
weight: 5
name : "What is this Hugo theme"
---
and a bug fix on header.html (on the breadcrumb creator) line 51
{{ $type := .Params.menu.main.parent }}
{{ $relLink := .RelPermalink }}
{{ range $name , $value := .Site.Menus.main }}
{{ if eq $value.Identifier $type }}
{{ if ne $relLink $value.URL }}
<a href="{{ $value.URL }}" itemprop="url"><span itemprop="title"> <b>{{ $value.Name }}</b></span></a> <i class="fa fa-angle-right"></i>
{{ end }}
{{ end }}
{{ end }}
and now i have the same menu, and the weight working.
I still working to reduce the duplication on top of content pages, since we have Title
and menu name
with the same values.
i think i just need replace all uses of .Title
with the menu value .Params.menu.main.name
, however havent done that yet, so now sure about that.
from hugo-theme-learn.
Yeah, that was why I was trying something like First
.Weight
(so order the sections by the weight of the first page in the section).
I don't know where I got the First
from - I believe I found it in some go documentation but I can't seem to find it again.
from hugo-theme-learn.
@TimNN @eddie Yes, it's a map of list of pages, you can't sort it like a list (https://gohugo.io/templates/list/). The key
is the folder name, the value
is the list of the pages inside the folder.
My thought was to create a menu automatically from the folder structure of the content, instead of using the Hugo menu functionality (in order to avoid boilerplate in config.toml). As Hugo does not provide (yet) a functionality like this, I based everything on the .Site.Sections
.
Based on that principle, and my little knowledge about Go Templates, I can't define right know a nice and clean solution (but I'm sure there is one 😄 ).
from hugo-theme-learn.
Hello Xaf,
I'll look into that. Since you used weigth and it does not work, it may be a bug.
Meanwhile, one simple solution is prefixing your folders with a number. Then, if you don't want the numbers to be in the path, create aliases.
Note: weight sure works for subpages, as you can see in the demo (repo). I'll check for chapter pages.
from hugo-theme-learn.
I'm also encountering this issue (weight does not work with chapters).
from hugo-theme-learn.
It looks like the problem is that .Site.Sections
is an map of pageName
to WeightedPages
objects and not a WeightedPages
object.
from hugo-theme-learn.
I tried to use {{ range $key , $value := sort .Site.Sections "First.Weight" }}
in menu.html
which I believe should work, but fails because "error calling sort: First is neither a struct field, a method nor a map element of type hugolib.WeightedPages".
from hugo-theme-learn.
@TimNN The sections are just directories right? So they won't have the weight attribute.
from hugo-theme-learn.
@TimNN Printing out the sections map gives me this
map[faq:[{0 }] changelog:[{0 }] intro:[{5 }]]
Not sure how to apply sort with this however :)
from hugo-theme-learn.
I created a pr #5 with this changes and keep compatibility to folder way, and with 3rd level menu, however, still have a decision to make if we wanna use go this way.
from hugo-theme-learn.
I think it would be much nicer to go with the default hugo way. Would love to see this PR merged.
from hugo-theme-learn.
I posted an alternative solution in #8
from hugo-theme-learn.
Related Issues (20)
- New Release to address the solved issues HOT 4
- Issue with setting landingPageURL being reliant on languages HOT 1
- Google Analytics in the exampleSite HOT 1
- Update Mermaid version HOT 2
- Font licensing? HOT 1
- Text-align left for chapters
- Create Handout HOT 1
- Search function not working as expected HOT 1
- Custom Header and Footer Rendering Under Sidebar HOT 1
- override global ordersectionsby on a per section basis? HOT 1
- disable copy-to-clipboard on a per code block basis? HOT 1
- i18n translation by content directory HOT 1
- mindmaps in mermaid (feature request ) HOT 1
- Attachments URL wrong if site is deployed under subpath
- link of logo not pointing to basepath HOT 1
- Synology Docker configuration & firewall HOT 1
- A Few Questions HOT 2
- What are people migrating too? HOT 2
- Global Markdown link references HOT 1
- Please change the default baseURL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hugo-theme-learn.