Hybrid Architecture 2.0: How I Automated the Intelligence of My Content Hubs

Automated English translation of the original Spanish article. Code examples keep their original identifiers.

In the previous article, I explained how I rescued my best articles from WordPress’s chronological graveyard using Hugo to build knowledge hubs. The result was a fast, clean, and well-organized /temas/ section.

Yet there was a problem I didn’t mention: every time I published a new post, I had to sit in front of my computer, run the script manually, and wait for Hugo to compile. If I was away from home or only had my phone, the Hubs remained outdated.

The content was dynamic. The architecture, too static.

The Right Question

I could have solved it with a webhook, a GitHub Action, or any CI/CD service. But the goal has always been the opposite: fewer external dependencies and more self-hosted control.

The question wasn’t “which service should I use?”. It was: “how do I make the server itself know when to rebuild?”

The Glue: Juredev Hubs Connector

The entire system hinges on one key piece of data: knowing which Hub each article belongs to. That information doesn’t exist in WordPress by default, so it has to be created.

The Juredev Hubs Connector plugin solves this using three WordPress hooks. The first adds a selector in each post’s sidebar editor. The second saves that choice as metadata upon publishing. The third automatically injects a banner at the end of the post linking back to the Hub.

The selector lists the ten available Hubs in the editor’s sidebar panel. When I save the post, the plugin writes the selected slug into wp_postmeta under the _juredev_selected_hub key. A minimalist piece of data that does exactly one thing.

The banner displayed at the end of each post uses rel="tag" on the link—a subtle semantic detail that reinforces the relationship between the article and its Hub for crawlers:

$banner_html = '<p class="post-series">
    Tema Relacionado: <a href="' . esc_url( $hub_url ) . '" rel="tag">' . esc_html( $hub_name ) . '</a>
</p>';

It’s worth noting that the plugin verifies three conditions before injecting the banner: it must be a single post page, it must be inside the main loop, and it must be the main query. Without these checks, the banner might appear in widgets, excerpts, or anywhere else WordPress renders content.

The Brain of the System: A SQL Query

Before tackling automation, I had to solve a more fundamental problem: what data does Hugo actually need?

The answer lies in SELECT-WP-POST.sql, a query that performs several tasks simultaneously. It extracts the title, date, slug, and excerpt for each post. It resolves the featured image by navigating the metadata table. It groups categories and tags using GROUP_CONCAT. And it handles something specific to this architecture: reading the _juredev_selected_hub field—the metadata written by the Juredev Hubs Connector plugin whenever I assign a post to a Hub in the WordPress editor.

(SELECT meta_value FROM wp_postmeta 
 WHERE post_id = p.ID 
 AND meta_key = '_juredev_selected_hub') AS hub_slug,

That line serves as the bridge between both systems. Without it, Hugo wouldn’t know which posts belong to which Hub.

There is also an editorial criterion to consider: posts tagged as Opinión (Opinion) are explicitly excluded. The Hubs are technical collections; opinions have their own place in the chronological feed. The query reflects this:

AND p.ID NOT IN (
    SELECT tr.object_id FROM wp_term_relationships tr
    INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
    INNER JOIN wp_terms t ON tt.term_id = t.term_id
    WHERE tt.taxonomy = 'post_tag' AND t.name = 'Opinión'
)

The Exporter: PHP Talking Directly to the Database

The export-wp-to-hugo.php script doesn’t use the WordPress REST API. It connects directly to the database, executes the SQL query, and dumps the result into data/posts.json, the file Hugo uses to build each Hub.

The reason for bypassing the API and going straight to the DB is simple: speed and control. There is no HTTP overhead, no authentication, and no plugins to interfere. The script reads, transforms, and writes:

$row['categorias'] = explode(', ', $row['categorias']);
$row['tags'] = explode(', ', $row['tags']);

Those two lines convert the GROUP_CONCAT strings into real arrays, which is the format Hugo expects in its templates.

The Watcher: Bash + WP-CLI + Cron

With the exporter ready, the next step was getting the server to decide when to run it. The solution is a Bash script that acts as a watcher, running every 15 minutes via cron:

*/15 * * * * /bin/bash /home/temasadmin/auto-deploy-hugo.sh

The logic is deliberately simple. The script queries WordPress for the ID of the latest published post:

ID_ACTUAL=$(wp post list --post_type=post --post_status=publish \
  --posts_per_page=1 --field=ID \
  --path=$PATH_WP --skip-plugins --skip-themes --allow-root)

It compares this ID against the last recorded ID stored in a plain text file. If the number has increased, there is new content. If not, it does nothing and the server stays idle. No unnecessary polling, no HTTP requests, and no external dependencies.

When it detects a new ID, it triggers the full chain:

/usr/bin/php export-wp-to-hugo.php    # Actualiza el JSON desde la DB
/usr/local/bin/hugo --gc --minify           # Recompila el sitio estático
/usr/bin/rsync -avzh --delete public/ $WEB_DIR/  # Sincroniza solo lo que cambió
chown -R www-data:www-data $WEB_DIR     # Ajusta permisos
echo $ID_ACTUAL > $LAST_ID_FILE         # Registra el nuevo ID

Everything is recorded in a timestamped log. If anything fails, full traceability is preserved.

The complete workflow looks like this:

flowchart TD
    WP[(WordPress DB)] -- Publicas un Post --> WP
    Cron[Cron cada 15min] -- Chequea ID --> WP
    Cron -- "ID nuevo detectado" --> Export[PHP Export]
    Export --> JSON[(posts.json)]
    JSON --> Hugo[Hugo Build]
    Hugo --> Deploy[rsync a /temas/]
    Deploy --> Live((Sitio Actualizado))
    

What Changed in Practice

Previously, I would publish an article and then have to return to my computer to update the Hubs. Now I can publish from anywhere—my phone, a tablet, or any browser—and in under 15 minutes the Hubs update automatically, with the article properly assigned to its Hub, complete with all metadata, without me lifting another finger.

A hybrid architecture isn’t just about decoupling frontend from backend. It’s about designing an ecosystem where each tool does exactly what it does best: WordPress manages the content, PHP extracts the data, Hugo compiles the pages, and rsync handles synchronization. No single tool steps on another’s toes.

And when concerns are cleanly separated, automating them becomes trivial.