Skip to content
Go back

How to Create SEO-Optimized Blog Posts with Hugo Paper's New-Post Script

Creating blog posts with proper SEO optimization can be time-consuming. Hugo Paper’s new-post script automates this process, helping you create well-structured, SEO-friendly posts in seconds.

Table of Contents

Why Use the New-Post Script?

Traditional blog post creation requires manually setting up frontmatter with numerous SEO fields. The new-post script streamlines this by:

Prerequisites

Before using the script, ensure you have:

# Check Node.js version (18.0+)
node --version

# Check pnpm version (8.0+)
pnpm --version

# Install dependencies if needed
pnpm install

Two Ways to Create Posts

Hugo Paper provides two scripts for different workflows:

The new-post script provides an interactive experience with prompts for all fields:

# Basic usage
pnpm new-post

# With title
pnpm new-post "Getting Started with Hugo"

# With title and language
pnpm new-post "Hugo Getting Started Guide" en

2. Quick Mode

The quick-post script uses sensible defaults for rapid post creation:

# Quick English post
pnpm quick-post "My Article Title"

# Quick Chinese post
pnpm quick-post "My Article Title" en

Step-by-Step: Using New-Post

Step 1: Run the Command

pnpm new-post "How to Build a Hugo Blog"

Step 2: Follow the Prompts

The script will ask for:

1. Slug (URL-friendly identifier)

Enter slug (press Enter for auto-generated): 
→ how-to-build-hugo-blog

Best practices:

2. Description (150-160 characters)

Enter description (150-160 chars for SEO): 
→ Learn how to build a professional blog with Hugo static site generator. 
  Step-by-step guide with examples and best practices.

Best practices:

3. Keywords (comma-separated)

Enter keywords (comma-separated, 3-5 recommended): 
→ hugo, static-site-generator, blog-tutorial, web-development

Best practices:

4. Author

Enter author name: 
→ John Doe

5. Categories (comma-separated)

Enter categories (comma-separated): 
→ Tutorial, Web Development

Best practices:

6. Tags (comma-separated)

Enter tags (comma-separated, 5-10 recommended): 
→ hugo, jamstack, static-site, blogging, tutorial, beginner-friendly

Best practices:

7. Featured Post

Is this a featured post? (y/n): 
→ y

Featured posts appear prominently on your homepage.

8. Draft Status

Is this a draft? (y/n): 
→ n

Set to y for unpublished posts.

Step 3: Edit Your Post

The script creates a file at:

content/en/post/how-to-build-hugo-blog.md

Open it and start writing:

---
title: "How to Build a Hugo Blog"
slug: "how-to-build-hugo-blog"
description: "Learn how to build a professional blog with Hugo..."
date: 2024-11-15T10:00:00+08:00
lastmod: 2024-11-15T10:00:00+08:00
author: "John Doe"
keywords:
  - hugo
  - static-site-generator
  - blog-tutorial
categories:
  - Tutorial
tags:
  - hugo
  - jamstack
featured: true
draft: false
---

## Introduction

Your content starts here...

Quick-Post for Rapid Creation

When you need to create posts quickly without interactive prompts:

# Creates post with default values
pnpm quick-post "Quick Article Title"

Default values:

When to use quick-post:

Multilingual Post Creation

Creating Chinese Posts

# Interactive Chinese post
pnpm new-post "Hugo Blog Setup Guide" zh

# Quick Chinese post
pnpm quick-post "My Article" zh

The script automatically:

Language-Specific Best Practices

English posts:

Chinese posts:

SEO Optimization Tips

1. Title Optimization

Good titles:

Poor titles:

Best practices:

2. Description Optimization

Good descriptions:

Learn how to build a professional blog with Hugo static site generator. 
This step-by-step guide covers installation, configuration, and deployment 
with practical examples.

Poor descriptions:

This is a post about Hugo.

Best practices:

3. Keyword Strategy

Keyword research:

  1. Use Google Keyword Planner
  2. Check competitor keywords
  3. Use Google autocomplete
  4. Check “People also ask”

Keyword placement:

4. URL Structure

Good slugs:

Poor slugs:

Advanced Usage

Custom Templates

Create custom post templates by modifying the script:

// scripts/new-post.ts
function generatePostContent(metadata: PostMetadata): string {
  return `## Introduction

Write your introduction here...

## Main Content

### Section 1

Content...

### Section 2

Content...

## Conclusion

Wrap up your post...

## References

- [Link 1](https://example.com)
- [Link 2](https://example.com)
`;
}

Batch Post Creation

Create multiple posts with a shell script:

#!/bin/bash
# create-posts.sh

posts=(
  "First Post Title"
  "Second Post Title"
  "Third Post Title"
)

for post in "${posts[@]}"; do
  pnpm quick-post "$post"
done

Integration with CI/CD

Automate post creation in your workflow:

# .github/workflows/create-post.yml
name: Create Post

on:
  workflow_dispatch:
    inputs:
      title:
        description: 'Post title'
        required: true

jobs:
  create:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
      - run: pnpm install
      - run: pnpm quick-post "${{ github.event.inputs.title }}"
      - uses: stefanzweifel/git-auto-commit-action@v4

Troubleshooting

Script Not Found

Error: Cannot find module 'scripts/new-post.ts'

Solution:

# Ensure you're in the theme directory
cd hugo-theme-paper

# Install dependencies
pnpm install

Permission Denied

Error: EACCES: permission denied

Solution:

# Make script executable (Unix/Mac)
chmod +x scripts/new-post.ts

# Or run with tsx directly
npx tsx scripts/new-post.ts

Invalid Date Format

Error: Invalid date format

Solution: The script uses ISO 8601 format automatically. If you see this error, check your system timezone settings.

Best Practices Checklist

Before publishing, ensure:

Comparison: Manual vs Script

AspectManual CreationNew-Post Script
Time5-10 minutes30 seconds
SEO fieldsOften forgottenAlways included
ConsistencyVariesUniform
ErrorsCommonRare
Learning curveLowVery low
FlexibilityHighHigh

Next Steps

Now that you know how to create posts efficiently:

  1. Read the SEO guide - Learn advanced SEO optimization
  2. Configure OG images - Set up dynamic social media images
  3. Customize templates - Modify the script for your needs
  4. Create content - Start writing amazing posts!

Conclusion

The new-post script is a powerful tool that saves time and ensures SEO best practices. By automating frontmatter creation, you can focus on what matters most: creating great content.

Start using it today and experience the difference in your content creation workflow!


Questions or feedback? Open an issue on GitHub or join our discussions.


Edit page
Share this post on:

Previous Post
Dynamic OG Image Generation in Hugo Paper
Next Post
Dynamic OG Image Generation in Hugo Paper: Boost Social Media Engagement