Importing Old Blog Posts with AI

After transforming my blog into a personal idea incubator, I faced an interesting challenge: importing nearly two decades worth of blog posts from my old WordPress site. I could have done this manually, copy-pasting each post, reformatting the content, downloading images… but that sounded tedious. Instead, I decided to automate the entire process using scripts and GitHub Copilot CLI.

The Automation Process

The key to this automation was creating a chain of commands that worked together:

  1. A bash script that iterates through a list of old post URLs
  2. GitHub Copilot CLI that receives instructions and executes them
  3. An instruction file that tells Copilot exactly how to import posts
  4. Automated UI tests that verfify that every page is rendering correctly

The beauty of this approach is that each component does what it does best. The bash script handles iteration and orchestration, Copilot handles the complex decision-making and content transformation, and the instruction file ensures consistency.

The Script

Here’s the excerpt from the import script:

function import_prompt() {
    local post="$1"
    cat <<EOF
Please import the following blog post: $post
Follow the instructions in docs/IMPORTING.md
If there are any issues try again with a slightly different approach and update the IMPORTING.md file if needed, but keep it concise.
Make sure to run the playwright tests after importing.
EOF
}

for post in "${posts[@]}"; do
    echo "Importing $post"
    copilot -p "$(import_prompt "$post")" --allow-all-tools --add-dir . --add-dir /tmp
    git add .
    git commit -am "automatically imported $post"
    git push
done

This script does several clever things:

  • Maintains a list of post URLs to import
  • Generates a prompt for each post that references the instruction file
  • Invokes Copilot CLI with the generated prompt for this post
  • Automatically commits each imported post with a descriptive message
  • Improves the instructions by analysing the importing experience and any issues detected

Notice the line If there are any issues try again with a slightly different approach and update the IMPORTING.md file if needed, but keep it concise. This makes sure that our importing agent is an evolving agent in a similar sense to what I described in Evolving Agent System

The Instruction File

The instruction file is crucial because it provides Copilot with a step-by-step guide. Here is a shorter version of the instructions file:

## How to Import a Blog Post

1. **Copy the Example Post**
  - Use `src/content/blog/_template.mdx` as a reference
  - The post filename must follow `YYYY-MM-DD-slug.mdx` format
  - Verify that the text matches the original post

2. **Download Images**
  - Create a dedicated folder named `YYYY-MM-DD-slug-images`
  - Use `wget` to download images from the original post

3. **Import Images in MDX**
  - Import images at the top of the MDX file
  - Use the imported variable in markdown

4. **Register the Post**
  - Add an entry to `src/utils/blog.js` in the `blogPosts` array
  - The `slug` must match the filename

5. **Run the playwright tests**
  - Ensure the post renders correctly
  - All tests should pass, including image loading tests

The real file also includes specific instructions for extracting content from WordPress using Python and regex, handling code blocks, converting HTML entities, and more. This ensures consistency across all imported posts.

Interactive Transformations

One of the most exciting aspects of this import process was the opportunity to transform some old static posts into interactive React components. The new site supports both traditional MDX posts and fully interactive JSX components.

Here are a couple of pages that have been converted:

Any imported post could potentially be enhanced this way. Instead of just describing a concept, I can now let readers interact with it directly. The posts themselves become tiny applications, making the blog a true “idea incubator” rather than just a content archive.

How It Works End-to-End

Here’s what happens when I run the import script:

  1. The script starts and picks the first URL from the list
  2. Copilot receives the prompt with the URL and instruction file reference
  3. Copilot downloads the WordPress HTML using curl
  4. Content is converted from HTML to MDX format with proper frontmatter
  5. Images are downloaded using wget to a dedicated folder
  6. Image imports are added to the MDX file
  7. The post is registered in src/utils/blog.js with metadata
  8. Playwright tests run to verify the post renders correctly
  9. Changes are committed and pushed automatically
  10. The instructions file is updated based on any issues encountered
  11. The script moves to the next URL and repeats

The entire process is now hands-off. It took a couple of attempts to get it right, but now I can add 20 URLs to the script, run it once, and come back to find all 20 posts imported, tested, and deployed. Each with a different commit for easier review and cherry picking.

Generalizing the Approach

This pattern of “script → AI CLI → instruction file” is incredibly powerful and can be applied to many other scenarios. I talked more about this in (How to Easily Create AI Agent Workflows)[/blog/2025-08-04-how-to-easily-create-ai-agent-workflows].

The key insight is that AI excels at individual tasks when given clear instructions, while scripts excel at orchestration and repetition. By combining them, you get the best of both worlds: the reliability and consistency of automation with the intelligence and adaptability of AI. Furthermore the iterative process with a feedback loop makes it easier to

If you’re sitting on a pile of content that needs to be migrated, transformed, or updated, consider this approach. You might be surprised at how much you can automate with a simple script, clear instructions, and an AI assistant that knows how to follow them.

© 2025 Jaksa Vuckovic. Built with SvelteKit