Migrate vicihost.com off WordPress to Astro

Same approach as the vicidial.com migration: 58 pages, 6 posts, 41
attachments and the 4-item nav exported from wordpress_vicihost via
scripts/export-wp.mjs, with the layout and styling ported from this
site's own copy of the small-business theme.

That theme copy is not identical to vicidial's -- it carries the red
VICIhost palette, its own meta description, and shows 6 slides rather
than 5 (smallbusiness_ppp) -- so the CSS and slideshow are ported from
it rather than shared with the other site.

The export script gained handling for custom-link menu items, which this
menu uses for its "Home" entry and vicidial's did not.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 19:50:37 -04:00
co-authored by Claude Opus 5
commit e8f276f427
244 changed files with 7545 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
# Normalise text to LF in the repository and on checkout. global.css was ported
# from the WordPress theme with CRLF endings and has been renormalised.
* text=auto eol=lf
# Migrated WordPress uploads and other binaries: never diff, merge or touch endings.
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.webp binary
*.pdf binary
*.mp4 binary
# Generated by npm, and pure noise in review.
package-lock.json -diff linguist-generated=true
+26
View File
@@ -0,0 +1,26 @@
# Build output. Apache serves /srv/www/vhosts/vicidial/dist directly from disk,
# so this is regenerated in place by `npm run build` and never committed.
dist/
# Generated types and caches
.astro/
node_modules/
# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Credentials. scripts/export-wp.mjs takes WP_DB_USER / WP_DB_PASSWORD from the
# environment, so keep any local .env holding those out of the repo.
.env
.env.*
# Editor and OS noise
.vscode/
.idea/
*.swp
.DS_Store
Thumbs.db
+5
View File
@@ -0,0 +1,5 @@
// @ts-check
import { defineConfig } from 'astro/config';
// https://astro.build/config
export default defineConfig({});
+4273
View File
File diff suppressed because it is too large Load Diff
+23
View File
@@ -0,0 +1,23 @@
{
"name": "vicidial",
"type": "module",
"version": "0.0.1",
"engines": {
"node": ">=22.12.0"
},
"scripts": {
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@splidejs/splide": "^4.1.4",
"astro": "^7.3.2",
"mysql2": "^3.24.4",
"turndown": "^7.2.4"
},
"allowScripts": {
"esbuild": true
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

+2
View File
@@ -0,0 +1,2 @@
User-Agent: *
Allow: /
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

+269
View File
@@ -0,0 +1,269 @@
#!/usr/bin/env node
// One-time (re-runnable) export of the WordPress content into Astro content collections.
// Requires read-only DB creds via env vars: WP_DB_USER, WP_DB_PASSWORD
// (host/db default to the known wordpress_vicidial instance, override via WP_DB_HOST/WP_DB_NAME).
//
// WP_DB_USER=viciadmin WP_DB_PASSWORD=... node scripts/export-wp.mjs
import mysql from 'mysql2/promise';
import TurndownService from 'turndown';
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, '..');
const DB_HOST = process.env.WP_DB_HOST || '192.168.202.2';
const DB_USER = process.env.WP_DB_USER;
const DB_PASSWORD = process.env.WP_DB_PASSWORD;
const DB_NAME = process.env.WP_DB_NAME || 'wordpress_vicihost';
const TABLE_PREFIX = 'vhmain_';
if (!DB_USER || !DB_PASSWORD) {
console.error('Set WP_DB_USER and WP_DB_PASSWORD (read-only WordPress DB creds) before running.');
process.exit(1);
}
const UPLOADS_SRC = '/srv/www/vhosts/vicihost-old/wp-content/uploads';
const UPLOADS_DEST = path.join(ROOT, 'src/assets/uploads');
const PAGES_DEST = path.join(ROOT, 'src/content/pages');
const POSTS_DEST = path.join(ROOT, 'src/content/posts');
const NAV_DEST = path.join(ROOT, 'src/data/nav.json');
const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' });
// Emit literal <br /> rather than Markdown's trailing-two-spaces hard break. Markdown drops a
// hard break at the start of a paragraph, and this content uses leading breaks deliberately to
// space out sections -- raw tags survive that round-trip, and render identically.
// Deliberately no trailing newline: a lone tag on its own line starts a raw HTML block
// (CommonMark type 7), which would stop the rest of the paragraph being parsed as Markdown.
turndown.addRule('lineBreak', {
filter: 'br',
replacement: () => '<br />',
});
// This DB's post_content has literal backslash-n sequences from a past export/import,
// not real newlines -- normalize before treating it as HTML/text. The content also contains
// malformed `</br>` closing tags, which browsers (and therefore the old site) render as a
// line break, but an HTML parser drops -- rewrite them so those breaks survive.
function fixLiteralNewlines(text) {
return text
.replace(/\\r\\n/g, '\n')
.replace(/\\n/g, '\n')
.replace(/\r\n/g, '\n')
.replace(/\r/g, '\n')
.replace(/<\/br\s*>/gi, '<br />');
}
// Classic-editor content is stored without <p> tags and rendered through WordPress's
// wpautop filter at display time. Reproduce that so converted Markdown keeps paragraph breaks.
function wpautop(text) {
return text
.split(/\n\s*\n/)
.map((block) => block.trim())
.filter(Boolean)
.map((block) => {
if (/^<(h[1-6]|div|ul|ol|li|table|blockquote|p)[ >]/i.test(block)) return block;
return `<p>${block.replace(/\n/g, '<br>\n')}</p>`;
})
.join('\n');
}
function frontmatterString(value) {
return `"${String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
}
function rewriteImageUrls(html, fromDir) {
const relToUploads = path.relative(fromDir, UPLOADS_DEST);
return html.replace(
/(?:https?:\/\/(?:www\.|wp\.)?vicihost\.com)?\/wp-content\/uploads\/([^\s"')]+)/g,
(_match, relPath) => `${relToUploads}/${relPath}`
);
}
// Content links between pages are stored as absolute WordPress URLs against www.vicihost.com.
// Turn them into site-relative paths. IDs with no published page/post behind them (deleted
// pages, a stray revision) are left alone: they are already broken on the live site.
function rewriteInternalLinks(html, linkMap, unresolved) {
return html.replace(
/https?:\/\/(?:www\.|wp\.)?vicihost\.com\/\?(?:page_id|p)=(\d+)/gi,
(match, id) => {
const target = linkMap.get(Number(id));
if (!target) {
unresolved.add(id);
return match;
}
return target;
}
);
}
// WordPress expands [caption] at render time via do_shortcode(); the raw post_content keeps it
// literal, so it has to be expanded here or it shows up as visible markup on the page.
// The shortcode is swapped for a placeholder before the HTML->Markdown conversion and rebuilt
// afterwards, so the <img> inside still goes through Turndown (and therefore still gets picked
// up by Astro's image pipeline) rather than being frozen as raw HTML pointing into src/assets.
const CAPTION_PLACEHOLDER = (i) => `CAPTIONPLACEHOLDER${i}END`;
function extractCaptions(html, captions) {
return html.replace(/\[caption([^\]]*)\]([\s\S]*?)\[\/caption\]/gi, (_match, attrs, inner) => {
const lastTag = inner.lastIndexOf('>');
captions.push({
align: (attrs.match(/align=["']?(align\w+)["']?/i) || [, 'aligncenter'])[1],
width: (attrs.match(/width=["']?(\d+)["']?/i) || [, ''])[1],
mediaHtml: inner.slice(0, lastTag + 1),
text: inner.slice(lastTag + 1).trim(),
});
return CAPTION_PLACEHOLDER(captions.length - 1);
});
}
// Blank lines around the image are load-bearing: they close the surrounding raw HTML block so
// the image is parsed as Markdown rather than swallowed as literal HTML.
function buildCaption({ align, width, mediaHtml, text }) {
const media = turndown.turndown(mediaHtml).trim();
const style = width ? ` style="width: ${Number(width) + 10}px"` : '';
const caption = text ? `\n<p class="wp-caption-text">${text}</p>` : '';
return `<div class="wp-caption ${align}"${style}>\n\n${media}\n${caption}\n</div>`;
}
async function buildLinkMap(conn) {
const [rows] = await conn.execute(
`SELECT ID, post_type, post_name FROM ${TABLE_PREFIX}posts
WHERE post_status = 'publish' AND post_type IN ('page', 'post')`
);
return new Map(rows.map((r) => [r.ID, r.post_type === 'post' ? `/blog/${r.post_name}` : `/${r.post_name}`]));
}
async function copyAttachments() {
// Copy the whole uploads tree rather than just the 82 attachment rows: WordPress generates
// multiple resized variants per image (e.g. "-1008x1024.png") that content <img> tags/srcsets
// reference directly but that aren't tracked as their own attachment posts in the DB.
await fs.rm(UPLOADS_DEST, { recursive: true, force: true });
await fs.cp(UPLOADS_SRC, UPLOADS_DEST, { recursive: true });
console.log(`Copied uploads tree to ${UPLOADS_DEST}`);
}
async function exportPostType(conn, postType, destDir, { attachmentPaths, thumbnails, linkMap, unresolved }) {
const [rows] = await conn.execute(
`SELECT ID, post_title, post_name, post_date, post_content, post_excerpt
FROM ${TABLE_PREFIX}posts WHERE post_type = ? AND post_status = 'publish' ORDER BY post_date DESC`,
[postType]
);
await fs.mkdir(destDir, { recursive: true });
for (const row of rows) {
const slug = row.post_name || String(row.ID);
let html = fixLiteralNewlines(row.post_content || '');
if (!/^\s*<(p|div|h[1-6]|ul|ol|table)[ >]/i.test(html)) {
html = wpautop(html);
}
html = rewriteImageUrls(html, destDir);
html = rewriteInternalLinks(html, linkMap, unresolved);
const captions = [];
html = extractCaptions(html, captions);
const markdown = turndown
.turndown(html)
.replace(/CAPTIONPLACEHOLDER(\d+)END/g, (_m, i) => buildCaption(captions[Number(i)]));
let excerpt = fixLiteralNewlines(row.post_excerpt || '');
if (!excerpt) {
const plain = html
.replace(/CAPTIONPLACEHOLDER\d+END/g, ' ')
.replace(/<[^>]+>/g, ' ')
.replace(/\s+/g, ' ')
.trim();
// 60 words: what the theme's front-page loop sets ($sbExcerptLength = 60).
// The slideshow truncates this further to 30 at render, as the theme does.
excerpt = plain.split(' ').slice(0, 60).join(' ');
}
const frontmatter = [`title: ${frontmatterString(row.post_title)}`, `slug: ${frontmatterString(slug)}`];
if (postType === 'post') {
frontmatter.push(`date: ${frontmatterString(row.post_date.toISOString())}`);
frontmatter.push(`excerpt: ${frontmatterString(excerpt)}`);
const thumbId = thumbnails.get(row.ID);
const thumbFile = thumbId && attachmentPaths.get(Number(thumbId));
if (thumbFile) {
const relToUploads = path.relative(destDir, UPLOADS_DEST);
frontmatter.push(`featuredImage: ${frontmatterString(`${relToUploads}/${thumbFile}`)}`);
}
}
await fs.writeFile(path.join(destDir, `${slug}.md`), `---\n${frontmatter.join('\n')}\n---\n\n${markdown}\n`);
}
console.log(`Wrote ${rows.length} ${postType}(s) to ${destDir}`);
}
async function exportNav(conn) {
// A menu item is either a reference to a page/post (title and URL come from the target) or a
// custom link, which carries its own label and URL -- this menu's "Home" entry is the latter.
const [navRows] = await conn.execute(
`SELECT p.ID, p.menu_order, p.post_title,
MAX(CASE WHEN pm.meta_key = '_menu_item_object_id' THEN pm.meta_value END) AS object_id,
MAX(CASE WHEN pm.meta_key = '_menu_item_type' THEN pm.meta_value END) AS item_type,
MAX(CASE WHEN pm.meta_key = '_menu_item_url' THEN pm.meta_value END) AS item_url
FROM ${TABLE_PREFIX}posts p
JOIN ${TABLE_PREFIX}postmeta pm ON pm.post_id = p.ID
WHERE p.post_type = 'nav_menu_item' AND p.post_status = 'publish'
GROUP BY p.ID, p.menu_order, p.post_title
ORDER BY p.menu_order`
);
const targetIds = navRows.filter((r) => r.item_type !== 'custom').map((r) => Number(r.object_id));
const [targetRows] = targetIds.length
? await conn.query(`SELECT ID, post_title, post_name, post_type FROM ${TABLE_PREFIX}posts WHERE ID IN (?)`, [targetIds])
: [[]];
const targets = new Map(targetRows.map((r) => [r.ID, r]));
const nav = navRows.map((r) => {
if (r.item_type === 'custom') {
return { title: r.post_title, href: r.item_url || '/' };
}
const target = targets.get(Number(r.object_id));
const href = target?.post_type === 'post' ? `/blog/${target.post_name}` : `/${target?.post_name ?? ''}`;
// WordPress lets a menu item override the target's label; fall back to the target title.
return { title: r.post_title || target?.post_title || '', href };
});
await fs.mkdir(path.dirname(NAV_DEST), { recursive: true });
await fs.writeFile(NAV_DEST, `${JSON.stringify(nav, null, 2)}\n`);
console.log(`Wrote ${nav.length} nav items to ${NAV_DEST}`);
}
async function main() {
const conn = await mysql.createConnection({ host: DB_HOST, user: DB_USER, password: DB_PASSWORD, database: DB_NAME });
const [attachmentRows] = await conn.execute(
`SELECT p.ID, pm.meta_value AS file FROM ${TABLE_PREFIX}posts p
JOIN ${TABLE_PREFIX}postmeta pm ON pm.post_id = p.ID AND pm.meta_key = '_wp_attached_file'
WHERE p.post_type = 'attachment'`
);
const attachmentPaths = new Map(attachmentRows.map((r) => [r.ID, r.file]));
const [thumbRows] = await conn.execute(`SELECT post_id, meta_value FROM ${TABLE_PREFIX}postmeta WHERE meta_key = '_thumbnail_id'`);
const thumbnails = new Map(thumbRows.map((r) => [r.post_id, r.meta_value]));
await copyAttachments();
const linkMap = await buildLinkMap(conn);
const unresolved = new Set();
await exportPostType(conn, 'page', PAGES_DEST, { attachmentPaths, thumbnails, linkMap, unresolved });
await exportPostType(conn, 'post', POSTS_DEST, { attachmentPaths, thumbnails, linkMap, unresolved });
if (unresolved.size) {
console.warn(`Left ${unresolved.size} link(s) pointing at WordPress IDs with no published page: ${[...unresolved].join(', ')}`);
}
await exportNav(conn);
await conn.end();
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Some files were not shown because too many files have changed in this diff Show More