I had an old site made with Hugo in 2015 with different articles. The home page display a list of articles title and summary. They were properly sorted.
Now using the latest Hugo version v0.28, they are not sorted by weight anymore.
Well I don’t have enough to troubleshoot this. Link to your site’s repo, and I will take a look.
If you are saying it isn’t working with a new version of Hugo, then you need to check all the templates generating that page, as well as the front matter in question, to ensure it is consistent and correct.
Using the code examples you shared, I tested it and it works as expected: they sort by weight. I am using 0.29.
I doubt there was a different in 0.28, but it was only the latest release for like a day, so maybe something broke. Try upgrading and seeing if that helps.
If you want, you can send me the theme or templates, and I can test them directly. To really make sure, you might want to make a copy of the site site, clear out all the content, and try adding a few pieces from scratch, with only title, date and weight, to see how it is behaving; hopefully that reveals an obvious fix.
I just installed 0.29 and copied config.toml, layouts and static into a new directory. I created fresh content with the matter set with title date and weight. The files a displayed in creation order, ignoring the weight value.
Note that I created the directories by hand and copied the files needed. Note also that I’m on Linux (Ubuntu). I don’t know if this matter.
Activating verbose log, These are the warnings I see
INFO 2017/09/30 12:36:57 found taxonomies: map[string]string{“tag”:“tags”, “category”:“categories”}
WARN 2017/09/30 12:36:57 [en] Unable to locate layout for “taxonomyTerm”: [taxonomy/category.terms.en.html.html …
WARN 2017/09/30 12:36:57 [en] Unable to locate layout for “taxonomyTerm”: [taxonomy/tag.terms.en.html.html …
WARN 2017/09/30 12:36:57 [en] Unable to locate layout for “section”: [section/docs.en.html.html …
WARN 2017/09/30 12:36:57 [en] Unable to locate layout for “404”: [404.html] …
WARN 2017/09/30 12:36:57 Skip dataDir: lstat /home/xxx/Sources/test-www.ditp.dir/data: no such file or directory
WARN 2017/09/30 12:36:57 Skip i18nDir: lstat /home/xxx/Sources/test-www.ditp.dir/i18n: no such file or directory
The site was created with Hugo 0.29 “hugo new site hugo-example”.
This is the HTML output:
<!DOCTYPE html>
<html>
<head>
<meta name="generator" content="Hugo 0.29" />
<meta charset="utf-8">
<title> My New Hugo Site </title>
</head>
<body>
<p>Index title page</p>
<p>Page("File2")</p>
<p>Page("File1")</p>
<p>Page("File0")</p>
<script data-no-instant>document.write('<script src="/livereload.js?port=1313&mindelay=10"></' + 'script>')</script></body>
</html>
As you can see the pages are not sorted by weight. The order should by file0, file2, file1.
If you get something different, then it could be OS related. I don’t know.
I am guessing as it is the default, pages assigned zero all fall in the same space, so any weighted piece gets processed first. Or something. I don’t know, we ought to pin that down and document it.
In the meantime, if you use any other weight, it sorts as expected. In my test I didn’t use 0, so I never ran into your issue. Now that you know, I guess you will figure out how to proceed.
Excellent ! Thank you very very much for the help. That was indeed the error.
This is the documentation page that should be fixed. https://gohugo.io/content-management/front-matter/ Adding to the weight parameter value that it must be bigger than 0 would save a lot of time to people like me