Brian Strickland

ServiceNow Platform Manager | Product Owner | AI Enthusiast | Developer | CISSP

Migrated to Hugo and Implemented a Secure GitHub-Powered Publishing Workflow

June 2, 2025

Today, I undertook a comprehensive overhaul of my personal blog infrastructure. The primary objectives were to migrate the site from static HTML to Hugo for enhanced flexibility and to establish a secure, automated publishing pipeline leveraging Azure Functions and GitHub.

Transitioning to Hugo

The initial setup of my blog was based on static HTML pages hosted via Azure Static Web Apps. While functional, this approach lacked scalability and ease of content management. To address these limitations, I transitioned the site to Hugo, a fast and flexible static site generator.

Key steps in the migration included:

  • Configuring config.toml to define the base URL, theme, and section layouts.
  • Developing a custom layouts/index.html template to dynamically display blog post summaries.
  • Organizing all blog posts under the content/blog/ directory, utilizing Markdown files with YAML front matter for metadata.
  • Eliminating the manually maintained index.html in favor of Hugo's automatic content listing capabilities.

This migration not only streamlined content management but also laid the groundwork for future enhancements such as tagging, categorization, and improved search functionality.

Establishing a Secure Publishing API

To facilitate seamless content updates without manual Git operations, I developed an Azure Function that serves as a secure API endpoint for publishing new blog posts.

The API operates as follows:

  • Endpoint: /api/new-blog-post
  • Authentication: Validates requests using an x-api-key header.
  • Input: Accepts a JSON payload containing title, content (in HTML), and optional slug and date fields.
  • Processing:
    • Generates a filename in the format content/blog/YYYY-MM-DD-HHMM-slug.md.
    • Converts the HTML content to Markdown, embedding it within YAML front matter.
    • Commits the new file to the GitHub repository using the GitHub API.

This setup enables content publication through a simple API call, eliminating the need for direct interaction with Git or the Hugo CLI.

Handling Deployment and Automation

Initially, I configured the API to trigger a GitHub Actions workflow (deploy.yml) post-commit to automate the deployment process. However, I observed that Azure Static Web Apps automatically redeploys the site upon detecting changes in the repository. Consequently, I removed the explicit workflow trigger from the API, simplifying the deployment pipeline.

Challenges and Resolutions

During the implementation, several issues arose:

  • Future-Dated Posts: Posts with a date set in the future were not rendered by Hugo. To resolve this, I ensured that the API assigns the current date and time in the Eastern Time Zone when no date is provided.
  • Markdown Rendering Issues: Improperly formatted YAML front matter led to rendering problems. This was corrected by standardizing the front matter structure and ensuring proper file extensions.
  • GitHub API Errors: Encountered 404 errors when attempting to trigger non-existent workflows. Recognizing that automatic deployment was already handled by Azure, I removed the redundant workflow triggers.

Outcome

With these enhancements, the blog now supports efficient content management and publication through a secure, automated pipeline. The integration of Hugo, Azure Functions, and GitHub streamlines the workflow, allowing for rapid content updates without manual intervention.

Future Enhancements

Planned improvements include:

  • Implementing image upload capabilities via the API.
  • Adding support for tags and categories to enhance content organization.
  • Developing archive views and changelog tracking features.
  • Integrating AI tools to assist with content creation and summarization.

This project marks a significant step toward a fully automated and maintainable blogging platform.


Comments

Loading comments...

Leave a Comment