Learn how to add a post to the site using Hugo. Also, explore how Hugo handles draft content, and how to preview drafts using the Hugo server.
- [Instructor] Like everything else with hugo, adding new content to a hugo site starts in the terminal. Inside of my project folder, I can run hugo new post/hello-world.md. This creates a new file, which I can see in my editor, in the content folder, post sub folder and finally, hello-world.md, the file I just created. The filename, hello-world becomes the URL of the new post and it typically follows the title of the post.
MD stands for markdown, which is the language you'll use to add formatting to your post and pages. If you're not familiar with markdown, you can visit markdowntutorial.com to get a quick lesson. I'll go ahead and edit the title of this post a little bit and then add some content. Now, let's run the hugo server again to preview the site with this new post. I'll save this file and then in my terminal, run hugo server. When I open up a browser and go to local host, the new post does not show up.
This isn't a bug. The reason the new post didn't show up is because it's marked as a draft. You can see this at the top of the new file, draft equals true. Drafts let you work on post and preview post before they go live on your site. This whole section at the top of the file is called front matter. And I'll explain more about it in a bit. For now, we're not going to change anything there. Instead, in my terminal, I'm going to cancel the hugo server with Control + C and then run hugo server again, but this time with the dash D flag.
Dash D here, tells hugo server to render the drafts as well. So, now when I go to the browser and refresh, I'll see the new post that I created. Next, I'll take a closer look at that front matter section at the top of the file.
- How static sites work
- Advantages of static sites
- Tools for building static sites
- Installing Hugo and Git
- Creating a new Hugo site
- Building a website
- Setting up a deployment pipeline
- Deploying and testing a site