WordPress and a wiki to one Sphinx build

Note

TL;DR

  • We merged www.amarulasolutions.com (WordPress) and wiki.amarulasolutions.com (Sphinx) into one Sphinx project: 99 posts, 26 project pages, 36 team profiles and 273 documentation pages.

  • The result is a static site with no PHP, MySQL or plugin stack at runtime. Content lives in Git, and a local Decap CMS keeps the editing workflow approachable.

  • The hard parts were preserving legacy URLs, converting WordPress HTML and media, and replacing the one dynamic feature (the forms) with a small self-hosted service.


The Starting Point

The old site was two products with two lifecycles. WordPress served the corporate pages, blog, projects and team profiles from PHP and MySQL, with a theme, a plugin stack and a public admin panel. The developer wiki was a separate Sphinx project, built from Git and deployed beside it. Both worked, but nothing was shared: typography, navigation, search, backups, deploy paths and review process all existed twice.

We wanted one static build without giving up three things:

  1. Existing URLs and search rankings. WordPress tags, pagination, LearnPress course pages and media files were all public addresses.

  2. A friendly editing interface. The marketing team should not need to hand-write Markdown, RST or front matter to publish a post or update a team profile.

  3. A rollback path. If the cutover went wrong, the old site had to remain reachable while we fixed it.

The forms were the only feature that genuinely needed a server. They became the one explicit dynamic service instead of a reason to keep a CMS runtime.


Target Architecture

The new site is one Sphinx project with three content dialects:

  • Corporate pages at the repository root, in reStructuredText.

  • Marketing content under blog/ and team/, in Markdown with YAML front matter and a few MyST directives.

  • Technical documentation under docs/, in reStructuredText and served under /docs/.

The dirhtml builder produces the trailing-slash URLs the old sites used. A local theme under _themes/amarula inherits sphinx_rtd_theme and shares one navbar, footer, search box and typography across marketing pages and documentation.

.
├── index.rst                 # corporate homepage
├── blog/                     # 99 Markdown posts
├── team/                     # 36 team profiles
├── docs/                     # 273 RST documentation pages
├── _ext/                     # blog, team, SEO, llms.txt, forms
├── _themes/amarula/          # shared local theme
├── _templates/               # navbar, footer and layout overrides
├── tools/                    # migration, guard, link and SEO checks
└── infra/                    # nginx/Apache rules and the form service

The custom extensions are deliberately small. amarula_blog reads front matter, orders posts and renders the archive and category filters. amarula_team builds the roster and profile pages. amarula_content inserts the publication date, hero image and caption from the front matter. amarula_seo adds metadata and JSON-LD, and amarula_llms writes llms.txt at build time.


Migrating the Content

The WordPress export was a one-off build tool, not a live dependency: tools/wp_migrate/migrate.py. The pipeline was:

  1. Read the WordPress sitemaps and REST API for pages, posts, team and categories. The projects post type was not exposed through REST, so it was crawled from /projects/.

  2. Cache the raw JSON and HTML in tools/wp_migrate/cache/.

  3. Extract each article body, rewrite images and internal links, convert the HTML with Pandoc, and post-process the resulting RST.

  4. Download the referenced media into _static/site/ with unique, hash-prefixed names.

  5. Write _data/wp_snapshot.json and _data/wp_asset_manifest.json for provenance.

  6. Regenerate the blog, project, team and services indexes.

  7. Write infra/apache/media-redirects.conf for the old media URLs.

The marketing sources were then converted from RST to Markdown with tools/convert_marketing_to_myst.py. That step needed an isolated environment pinned to rst-to-myst[sphinx]==0.4.0 because those pins conflict with the site’s Sphinx 7 environment:

python3 -m venv /tmp/rst2myst-venv
/tmp/rst2myst-venv/bin/pip install 'rst-to-myst[sphinx]==0.4.0'
RST2MYST=/tmp/rst2myst-venv/bin/rst2myst \
  .venv/bin/python tools/convert_marketing_to_myst.py

Both scripts are now frozen. The WordPress migration would recreate .rst sources, explicit toctrees and the old team exclusion list, which would produce duplicate docnames against the current Markdown tree. The script refuses to run when Markdown marketing files exist unless --allow-legacy-migration is passed. It is kept for provenance, not as a routine tool.

Before cutover the process is deliberately conservative: freeze WordPress, run migrate.py --refresh one final time, review the diff, then run the full build and link check before deploying.


Keeping URLs Alive

URL preservation was the part most likely to fail silently. Three mechanisms cover it:

Trailing-slash URLs. The dirhtml builder writes /blog/from-wordpress-to-sphinx/ rather than /blog/from-wordpress-to-sphinx.html. The old WordPress and wiki shapes therefore continue to match.

Canonical overrides. Legacy duplicate pages are listed in canonical_overrides in conf.py. The same list drives the Apache and nginx 301 rules and tests/test_redirects.py, which fails if the three copies drift apart.

Explicit redirect rules. infra/apache/redirects.conf and infra/nginx/redirects.conf cover WordPress tags, pagination, LearnPress course URLs, /careers/ and /job-opportunities/. A generated media-redirects.conf preserves the old upload paths. The old wiki .html URLs redirect to their /docs/ equivalents, and wiki.amarulasolutions.com becomes a permanent redirect to /docs/.

