-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add Wix migrate tool #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PaulAdamDavis
wants to merge
7
commits into
main
Choose a base branch
from
wix-csv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Wix migrate tool #1802
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f51b91f
Add Wix migrate tool
PaulAdamDavis 77939ef
Escape asset scraping domains
PaulAdamDavis e883e96
Throw error for empty CSV files
PaulAdamDavis 352a2c1
Sanitize href values in links
PaulAdamDavis fe9ab43
Guard against malformed image references
PaulAdamDavis c1e8da7
Update README.md
PaulAdamDavis 34f5561
Add license
PaulAdamDavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module.exports = { | ||
| parser: '@typescript-eslint/parser', | ||
| plugins: ['ghost'], | ||
| extends: [ | ||
| 'plugin:ghost/node' | ||
| ], | ||
| rules: { | ||
| 'no-unused-vars': 'off', | ||
| 'no-undef': 'off', | ||
| 'ghost/ghost-custom/no-native-errors': 'off', | ||
| 'ghost/ghost-custom/no-native-error': 'off', | ||
| 'ghost/ghost-custom/ghost-error-usage': 'off', | ||
| 'ghost/filenames/match-regex': 'off' | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /build | ||
| /tsconfig.tsbuildinfo | ||
| /tmp | ||
| .env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2013-2026 Ghost Foundation | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Wix CSV Migration | ||
|
|
||
| Migrate Wix blog posts from a posts CSV export into a Ghost import file. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| migrate wix-csv --posts /path/to/posts.csv --url https://example.com | ||
| ``` | ||
|
|
||
| By default, the command reads posts, converts Wix rich content to Ghost-compatible HTML/Lexical, downloads Wix-hosted assets, and writes a Ghost import zip. | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |-------------------------|---------|----------|---------------------------------------------------------------------------------------------------------------------| | ||
| | `--posts` | string | `null` | Path to the Wix posts CSV file. Required. | | ||
| | `--url` | string | `null` | URL to the live Wix site, used for source URLs and link fixing. Required. | | ||
| | `--defaultAuthorName` | string | `null` | Fallback author name when the CSV row has no author. | | ||
| | `--scrape` | array | `assets` | Asset scraping mode. Use `assets`, `img`, `media`, or `files` to download assets; use `none` to skip. | | ||
| | `--includeMainCategory` | boolean | `true` | Include the `Main Category` column as Ghost tags. Note: option name intentionally matches the current CLI spelling. | | ||
| | `--includeCategories` | boolean | `true` | Include the `Categories` column as Ghost tags. Supports plain category names and legacy JSON arrays. | | ||
| | `--includeTags` | boolean | `true` | Include the `Tags` column as Ghost tags. | | ||
| | `--tmpPath` | string | `null` | Full path for temporary migration files. Defaults to the migrator cache location. | | ||
| | `--outputPath` | string | `null` | Full path where the final zip should be saved. Defaults to the current working directory. | | ||
| | `--cacheName` | string | `null` | Custom cache name. Defaults to a name derived from the site URL. | | ||
| | `--cache` | boolean | `true` | Keep the local cache after migration completes. Only applies when `--zip` is enabled. | | ||
| | `--zip` | boolean | `true` | Create a Ghost import zip. Set to `false` to write only the import JSON/cache output. | | ||
| | `-V`, `--verbose` | boolean | `false` | Show verbose output. Defaults to `true` when `DEBUG` is set. | | ||
| | `--veryVerbose` | boolean | `false` | Show very verbose output. Implies `--verbose`. | | ||
| | `--ghostApiUrl` | string | `null` | Ghost site URL used to fetch existing users for author matching. | | ||
| | `--ghostAdminKey` | string | `null` | Ghost Admin API key used with `--ghostApiUrl`. | | ||
|
|
||
| ## Taxonomy | ||
|
|
||
| The migrator always adds the internal source tag `#wix`. | ||
|
|
||
| CSV taxonomy fields are controlled independently: | ||
|
|
||
| ```bash | ||
| migrate wix-csv --posts /path/to/posts.csv --url https://example.com --includeMainCategory false --includeCategories true --includeTags false | ||
| ``` | ||
|
|
||
| For updated Wix CSV exports, `Categories` may contain readable names such as `Tax Planning`. Older exports may contain JSON arrays of IDs. The migrator accepts both formats. | ||
|
|
||
| ## Content Notes | ||
|
|
||
| - `Rich Content` is used as the source of post body HTML. | ||
| - `Plain Content` is used as fallback content when `Rich Content` is empty or invalid. | ||
| - `Internal ID` is mapped to Ghost `comment_id`. | ||
| - Wix image URLs are converted to original static media URLs, for example `https://static.wixstatic.com/media/<media-id>`. | ||
|
|
||
|
|
||
| # Copyright & License | ||
|
|
||
| Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| { | ||
| "name": "@tryghost/mg-wix-csv", | ||
| "version": "0.1.0", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/TryGhost/migrate.git", | ||
| "directory": "packages/mg-wix-csv" | ||
| }, | ||
| "author": "Ghost Foundation", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "main": "build/index.js", | ||
| "types": "build/types.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "source": "./src/index.ts", | ||
| "default": "./build/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "dev": "echo \"Implement me!\"", | ||
| "build:watch": "tsc --watch --preserveWatchOutput --sourceMap", | ||
| "build": "tsc --build --sourceMap", | ||
| "lint": "eslint src/ --ext .ts --cache", | ||
| "test": "c8 --src src --all --check-coverage --100 --reporter text --reporter cobertura node --test 'build/test/**/*.test.js'", | ||
| "test:local": "pnpm build && pnpm test", | ||
| "posttest": "pnpm lint" | ||
| }, | ||
| "files": [ | ||
| "build" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "24.12.4", | ||
| "@typescript-eslint/parser": "8.59.4", | ||
| "c8": "11.0.0", | ||
| "eslint": "8.57.1", | ||
| "typescript": "6.0.3" | ||
| }, | ||
| "dependencies": { | ||
| "@tryghost/errors": "3.0.3", | ||
| "@tryghost/kg-default-cards": "10.2.10", | ||
| "@tryghost/mg-fs-utils": "workspace:*", | ||
| "@tryghost/string": "0.3.1", | ||
| "simple-dom": "1.4.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import {mapContent} from './lib/mapper.js'; | ||
|
|
||
| export default async (args: {options: any}) => { | ||
| const result = await mapContent(args); | ||
| return result; | ||
| }; | ||
|
|
||
| export { | ||
| mapContent | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| import errors from '@tryghost/errors'; | ||
| import fsUtils from '@tryghost/mg-fs-utils'; | ||
| import {slugify} from '@tryghost/string'; | ||
| import {richContentToHtml} from './rich-content.js'; | ||
| import {wixImageUriToUrl} from './wix-image.js'; | ||
|
|
||
| const parsePostsCSV = async ({pathToFile}: {pathToFile: string}) => { | ||
| const parseCSV = fsUtils.csv.parseCSV; | ||
| const parsed = await parseCSV(pathToFile); | ||
|
|
||
| return parsed as wixCSVPostDataObject[]; | ||
| }; | ||
|
|
||
| const parseDate = (value?: string) => { | ||
| if (!value) { | ||
| return null; | ||
| } | ||
|
|
||
| const date = new Date(value); | ||
| return Number.isNaN(date.getTime()) ? null : date; | ||
| }; | ||
|
|
||
| const parseBoolean = (value?: string) => { | ||
| return typeof value === 'string' && value.toLowerCase() === 'true'; | ||
| }; | ||
|
|
||
| const parseIdArray = (value?: string) => { | ||
| if (!value) { | ||
| return []; | ||
| } | ||
|
|
||
| const trimmed = value.trim(); | ||
|
|
||
| if (trimmed.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| try { | ||
| const parsed = JSON.parse(trimmed); | ||
|
|
||
| if (!Array.isArray(parsed)) { | ||
| return []; | ||
| } | ||
|
|
||
| return parsed.filter((item): item is string => typeof item === 'string' && item.length > 0); | ||
| } catch (error) { | ||
| return [trimmed]; | ||
| } | ||
| }; | ||
|
|
||
| const uniqueIds = (ids: string[]) => { | ||
| return [...new Set(ids.filter(Boolean))]; | ||
| }; | ||
|
|
||
| const looksLikeWixId = (value: string) => { | ||
| return /^[a-f0-9]{24}$/i.test(value); | ||
| }; | ||
|
|
||
| const createTag = (value: string) => { | ||
| const slug = looksLikeWixId(value) ? value : slugify(value); | ||
|
|
||
| return { | ||
| url: `migrator-added-tag-${slug}`, | ||
| data: { | ||
| slug, | ||
| name: value | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| const createAuthor = ({name, defaultAuthorName}: {name?: string, defaultAuthorName?: string}) => { | ||
| const authorName = name?.trim() || defaultAuthorName?.trim() || 'Author'; | ||
| const authorSlug = slugify(authorName); | ||
|
|
||
| return { | ||
| url: `migrator-added-author-${authorSlug}`, | ||
| data: { | ||
| slug: authorSlug, | ||
| name: authorName, | ||
| email: `${authorSlug}@example.com` | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| const buildPostUrl = ({url, path}: {url?: string, path?: string}) => { | ||
| if (!url || !path) { | ||
| return path || ''; | ||
| } | ||
|
|
||
| if (path.startsWith('http://') || path.startsWith('https://')) { | ||
| return path; | ||
| } | ||
|
|
||
| return `${url}${path.startsWith('/') ? '' : '/'}${path}`; | ||
| }; | ||
|
|
||
| const createSlug = ({slug, title}: {slug?: string, title?: string}) => { | ||
| if (slug && slug.trim().length > 0) { | ||
| return slugify(slug); | ||
| } | ||
|
|
||
| return slugify(title || 'untitled'); | ||
| }; | ||
|
|
||
| const shouldInclude = (value: boolean | undefined) => { | ||
| return value !== false; | ||
| }; | ||
|
|
||
| const mapTags = (postData: wixCSVPostDataObject, options?: any) => { | ||
| const categories = parseIdArray(postData.Categories); | ||
| const tags = parseIdArray(postData.Tags); | ||
| const mainCategory = postData['Main Category']; | ||
| const includeMainCategory = shouldInclude(options?.includeMainCategory); | ||
| const includeCategories = shouldInclude(options?.includeCategories); | ||
| const includeTags = shouldInclude(options?.includeTags); | ||
| const shouldDropLegacyMainCategoryId = mainCategory && !looksLikeWixId(mainCategory) && categories[0] && looksLikeWixId(categories[0]); | ||
| const secondaryCategories = shouldDropLegacyMainCategoryId ? categories.slice(1) : categories; | ||
| const orderedCategories = uniqueIds([ | ||
| ...(includeMainCategory && mainCategory ? [mainCategory] : []), | ||
| ...(includeCategories ? secondaryCategories : []) | ||
| ]); | ||
|
|
||
| return [ | ||
| ...uniqueIds([ | ||
| ...orderedCategories, | ||
| ...(includeTags ? tags : []) | ||
| ]).map(createTag), | ||
| { | ||
| url: 'migrator-added-tag-hash-wix', | ||
| data: { | ||
| slug: 'hash-wix', | ||
| name: '#wix' | ||
| } | ||
| } | ||
| ]; | ||
| }; | ||
|
|
||
| const mapPost = ({postData, options}: {postData: wixCSVPostDataObject, options?: any}) => { | ||
| const publishedAt = parseDate(postData['Published Date']); | ||
| const updatedAt = parseDate(postData['Last Published Date']) || publishedAt; | ||
| const createdAt = publishedAt || updatedAt || new Date(); | ||
| const postSlug = createSlug({slug: postData.Slug, title: postData.Title}); | ||
| const featureImage = wixImageUriToUrl(postData['Cover Image']); | ||
|
|
||
| const mappedData: mappedDataObject = { | ||
| url: buildPostUrl({url: options?.url, path: postData['Post Page URL']}), | ||
| data: { | ||
| slug: postSlug, | ||
| comment_id: postData['Internal ID'] || null, | ||
| published_at: publishedAt, | ||
| updated_at: updatedAt, | ||
| created_at: createdAt, | ||
| title: postData.Title || postSlug, | ||
| type: 'post', | ||
| html: richContentToHtml({ | ||
| richContent: postData['Rich Content'], | ||
| plainContent: postData['Plain Content'] | ||
| }), | ||
| plaintext: postData['Plain Content'] || null, | ||
| status: publishedAt ? 'published' : 'draft', | ||
| custom_excerpt: postData.Excerpt || null, | ||
| visibility: 'public', | ||
| featured: parseBoolean(postData.Featured), | ||
| tags: mapTags(postData, options), | ||
| author: createAuthor({ | ||
| name: postData.Author, | ||
| defaultAuthorName: options?.defaultAuthorName | ||
| }) | ||
| } | ||
| }; | ||
|
|
||
| if (featureImage) { | ||
| mappedData.data.feature_image = featureImage; | ||
| } | ||
|
|
||
| return mappedData; | ||
| }; | ||
|
|
||
| const mapPosts = async ({pathToFile, options}: {pathToFile: string, options: any}) => { | ||
| const parsed = await parsePostsCSV({pathToFile}); | ||
|
|
||
| return parsed.map((postData: wixCSVPostDataObject) => { | ||
| return mapPost({postData, options}); | ||
| }); | ||
| }; | ||
|
|
||
| const mapContent = async (args: {options: any}) => { | ||
| const output = { | ||
| posts: [] as mappedDataObject[] | ||
| }; | ||
|
|
||
| const mappedPosts = await mapPosts({pathToFile: args.options.posts, options: args.options}); | ||
|
|
||
| if (mappedPosts.length < 1) { | ||
| throw new errors.NoContentError({message: 'Input file is empty'}); | ||
| } | ||
|
|
||
| output.posts = mappedPosts; | ||
|
|
||
| return output; | ||
| }; | ||
|
|
||
| export { | ||
| buildPostUrl, | ||
| createAuthor, | ||
| createSlug, | ||
| mapContent, | ||
| mapPost, | ||
| mapTags, | ||
| parseBoolean, | ||
| parseDate, | ||
| parseIdArray, | ||
| parsePostsCSV, | ||
| uniqueIds | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.