Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/mg-beehiiv-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
},
"dependencies": {
"@tryghost/errors": "3.0.3",
"@tryghost/kg-default-cards": "10.2.5",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.2.21",
"simple-dom": "1.4.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/mg-beehiiv-api/src/lib/process.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {domUtils, youtubeUtils, stringUtils} from '@tryghost/mg-utils';
import {domUtils, youtubeUtils, stringUtils, cardUtils} from '@tryghost/mg-utils';
import SimpleDom from 'simple-dom';
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
import embedCard from '@tryghost/kg-default-cards/lib/cards/embed.js';
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';

const {parseFragment, serializeChildren, serializeNode, replaceWith, insertAfter, attr, parents} = domUtils;
const {unescapeHTML} = stringUtils;

const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
const {getYouTubeID} = youtubeUtils;
const imageCard = cardUtils.getCard('image');
const embedCard = cardUtils.getCard('embed');
const bookmarkCard = cardUtils.getCard('bookmark');

const isURL = (urlString: string | undefined) => {
if (undefined === urlString) {
Expand Down
3 changes: 0 additions & 3 deletions packages/mg-beehiiv-api/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
declare module '@tryghost/errors';
declare module '@tryghost/kg-default-cards/lib/cards/image.js';
declare module '@tryghost/kg-default-cards/lib/cards/embed.js';
declare module '@tryghost/kg-default-cards/lib/cards/bookmark.js';
declare module '@tryghost/string';
declare module 'sanitize-html';

Expand Down
1 change: 0 additions & 1 deletion packages/mg-beehiiv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"typescript": "6.0.3"
},
"dependencies": {
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-fs-utils": "workspace:*",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/mg-beehiiv/src/lib/process.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as cheerio from 'cheerio';
import sanitizeHtml from 'sanitize-html';
import SimpleDom from 'simple-dom';
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
import embedCard from '@tryghost/kg-default-cards/lib/cards/embed.js';
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
import {youtubeUtils} from '@tryghost/mg-utils';
import {youtubeUtils, cardUtils} from '@tryghost/mg-utils';

const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
const {getYouTubeID} = youtubeUtils;
const imageCard = cardUtils.getCard('image');
const embedCard = cardUtils.getCard('embed');
const bookmarkCard = cardUtils.getCard('bookmark');

const isURL = (urlString: string | undefined) => {
if (undefined === urlString) {
Expand Down
3 changes: 0 additions & 3 deletions packages/mg-beehiiv/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
declare module '@tryghost/kg-default-cards/lib/cards/image.js';
declare module '@tryghost/kg-default-cards/lib/cards/embed.js';
declare module '@tryghost/kg-default-cards/lib/cards/bookmark.js';
declare module '@tryghost/mg-fs-utils';
declare module '@tryghost/string';
declare module 'sanitize-html';
Expand Down
4 changes: 2 additions & 2 deletions packages/mg-blogger/lib/process.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {basename} from 'node:path';
import {domUtils} from '@tryghost/mg-utils';
import {domUtils, cardUtils} from '@tryghost/mg-utils';
import autop from 'autop';
import sanitizeHtml from 'sanitize-html';
import {slugify} from '@tryghost/string';
import errors from '@tryghost/errors';
import SimpleDom from 'simple-dom';
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';

const {serializeChildren, replaceWith, wrap} = domUtils;

const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
const imageCard = cardUtils.getCard('image');

const cleanExcerpt = (htmlContent) => {
// Convert to text only
Expand Down
1 change: 0 additions & 1 deletion packages/mg-blogger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@tryghost/errors": "3.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
"autop": "1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/mg-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@tryghost/errors": "3.0.3",
"@tryghost/html-to-mobiledoc": "3.2.21",
"@tryghost/kg-html-to-lexical": "1.2.38",
"@tryghost/kg-html-to-lexical": "1.3.1",
"@tryghost/listr-smart-renderer": "workspace:*",
"@tryghost/validator": "3.1.1",
"@typescript-eslint/parser": "8.60.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/mg-context/src/lib/MigrateContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {stat, mkdir, open, writeFile} from 'node:fs/promises';
import {join, resolve} from 'node:path';
import {EventEmitter} from 'node:events';
import {createRequire} from 'node:module';
import errors from '@tryghost/errors';
import mobiledocConverter from '@tryghost/html-to-mobiledoc';
import lexicalConverter from '@tryghost/kg-html-to-lexical';

import MigrateBase from './MigrateBase.js';
import PostContext, {PostConstructorOptions} from './PostContext.js';
Expand All @@ -12,6 +12,9 @@ import AuthorContext from './AuthorContext.js';
import {createDatabase, type DatabaseModels} from './database.js';
import {withTransaction, findByIds, findByColumn, buildDateWhere, buildFullWhere, countWhere, findPostsWhere, findPostIdColumnsWhere, findAllPostIdsWhere, findPostsByIds} from './db-helpers.js';

const require = createRequire(import.meta.url);
const lexicalConverter = require('@tryghost/kg-html-to-lexical') as typeof import('@tryghost/kg-html-to-lexical');

type FindPostsOptions = {
slug?: string;
title?: string;
Expand Down
5 changes: 4 additions & 1 deletion packages/mg-context/src/lib/PostContext.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {z} from 'zod/v4';
import {randomBytes} from 'node:crypto';
import {createRequire} from 'node:module';
import mobiledocConverter from '@tryghost/html-to-mobiledoc';
import lexicalConverter from '@tryghost/kg-html-to-lexical';
import MigrateBase from './MigrateBase.js';
import TagContext, {TagObject, TagDataObject} from './TagContext.js';
import AuthorContext, {AuthorObject, AuthorDataObject} from './AuthorContext.js';
import type {DatabaseModels} from './database.js';

const require = createRequire(import.meta.url);
const lexicalConverter = require('@tryghost/kg-html-to-lexical') as typeof import('@tryghost/kg-html-to-lexical');

const postZodSchema = z.object({
title: z.string().max(255),
slug: z.string().max(191),
Expand Down
2 changes: 1 addition & 1 deletion packages/mg-html-lexical/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
},
"dependencies": {
"@tryghost/errors": "3.0.3",
"@tryghost/kg-html-to-lexical": "1.2.38"
"@tryghost/kg-html-to-lexical": "1.3.1"
}
}
7 changes: 6 additions & 1 deletion packages/mg-html-lexical/src/lib/convert-post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {htmlToLexical} from '@tryghost/kg-html-to-lexical';
import {createRequire} from 'node:module';
import errors from '@tryghost/errors';
import {convertToHTMLCard} from './convert-to-html-card.js';

Expand All @@ -20,6 +20,11 @@ const emptyParagraph = {
version: 1
};

const require = createRequire(import.meta.url);
const {htmlToLexical} = require('@tryghost/kg-html-to-lexical') as {
htmlToLexical: typeof import('@tryghost/kg-html-to-lexical')['htmlToLexical'];
};

const convertPost = (post: postOptions, htmlCard = false) => {
if (typeof post.html === 'undefined' || post.html === 'undefined') {
throw new errors.InternalServerError({message: 'Post has no html field to convert'});
Expand Down
4 changes: 2 additions & 2 deletions packages/mg-libsyn/lib/processor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {domUtils} from '@tryghost/mg-utils';
import {domUtils, cardUtils} from '@tryghost/mg-utils';
import {slugify, stripInvisibleChars} from '@tryghost/string';
import SimpleDom from 'simple-dom';
import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';

const {serializeChildren, replaceWith, insertBefore, insertAfter, isComment, getCommentData} = domUtils;
const audioCard = cardUtils.getCard('audio');

const durationToSeconds = (duration) => {
if (duration.includes(':')) {
Expand Down
1 change: 0 additions & 1 deletion packages/mg-libsyn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@tryghost/errors": "3.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
"node-fetch": "3.3.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/mg-medium-export/lib/process-content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {domUtils} from '@tryghost/mg-utils';
import {domUtils, cardUtils} from '@tryghost/mg-utils';
import SimpleDom from 'simple-dom';
import galleryCard from '@tryghost/kg-default-cards/lib/cards/gallery.js';
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
const galleryCard = cardUtils.getCard('gallery');
const bookmarkCard = cardUtils.getCard('bookmark');

const doReplace = (str) => {
const replaceParts = [
Expand Down
1 change: 0 additions & 1 deletion packages/mg-medium-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"dependencies": {
"@tryghost/debug": "2.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-fs-utils": "workspace:*",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/mg-squarespace-xml/lib/process.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {extname} from 'path';
import {xmlUtils, domUtils} from '@tryghost/mg-utils';
import {xmlUtils, domUtils, cardUtils} from '@tryghost/mg-utils';
import {slugify} from '@tryghost/string';
import SimpleDom from 'simple-dom';
import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
import errors from '@tryghost/errors';
import {decode} from 'html-entities';
const audioCard = cardUtils.getCard('audio');

const htmlToTextTrimmed = (html, max) => {
let noHtml = html.replace(/<[^>]+>/g, ' ').replace(/\r?\n|\r/g, ' ').replace(/ {2,}/, ' ').trim();
Expand Down
1 change: 0 additions & 1 deletion packages/mg-squarespace-xml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
},
"dependencies": {
"@tryghost/errors": "3.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
"html-entities": "2.6.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/mg-substack/lib/process.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {promises as fs} from 'node:fs';
import {join, basename} from 'node:path';
import url from 'node:url';
import {domUtils, stringUtils} from '@tryghost/mg-utils';
import {domUtils, stringUtils, cardUtils} from '@tryghost/mg-utils';
import errors from '@tryghost/errors';
import SimpleDom from 'simple-dom';
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
import galleryCard from '@tryghost/kg-default-cards/lib/cards/gallery.js';
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
import fileCard from '@tryghost/kg-default-cards/lib/cards/file.js';
import {decode} from 'html-entities';
import {parseSrcset} from 'srcset';
import {_base as debugFactory} from '@tryghost/debug';
Expand All @@ -20,6 +15,11 @@ const {startCase} = stringUtils;

const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
const debug = debugFactory('migrate:substack:process');
const imageCard = cardUtils.getCard('image');
const audioCard = cardUtils.getCard('audio');
const galleryCard = cardUtils.getCard('gallery');
const bookmarkCard = cardUtils.getCard('bookmark');
const fileCard = cardUtils.getCard('file');

const getFiles = async (filePath) => {
let filenames = await fs.readdir(filePath);
Expand Down
1 change: 0 additions & 1 deletion packages/mg-substack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"dependencies": {
"@tryghost/debug": "2.0.3",
"@tryghost/errors": "3.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-fs-utils": "workspace:*",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/mg-tinynews/lib/json-to-html.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import SimpleDom from 'simple-dom';
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
import {cardUtils} from '@tryghost/mg-utils';
import {TextNode} from './text.js';

const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
const imageCard = cardUtils.getCard('image');

// From https://gist.github.com/takien/4077195
const getYouTubeID = (url) => {
Expand Down
1 change: 0 additions & 1 deletion packages/mg-tinynews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@tryghost/debug": "2.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-utils": "workspace:*",
"@tryghost/string": "0.3.1",
"sanitize-html": "2.17.4",
Expand Down
1 change: 1 addition & 0 deletions packages/mg-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"typescript": "6.0.3"
},
"dependencies": {
"@tryghost/kg-default-cards": "10.3.1",
"fast-xml-parser": "5.8.0",
"linkedom": "0.18.12"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/mg-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import * as domUtils from './lib/dom-utils.js';
import * as youtubeUtils from './lib/youtube-utils.js';
import * as xmlUtils from './lib/xml-utils.js';
import * as stringUtils from './lib/string-utils.js';
import * as cardUtils from './lib/card-utils.js';

export {domUtils, youtubeUtils, xmlUtils, stringUtils};
export {domUtils, youtubeUtils, xmlUtils, stringUtils, cardUtils};
27 changes: 27 additions & 0 deletions packages/mg-utils/src/lib/card-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {createRequire} from 'node:module';

const require = createRequire(import.meta.url);

type SerializableNode = {
readonly nodeType: number;
readonly nodeName: string;
readonly nodeValue: string | null;
readonly nextSibling: SerializableNode | null;
readonly firstChild: SerializableNode | null;
};

type Card = {
name: string;
render: (args: unknown) => SerializableNode;
};

const getCards = () => {
const {cards} = require('@tryghost/kg-default-cards') as {cards: Card[]};
return cards;
};

const getCard = (name: string) => {
return getCards().find(card => card.name === name) as Card;
};

export {getCard};
12 changes: 12 additions & 0 deletions packages/mg-utils/src/test/card-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import assert from 'node:assert/strict';
import {describe, it} from 'node:test';
import {getCard} from '../lib/card-utils.js';

describe('cardUtils', function () {
it('returns cards by name from kg-default-cards', function () {
const imageCard = getCard('image');

assert.equal(imageCard.name, 'image');
assert.equal(typeof imageCard.render, 'function');
});
});
8 changes: 4 additions & 4 deletions packages/mg-wp-api/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import MgFsUtils from '@tryghost/mg-fs-utils';
import {htmlToText} from 'html-to-text';
import {_base as debugFactory} from '@tryghost/debug';
import SimpleDom from 'simple-dom';
import galleryCard from '@tryghost/kg-default-cards/lib/cards/gallery.js';
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
import {domUtils, youtubeUtils, stringUtils} from '@tryghost/mg-utils';
import {domUtils, youtubeUtils, stringUtils, cardUtils} from '@tryghost/mg-utils';
import {matchEmbedUrl, buildEmbedHtml} from './embed-utils.js';

const {unescapeHTML, stripHtml} = stringUtils;
Expand All @@ -35,6 +32,9 @@ const {getYouTubeID} = youtubeUtils;
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);

const debug = debugFactory('migrate:wp-api:processor');
const galleryCard = cardUtils.getCard('gallery');
const imageCard = cardUtils.getCard('image');
const bookmarkCard = cardUtils.getCard('bookmark');

const chunkArray = (arr, size) => {
const chunks = [];
Expand Down
1 change: 0 additions & 1 deletion packages/mg-wp-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@tryghost/debug": "2.0.3",
"@tryghost/kg-default-cards": "10.2.10",
"@tryghost/mg-fs-utils": "workspace:*",
"@tryghost/mg-shortcodes": "workspace:*",
"@tryghost/mg-utils": "workspace:*",
Expand Down
Loading