Two details that are easy to miss:

  • Sphinx 7.2.6 builds canonical URLs for dirhtml as <base>/<docname>.html. A small html-page-context hook in conf.py rewrites the page URL from the builder’s target URI.

  • The staging host carries X-Robots-Tag: noindex, nofollow until cutover. The header must be removed from the host that becomes www; otherwise the new site is invisible to search engines.


A Build With Gates

Nothing reaches production without passing make check, which runs four gates:

  • Content guard. Front matter, folder-derived category, title and description lengths, H2-only bodies, balanced MyST fences, the canonical CTA, root-relative links and local images with alt text. It also rejects raw HTML and leftover RST.

  • Warning-free build. sphinx-build must complete with no warnings.

  • Link checker. Every internal, same-host and mailto: link is resolved against the built output. The current build checks more than 51,000 internal links.

  • SEO checker. Meta descriptions, canonical and Open Graph URLs, Organization JSON-LD, llms.txt, sitemap <lastmod> and the absence of a published _sources/ directory.

.venv/bin/sphinx-build -b dirhtml -d _build/check-doctrees \
  -W --keep-going . _build/check

The content guard is deterministic and applies only a narrow set of safe fixes: whitespace, bare URLs, escaped alt text, malformed directive options and similar mechanical problems. It never rewrites prose, titles, descriptions or images. A pre-push hook runs the guard on exactly the files being pushed, prints the resulting diff and stops the push so the diff can be reviewed and committed.

Layout gets the same treatment. Playwright renders representative pages at phone, tablet, desktop and 4K widths and checks for horizontal overflow, missing images, broken blog/team structure, an unreadable prose measure and the documentation sidebar. The wide checks run at 1920, 2560, 3440 and 3840 pixels.

The documentation PDFs are built from the same sources as the HTML, so the PDF and the website cannot silently disagree.


Static Deployment

The build output is a directory of HTML, CSS, JavaScript and media. Jenkins runs the tests and make check, then rsyncs the built artifact to the Plesk host. The server does not run PHP, connect to a database or load a plugin per request.

The only dynamic endpoint is the form service. The amarula-form directive renders ordinary HTML forms for contact, quotation and job applications; they post same-origin to /forms/, a small self-hosted service that validates the request and sends an email to the relevant role inbox. It keeps no database and stores no submissions: uploads are sent as attachments. When no endpoint is configured, the form renders disabled with a mailto: fallback rather than pretending to work.

Analytics is consent-gated and loaded only on the production hosts. Local and test builds never load the Google tag.

Rollback is the previous artifact. The old document root stays available until ordinary traffic has flowed through the new site, and the WordPress installation remains reachable during the transition for a final delta migration if needed.


SEO, Search and AI Assistants

The SEO extension runs at build time and adds:

  • meta descriptions, canonical URLs, Open Graph and Twitter Card tags;

  • JSON-LD for the organization, the website, blog posts, people and technical articles;

  • a sitemap with <lastmod> values taken from the front matter date or the last Git commit, with utility pages and duplicate URLs removed;

  • noindex on utility pages such as search, 404 and the generator index;

  • llms.txt, a concise map of the site’s important pages for AI assistants.

Sphinx’s own search index covers both the marketing pages and the technical documentation, so there is one search box rather than two. Legacy redirects protect the link equity of the old URLs, and the canonical overrides prevent duplicate copies of the same article from competing in search results.


The Editor Workflow

The migration did not remove the CMS. It moved it to the editor’s machine. Decap CMS runs locally with decap-server, reads the collections for company posts, news, events and team profiles, and writes Markdown files directly into the checkout. A live preview rebuilds as the editor types. The admin bundle is excluded from the site build and is never deployed.

New Markdown files are picked up by hidden :glob: toctrees, so adding a post does not require editing an index. The blog archive, homepage cards, category counts and team grids update on the next build.

The trade-off is explicit: publishing is a Git commit and a push. That is normal for engineers and acceptable for the marketing team because the local CMS provides the form, the image upload and the preview. In exchange, every change has a diff, an author, a review path and a rollback.


What We Learned

  1. Inventory before migrating. Count every post type, every media file and every public URL shape. The redirect map is easier to build from an inventory than from a list of 404s after launch.

  2. Test redirects against the configs, not just the running site. The drift test between conf.py, Apache and nginx caught rules that would otherwise have rotted independently.

  3. Treat content as code from day one. Front matter validation, link checks and the pre-push guard are cheaper than fixing broken pages after publication.

  4. Keep an editing UI, but not in production. A local CMS gives editors the interface they expect without exposing an admin panel and a plugin stack to the internet.

  5. Freeze the source and run a final delta migration. A migration that runs while content is still being edited will always be incomplete.

  6. Keep the old environment until traffic has flowed. The old document root and WordPress installation cost little to leave in place and turn a bad surprise into a rollback.

  7. Budget for media. WordPress uploads are messy: duplicates, resized variants, uppercase names and remote images. Hash-prefixed local copies plus redirect rules are simpler than preserving the original paths.


Results

Migration results

Metric

Result

Marketing posts

99

Project pages

26

Team profiles

36

Documentation pages

273

Runtime dependencies

static files only

Build gates

content, build, links, SEO

Internal links checked

more than 51,000

The site is smaller to operate, but the more important change is the workflow: a change is reviewed like code because it is code.


Tip

Planning a similar move from a CMS to a static documentation stack? Amarula Solutions builds developer portals, CI/CD pipelines and embedded Linux infrastructure. Contact our engineering team

For the short version of this migration story, read the blog announcement.