weight matter in Hugo not taken in account - hugo

I had an old site made with Hugo in 2015 with different articles.
They were properly sorted.
Now using the latest Hugo, they are apparently sorted by date and not by weight.
The directory is organized as follow:
content
docs
file1.md
file2.md
layouts
docs
single.html
summary.html
partials
css.html
header.html
footer.html
index.html
static
img1.png
img2.png
The list is displayed in the index file with
<div id="idx-content">
{{range .Data.Pages}}
{{.Render "summary"}}
{{end}}
</div>
Unfortunately, the ordering of the file summaries is not sorted by weight.
Adding .ByWeight after .Data.Pages doesn't help.

The weight value in the matter must be bigger than 0.

Related

How to use the same layout in a different directory?

I have a site using the hugo-coder theme, which has a layouts/posts folder that specifies that anything in the "posts" folder will have a blog post format.
I would like to have two different blogs in two different subdirectories, using the same layout. Is there a way to tell Hugo that the content/blog1 directory should use the same settings and layout as the content/posts directory without copying themes/hugo-coder/layouts/posts into layouts/blog1? Ideally I would avoid using symlinks, because, while convenient, I've had a decent amount of software throw weird errors when I use symlinks, so I avoid them when it's possible.
You can set the layout or type field to posts in the frontmatter of your _index.md file in content/blog1.
See this docs page for more info.
Edit: Alternatively, you could create an archetype for blog1 that automatically sets the value to posts in the frontmatter of individual posts in that section, assuming you're using hugo new blog1/postname.md to create posts for that section.
Double edit: The first suggestion didn't work. You could also create subsections within content/posts/blog1 and set the permalinks of posts in that subsection to use the last section only. That should remove the need to explicitly set the type in post frontmatter every time because each post would already have a type of posts.
In config.toml:
[permalinks]
posts = "/:sections[last]/:slug/"
You can use a partial in your templates. If you do that you WILL need the single and list file in the layouts/blog directory, but it could be an empty file referencing the partial. The layouts/posts/single.html and the layouts/blog/single.html both will then look like this:
{{ partial "singleblog.html" . }}
Compeletely DRY... and without much complexity.

Split single file to multiple "posts" in Hugo?

Hugo's one-file->one-page model is nice and simple, especially for a blog. But sometimes you want to write an "article" for a blog and split it into 2 or more pieces for separate pages (perhaps to be posted on separate days, or whatever).
Is there a way to do this within Hugo? Perhaps a combination of something you put in a layout/theme/shortcode and internal markup within the page (to signal where to split the article)?
Possible models might include:
1 input post "splits" into 2/3/4 posts when the site is built to public
1 input post is duplicated into 2/3/4 posts when the site is built to public but somehow each duplicate isn't an exact duplicate but instead has the whole post but certain parts of the post are hidden/invisible, via CSS, such that they represent the 2/3/4 "pages" of the post.
Or, is this something you do external to Hugo?
UPDATE: I can see I need to clarify this. Consider this random illustrative blog post - it is the third of three closely related posts, and even has a set of links at the top so you can find the earlier posts in the series. Lots of technical blogs do this sort of thing (at least the ones I read).
Now, I'm not looking for a CMS or anything complex. What I do now with Hugo is hugo new posts/an-article-about-constexpr.md and I write one markdown file and it becomes one "post" in standard Hugo fashion. Exactly what you want a SSG to do.
What I want to do is write one markdown file but have some kind of markup in it separating it into sections (like <!-- More --> on steroids) so that instead of generating one page of my site it generates three (in this example) - three separate articles with links from the main page in the "posts" section, etc. etc. And for bonus points, I'd like to generate these "table of contents" sections with links to each of the pages.
So I've been doing that with a cobbled-up awk script that generates pages right next to the post, in the posts directory. I set the post to draft so it doesn't get published, but the pages generated by the awk script have draft=false so they do get published. And the dates get set so they're "in order".
And that's working, but before I invest more time in my little script, I wanted to see if there was a proper way to do this within hugo.
Not sure what you mean by one-file->one-page model.
I have very few parts of any hugo site which one markdown file=one rendered html page.
Could just be the way I build, but everything I've done so far has been vanilla hugo.
To answer your question: Yes, you are correct that would work. There a few ways to do this (I list one below), but maybe a deeper look would be separating the concept of a "tool-chain" and what Hugo is in that tool chain, from a CMS, which Hugo is not.
So, to possibly answer your specific question though:
You can store content in markdown, markdown front matter, or a Data form (XML/JSON) in hugo. Using the page resources {{ .GetPage }} you can access any content and load it in any template or using shortcodes, load it in other markdown.
If I needed to do this as part of a tool chain, i.e. use specific markdown and re-use it in multiple places, I would create a front matter variable, or taxonomy or tag depending on what groupings I needed where, so this was scalable. params such as
"articleAuthor: Jessie P."
"date: DATE HERE"
"tags: etc. etc."
Then lets say I know that's going to be a blog, well fine, then it will be in the corresponding content folder, but if I needed all of Jessie's articles, or articles on that date, or that specific article, I would use the shortcode I make or directly in a template, using .GetPage Match - import the markdown pages I need based on the parameters I need.
But on the other hand, I would need to understand the problem being solved, but, here are a few hugo docs to help you out:
https://gohugo.io/functions/getpage/#readout
https://gohugo.io/content-management/page-bundles/
Remember, Hugo is not a CMS, it is a site generator. If you want a CMS, you can always use Wordpress headless, or any other solution out there.
(off the top of my head using page bundles)
{{ $headlessBundle := .Site.GetPage "/blogs/specific-blog/index" }}
{{ with $getContent := $headlessBundle.Resources.Match "intro.md" }}
{{ (index $getContent 0).Content }}
(You would use various "Where" statements to "filter" content based on the params or however you delineate what you want).
Or for instance if I wanted only the text that had an H1 tag:
{{ $.Scratch.Set "summary" ((delimit (findRE "(<h1.*?>.*?</h1>\\s*)+" .Content) "[…]") | plainify | replaceRE "&" "&" | safeHTML) }}
{{ $.Scratch.Get "summary" }}
Based on the update to the question:
https://discourse.gohugo.io/t/split-markdown-content-in-two-files-but-dont-render-shortcodes-as-raw-text/32080/2
https://discourse.gohugo.io/t/getting-a-list-from-within-a-shortcode/28126
https://discourse.gohugo.io/t/splitting-content-into-sections-based-on-header-level/33749
https://discourse.gohugo.io/t/multiple-content-blocks-on-a-single-page/9092/3
jrmooring answered it best in the above with clear examples and code.
Though, note: If I was doing this in a technical blog this would be integrated into the CMS and coordinated with the builder.

