Initial Astro migration of vicidial.com off WordPress
Static brochure/marketing site: 55 pages, 5 posts, 82 attachments, and the 7-item nav, exported from the wordpress_vicidial DB via scripts/export-wp.mjs (re-runnable). Layout/styles ported from the small-business WP theme; homepage slideshow rebuilt as a Splide client island pulling the latest 5 posts at build time, replacing the old BJQS jQuery plugin.
@@ -0,0 +1,27 @@
|
||||
# build output
|
||||
dist/
|
||||
# generated types
|
||||
.astro/
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
||||
# logs
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
|
||||
# environment variables
|
||||
.env
|
||||
.env.production
|
||||
|
||||
# macOS-specific files
|
||||
.DS_Store
|
||||
|
||||
# jetbrains setting folder
|
||||
.idea/
|
||||
|
||||
# large video, copied into dist/ post-build instead of tracked in git
|
||||
public/VICIdial_v002_06-23-2017.mp4
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"recommendations": ["astro-build.astro-vscode"],
|
||||
"unwantedRecommendations": []
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "./node_modules/.bin/astro dev",
|
||||
"name": "Development server",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
## Development
|
||||
|
||||
When starting the dev server, use background mode:
|
||||
|
||||
```
|
||||
astro dev --background
|
||||
```
|
||||
|
||||
Manage the background server with `astro dev stop`, `astro dev status`, and `astro dev logs`.
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation: https://docs.astro.build
|
||||
|
||||
Consult these guides before working on related tasks:
|
||||
|
||||
- [Adding pages, dynamic routes, or middleware](https://docs.astro.build/en/guides/routing/)
|
||||
- [Working with Astro components](https://docs.astro.build/en/basics/astro-components/)
|
||||
- [Using React, Vue, Svelte, or other framework components](https://docs.astro.build/en/guides/framework-components/)
|
||||
- [Adding or managing content](https://docs.astro.build/en/guides/content-collections/)
|
||||
- [Adding styles or using Tailwind](https://docs.astro.build/en/guides/styling/)
|
||||
- [Supporting multiple languages](https://docs.astro.build/en/guides/internationalization/)
|
||||
@@ -0,0 +1,43 @@
|
||||
# Astro Starter Kit: Minimal
|
||||
|
||||
```sh
|
||||
npm create astro@latest -- --template minimal
|
||||
```
|
||||
|
||||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
||||
|
||||
## 🚀 Project Structure
|
||||
|
||||
Inside of your Astro project, you'll see the following folders and files:
|
||||
|
||||
```text
|
||||
/
|
||||
├── public/
|
||||
├── src/
|
||||
│ └── pages/
|
||||
│ └── index.astro
|
||||
└── package.json
|
||||
```
|
||||
|
||||
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
|
||||
|
||||
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
|
||||
|
||||
Any static assets, like images, can be placed in the `public/` directory.
|
||||
|
||||
## 🧞 Commands
|
||||
|
||||
All commands are run from the root of the project, from a terminal:
|
||||
|
||||
| Command | Action |
|
||||
| :------------------------ | :----------------------------------------------- |
|
||||
| `npm install` | Installs dependencies |
|
||||
| `npm run dev` | Starts local dev server at `localhost:4321` |
|
||||
| `npm run build` | Build your production site to `./dist/` |
|
||||
| `npm run preview` | Preview your build locally, before deploying |
|
||||
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
|
||||
| `npm run astro -- --help` | Get help using the Astro CLI |
|
||||
|
||||
## 👀 Want to learn more?
|
||||
|
||||
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-check
|
||||
import { defineConfig } from 'astro/config';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({});
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,2 @@
|
||||
User-Agent: *
|
||||
Allow: /
|
||||
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 403 B |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 900 B |
|
After Width: | Height: | Size: 884 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 19 KiB |
@@ -0,0 +1,168 @@
|
||||
#!/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_vicidial';
|
||||
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/vicidial-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' });
|
||||
|
||||
// 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.
|
||||
function fixLiteralNewlines(text) {
|
||||
return text.replace(/\\r\\n/g, '\n').replace(/\\n/g, '\n').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||
}
|
||||
|
||||
// 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?:\/\/(?:wp\.vicidial\.(?:com|net)|www\.vicidial\.com))?\/wp-content\/uploads\/([^\s"')]+)/g,
|
||||
(_match, relPath) => `${relToUploads}/${relPath}`
|
||||
);
|
||||
}
|
||||
|
||||
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 }) {
|
||||
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);
|
||||
const markdown = turndown.turndown(html);
|
||||
|
||||
let excerpt = fixLiteralNewlines(row.post_excerpt || '');
|
||||
if (!excerpt) {
|
||||
const plain = html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
excerpt = plain.split(' ').slice(0, 55).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) {
|
||||
const [navRows] = await conn.execute(
|
||||
`SELECT p.ID, p.menu_order, pm_obj.meta_value AS object_id
|
||||
FROM ${TABLE_PREFIX}posts p
|
||||
JOIN ${TABLE_PREFIX}postmeta pm_obj ON pm_obj.post_id = p.ID AND pm_obj.meta_key = '_menu_item_object_id'
|
||||
WHERE p.post_type = 'nav_menu_item' AND p.post_status = 'publish'
|
||||
ORDER BY p.menu_order`
|
||||
);
|
||||
|
||||
const targetIds = navRows.map((r) => Number(r.object_id));
|
||||
const [targetRows] = targetIds.length
|
||||
? await conn.query(`SELECT ID, post_title, post_name FROM ${TABLE_PREFIX}posts WHERE ID IN (?)`, [targetIds])
|
||||
: [[]];
|
||||
const targets = new Map(targetRows.map((r) => [r.ID, r]));
|
||||
|
||||
const nav = navRows.map((r) => {
|
||||
const target = targets.get(Number(r.object_id));
|
||||
return { title: target?.post_title ?? '', href: `/${target?.post_name ?? ''}` };
|
||||
});
|
||||
|
||||
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();
|
||||
await exportPostType(conn, 'page', PAGES_DEST, { attachmentPaths, thumbnails });
|
||||
await exportPostType(conn, 'post', POSTS_DEST, { attachmentPaths, thumbnails });
|
||||
await exportNav(conn);
|
||||
|
||||
await conn.end();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 191 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 204 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 21 KiB |