Cannot add a new post

I got an explanation how to add a post:
Add a blog post using the npm run create command.

Example

npm run create blog/say-hello-to-doks/index.md
But there is already one index.md and I do not need another index.md, so I changed the command like that:
npm run create blog/say-hello-to-doks/test.md
But after that no matter how many posts I would create, nothing was appeared on the website. What is going on? How to create a new post?

When you create a file named index.md in a directory, that directory becomes a Leaf Bundle. Other files within the same directory become Page Resources.

If you want a directory to have multiple pages, either remove the index.md file to have a generic list page, or replace the index.md file with an _index.md file.

A directory with an _index.md file is a Branch Bundle.

`

I deleted index.md. After that only one of my three test pages appeared, but all the Blog page lost its design:

I’d just be guessing. Can you share a repository?

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Looks fine to me…

git clone --recurse-submodules https://github.com/SingingFoot/techwriter
cd techwriter/
npm ci
hugo server
                   | EN  
-------------------+-----
  Pages            | 31  
  Paginator pages  |  0  
  Non-page files   |  1  
  Static files     | 90  
  Processed images |  0  
  Aliases          |  1  
  Sitemaps         |  1  
  Cleaned          |  0  

Ah! I’ve got it! I thought, that every new post in Blog page is just a new .md file and all. But in reality I need to create a new folder for every new post in Blog page and in every new folder must have the same index.md file (or not the same - I do not understand it). This index.md file is like a sceleton. Though I do not understand why do I need to create some md files except this index.md file: I cannot see them anyway.

I made it, but it does not help. Blog page is still crashed.

You can do this:

content/
└── blog/
    β”œβ”€β”€ post-1.md  <-- regular page
    β”œβ”€β”€ post-2.md  <-- regular page
    └── post-3.md  <-- regular page

Or this:

content/
└── blog/
    β”œβ”€β”€ _index.md  <-- section/list page (branch bundle)
    β”œβ”€β”€ post-1.md  <-- regular page
    β”œβ”€β”€ post-2.md  <-- regular page
    └── post-3.md  <-- regular page

Or this:

content/
└── blog/
    β”œβ”€β”€ post-1/
    β”‚   └── index.md  <-- regular page (leaf bundle)
    β”œβ”€β”€ post-2/
    β”‚   └── index.md  <-- regular page (leaf bundle)
    β”œβ”€β”€ post-3/
    β”‚   └── index.md  <-- regular page (leaf bundle)
    └── _index.md     <-- section/list page (branch bundle)

Or mix them together

content/
└── blog/
    β”œβ”€β”€ post-1/
    β”‚   └── index.md  <-- regular page (leaf bundle)
    β”œβ”€β”€ _index.md     <-- section/list page (branch bundle)
    β”œβ”€β”€ post-2.md     <-- regular page
    └── post-3.md     <-- regular page

2 Likes

Update baseurl in ./config/_default/config.yml

You have draft: true in most of your content. That’s OK, just make sure you tell Hugo to include draft content when you build or run the server:

hugo -D
hugo server -D

I did like in the first variant, and the page disappeared at all:

It ruined even the first page at all.

Please push your changes to the repo, then stop.

Let me pull the changes, take a look, and I’ll get back to you.

I pulled your changes at 2021-11-07T15:21:47-08:00, then ran hugo server -D.

Error: Error building site: β€œ/home/jmooring/temp/techwriter/content/en/blog/post2.md:13:1”: failed to render shortcode β€œimg”: failed to process shortcode: β€œ/home/jmooring/temp/techwriter/layouts/shortcodes/img.html:2:18”: execute of template failed: template: shortcodes/img.html:2:18: executing β€œshortcodes/img.html” at <$image.Resize>: nil pointer evaluating resource.Resource.Resize

It’s telling me there’s a problem on line 13, column 1 of content/blog/post2.md:

{{< img src="post2.jpg" alt="Post2" caption="Post2" class="wide" >}}

It’s telling me that here’s a problem on line 2, column 18 of layouts/shortcodes/img.html:

{{ $lqip := $image.Resize $.Site.Params.lqipWidth -}}

It’s telling me that the problem is:

nil pointer evaluating resource.Resource.Resize

So, it can’t find the image (Page Resource) that it is trying to resize. Why? Because page resources are available to Leaf Bundles and Branch Bundles, and content/blog/post2.md is neither.

You can fix this by:

  1. Removing the shortcode call from content/blog/post2.md, OR
  2. Change your structure and create some images.
hugo new content/en/blog/post2/index.md
content/en/blog
β”œβ”€β”€ post2/
β”‚   β”œβ”€β”€ index.md
β”‚   └── post2.jpg
β”œβ”€β”€ post1.md
└── post3.md

Now run hugo server -D again and continue to resolve the errors. You’ll end up with:

content/en/blog/
β”œβ”€β”€ post1/
β”‚   β”œβ”€β”€ index.md
β”‚   └── post1.jpg
β”œβ”€β”€ post2/
β”‚   β”œβ”€β”€ index.md
β”‚   └── post2.jpg
└── post3/
    β”œβ”€β”€ index.md
    └── post3.jpg

2 Likes

Thanks! You are very helpful! That was the night, so I made a break. Now I will try again.