How to make Sphinx resolve URL links from e.g. /about-manual to /about-manual.html

I'm creating a Sphinx documentation and I struggle to identify the "proper" way to set up the structure and links.
STRUCTURE 1#
Currently, my structure looks as below:
index.rst
about-manual/index.rst
Inside my root index.rst, the toctree is as below:
===========================
Contents
===========================
.. toctree::
about-manual/index
This results in the below links:
https://example.com/docs/ --> Content of index.rst
https://example.com/docs/about-manual --> Content of about-manual/index.rst
This works as intended in terms of link resolution
However, I'm unsure if it's the "proper" way of setting up my Sphinx structure
STRUCTURE 2#
index.rst
about-manual.rst
Inside my root index.rst, the toctree is as below:
===========================
Contents
===========================
.. toctree::
about-manual
This results in the below links:
https://example.com/docs/ --> Content of index.rst
https://example.com/docs/about-manual --> ERROR
https://example.com/docs/about-manual.html --> Content of about-manual.rst
This results in a more compact/simple Sphinx structure
However, if a user enters an URL without explicit .html at the end, the link is broken
Am I missing a basic configuration setting in Sphinx in order to make the link resolution work as per my expectation with 'STRUCTURE 2#' - without having to add the explicit .html at the end?
And is it possible to avoid having the Sphinx documentation explicitly resolve to the index.html at the end of an URL path? It does this as expected on the root index, but in 'STRUCTURE 1#' all sub pages explicitly show the index.html at the end.
I've looked at html_file_suffix and html_link_suffix, but I've not been able to make these work for my purpose either.
I found a solution for this by using sphinx-build -b dirhtml instead of sphinx-build -b html (as proposed by Jesse Tan from the sphinx_rtd_theme team) - for details see this link.
It basically lets me use the approach in 'STRUCTURE 2#', but it builds the output with an index.html files structured in folders named as per the .rst files.
Importantly, the internal links are also updated to not include the index.html part.

2sxc Adam folder list

I have a problem with listing/showing Folders created within Adam's File Library?
I have dowloaded Adam 2.0 tutorial from your site
I can't get them listed even in downloaded template and example "Another one rides the bus". If I change template view "Adam example with groups (folders) I don't see any image at all.
I tried adding #screenshots.Folders.Count but I get value 0 even there are already 2 non-empty folders created in given example gallery.
For #screenshots.Files.Count I get 4 which is correct value for a root level.
I get no other errors.
Thanks!
I'm not sure if those examples are all still current. But if you check out the latest Blueimp that may help. See https://2sxc.org/en/apps/app/blueimp-gallery-slider-4-0-with-koi-bootstrap-3-and-4.

blogger - filtering archive list widget by labels

I have made a blogger site for a friend. She wanted 2 blogs on the one site which I managed to achieve using search and labels.
http://thewishingtreeandotherdreams.blogspot.co.nz/search/label/moon
http://thewishingtreeandotherdreams.blogspot.co.nz/search/label/blog
Now what I want to do is also filter the archive widget based on the above labels.
I know I will have to have a second archive widget so one shows only "moon" labeled posts and the other only shows "blog" labeled posts
My programming knowledge however is VERY limited. Has anyone else already done this. Do you have code you could share with me?
Here's a script with similar functionality but not include nesting by dates. Only copy and edit the next code into new HTML/JavaScript widget.
<script src="http://cloud.github.com/downloads/jhwilson/Create-a-Blogger-archive-page/Make-Blogger-Archive-Page.js"></script>
<script src="http://NAME_OF_YOUR_BLOG.blogspot.com/feeds/posts/default/-/LABEL_NAME?max-results=500&alt=json-in-script&callback=LoadTheArchive"></script>
If adds some CSS could be look better.

Resources