@tryghost/mg-buttondown 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013-2025 Ghost Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Migrate Buttondown Export
2
+
3
+ Converts a Buttondown export and generates a `zip` file you can import into a Ghost installation.
4
+
5
+
6
+ ## Install
7
+
8
+ To install the CLI, which is required for the Usage commands below:
9
+
10
+ ```sh
11
+ npm install --global @tryghost/migrate
12
+ ```
13
+
14
+ To use this package in your own project:
15
+
16
+ `npm install @tryghost/mg-buttondown --save`
17
+
18
+ or
19
+
20
+ `yarn add @tryghost/mg-buttondown`
21
+
22
+
23
+ ## Usage
24
+
25
+ To run a basic Buttondown migration, the required command is this:
26
+
27
+ ```sh
28
+ migrate buttondown --pathToZip /path/to/export.zip --url https://example.com
29
+ ```
30
+
31
+ It's possible to pass more options, in order to achieve a better migration file for Ghost:
32
+
33
+ - **`--pathToZip`** (required)
34
+ - Path to a zip file
35
+ - string - default: `null`
36
+ - **`--url`** (required)
37
+ - Site URL
38
+ - string - default: `null`
39
+ - **`-s` `--scrape`**
40
+ - Configure scraping tasks
41
+ - string - default: `all`
42
+ - Choices: `all`, `img`, `web`, `media`, `files`, `none`
43
+ - **`--fallBackHTMLCard`**
44
+ - Fall back to convert to HTMLCard, if standard Mobiledoc convert fails
45
+ - bool - default: `true`
46
+ - **`--cache`**
47
+ - Persist local cache after migration is complete (Only if `--zip` is `true`)
48
+ - bool - default: `true`
49
+ - **`-V` `--verbose`**
50
+ - Show verbose output
51
+ - bool - default: `false`
52
+ - **`--zip`**
53
+ - Create a zip file
54
+ - bool - default: `true`
55
+
56
+
57
+ ## Develop
58
+
59
+ This is a mono repository, managed with [lerna](https://lerna.js.org).
60
+
61
+ Follow the instructions for the top-level repo.
62
+ 1. `git clone` this repo & `cd` into it as usual
63
+ 2. Run `yarn` to install top-level dependencies.
64
+
65
+
66
+ ### Run
67
+
68
+ To run a local development copy, `cd` into this directory, and use `yarn dev` instead of `migrate` like so:
69
+
70
+ ```sh
71
+ yarn dev buttondown <commands>
72
+ ```
73
+
74
+
75
+ ## Test
76
+
77
+ - `yarn lint` run just eslint
78
+ - `yarn test` run lint and tests
79
+
80
+
81
+ # Copyright & License
82
+
83
+ Copyright (c) 2013-2025 Ghost Foundation - Released under the [MIT license](LICENSE).
@@ -0,0 +1,6 @@
1
+ import { contentStats, readZip } from './lib/read-zip.js';
2
+ declare const _default: (args: any) => Promise<import("@tryghost/errors").NoContentError | {
3
+ posts: mappedDataObject[];
4
+ }>;
5
+ export default _default;
6
+ export { contentStats, readZip };
package/build/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { mapContent } from './lib/mapper.js';
2
+ import { contentStats, readZip } from './lib/read-zip.js';
3
+ export default async (args) => {
4
+ const theZip = await readZip(args.options.pathToZip);
5
+ args.posts = theZip.posts;
6
+ args.json = theZip.json;
7
+ const result = await mapContent(args);
8
+ return result;
9
+ };
10
+ export { contentStats, readZip };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAExD,eAAe,KAAK,EAAE,IAAS,EAAE,EAAE;IAC/B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC1B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAExB,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,OAAO,EACV,CAAC"}
@@ -0,0 +1,13 @@
1
+ import errors from '@tryghost/errors';
2
+ declare const mapPosts: ({ posts, options }: {
3
+ posts: buttondownPostDataObject[];
4
+ options: any;
5
+ }) => Promise<mappedDataObject[]>;
6
+ declare const mapContent: (args: {
7
+ options: any;
8
+ posts?: object[];
9
+ json: buttondownPostDataObject[];
10
+ }) => Promise<errors.NoContentError | {
11
+ posts: mappedDataObject[];
12
+ }>;
13
+ export { mapPosts, mapContent };
@@ -0,0 +1,55 @@
1
+ import errors from '@tryghost/errors';
2
+ import { processHTML } from './process.js';
3
+ const mapPost = ({ postData, options }) => {
4
+ const postDate = new Date(postData.publish_date);
5
+ const mappedData = {
6
+ url: `${options.url}/${postData.slug}`,
7
+ data: {
8
+ slug: postData.slug,
9
+ published_at: postDate,
10
+ updated_at: postDate,
11
+ created_at: postDate,
12
+ title: postData.subject,
13
+ type: 'post',
14
+ html: postData.html,
15
+ status: 'published',
16
+ custom_excerpt: null,
17
+ visibility: 'public',
18
+ tags: []
19
+ }
20
+ };
21
+ mappedData.data.tags.push({
22
+ url: 'migrator-added-tag-hash-buttondown',
23
+ data: {
24
+ slug: 'hash-buttondown',
25
+ name: '#buttondown'
26
+ }
27
+ });
28
+ mappedData.data.html = processHTML({ postData: mappedData });
29
+ return mappedData;
30
+ };
31
+ const mapPosts = async ({ posts, options }) => {
32
+ const mappedPosts = posts.map((postData) => {
33
+ return mapPost({ postData, options });
34
+ });
35
+ return mappedPosts;
36
+ };
37
+ const mapContent = async (args) => {
38
+ const output = {
39
+ posts: []
40
+ };
41
+ if (args?.posts && args?.posts?.length < 1) {
42
+ return new errors.NoContentError({ message: 'Input file is empty' });
43
+ }
44
+ // Inline the HTML we have with the CSV data
45
+ args.json.map((post) => {
46
+ const thisPostHTML = args?.posts?.find((item) => item.name === `${post.slug}.md`);
47
+ post.html = thisPostHTML?.html ?? '';
48
+ return post;
49
+ });
50
+ let mappedPosts = await mapPosts({ posts: args.json, options: args.options });
51
+ output.posts = mappedPosts;
52
+ return output;
53
+ };
54
+ export { mapPosts, mapContent };
55
+ //# sourceMappingURL=mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.js","sourceRoot":"","sources":["../../src/lib/mapper.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAEzC,MAAM,OAAO,GAAG,CAAC,EAAC,QAAQ,EAAE,OAAO,EAAsD,EAAE,EAAE;IACzF,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAEjD,MAAM,UAAU,GAAqB;QACjC,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE;QACt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;IACvE,CAAC;IAED,4CAA4C;IAC5C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;QACxB,MAAM,YAAY,GAAQ,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;QAC5F,IAAI,CAAC,IAAI,GAAG,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAI,WAAW,GAAuB,MAAM,QAAQ,CAAC,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC;IAEhG,MAAM,CAAC,KAAK,GAAG,WAAW,CAAC;IAE3B,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,OAAO,EACH,QAAQ,EACR,UAAU,EACb,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const processHTML: ({ postData }: {
2
+ postData?: mappedDataObject;
3
+ }) => any;
4
+ export { processHTML };
@@ -0,0 +1,51 @@
1
+ import MarkdownIt from 'markdown-it';
2
+ import MarkdownItFootnote from 'markdown-it-footnote';
3
+ import * as cheerio from 'cheerio';
4
+ const processHTML = ({ postData }) => {
5
+ const md = new MarkdownIt({
6
+ html: true
7
+ }).use(MarkdownItFootnote);
8
+ if (!postData?.data?.html) {
9
+ return '';
10
+ }
11
+ let html = postData.data.html;
12
+ // Strip HTML comments
13
+ html = html.replace(/<!--(.*?)-->/gm, '');
14
+ let renderedHtml = md.render(html);
15
+ const $ = cheerio.load(renderedHtml, {
16
+ xmlMode: false,
17
+ decodeEntities: false
18
+ });
19
+ // Handle embeded tweets
20
+ $('blockquote.twitter-tweet').each((i, el) => {
21
+ let $figure = $('<figure class="kg-card kg-embed-card"></figure>');
22
+ let $script = $('<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>');
23
+ $(el).wrap($figure);
24
+ $figure.append($script);
25
+ $figure.before('<!--kg-card-begin: embed-->');
26
+ $figure.after('<!--kg-card-end: embed-->');
27
+ });
28
+ // Move the .footnotes-sep HR so it's inside the .footnotes element
29
+ $('.footnotes-sep').each((i, el) => {
30
+ $(el).prependTo($('.footnotes'));
31
+ });
32
+ // Wrap footnotes in a HTML card
33
+ $('.footnotes').each((i, el) => {
34
+ $(el).before('<!--kg-card-begin: html-->');
35
+ $(el).after('<!--kg-card-end: html-->');
36
+ });
37
+ $('p').each((i, el) => {
38
+ if ($(el).text().includes('{{ subscribe_form }}')) {
39
+ $(el).remove();
40
+ }
41
+ });
42
+ $('p').each((i, el) => {
43
+ if ($(el).text().trim().length === 0) {
44
+ $(el).remove();
45
+ }
46
+ });
47
+ let finalHtml = $('body').html();
48
+ return finalHtml;
49
+ };
50
+ export { processHTML };
51
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/lib/process.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,GAAG,CAAC,EAAC,QAAQ,EAAgC,EAAE,EAAE;IAC9D,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC;QACtB,IAAI,EAAE,IAAI;KACb,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAE3B,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;IAE9B,sBAAsB;IACtB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE1C,IA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AC,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;YAChD,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;QACnB,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAO,EAAE,EAAE;QAC5B,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;QACnB,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAEjC,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,OAAO,EACH,WAAW,EACd,CAAC"}
@@ -0,0 +1,5 @@
1
+ declare const contentStats: (zipPath: string) => Promise<{
2
+ posts: any;
3
+ }>;
4
+ declare const readZip: (zipPath: string) => any;
5
+ export { contentStats, readZip };
@@ -0,0 +1,30 @@
1
+ import fsUtils from '@tryghost/mg-fs-utils';
2
+ const contentStats = async (zipPath) => {
3
+ const entries = await fsUtils.readZipEntries(zipPath);
4
+ const posts = entries.filter((value) => /emails\/.*\.md/.test(value)).length;
5
+ return {
6
+ posts: posts
7
+ };
8
+ };
9
+ const readZip = (zipPath) => {
10
+ let content = {
11
+ json: null,
12
+ posts: []
13
+ };
14
+ fsUtils.zip.read(zipPath, (entryName, zipEntry) => {
15
+ // Catch all MD files inside `emails/`
16
+ if (/^emails\/.*\.md$/.test(entryName) || /\/emails\/.*\.md$/.test(entryName)) {
17
+ content.posts.push({
18
+ name: entryName.replace('emails/', ''),
19
+ html: zipEntry.getData().toString('utf8')
20
+ });
21
+ // Get the emails.json
22
+ }
23
+ else if (entryName === 'emails.json' || entryName.endsWith('/emails.json')) {
24
+ content.json = JSON.parse(zipEntry.getData().toString('utf8'));
25
+ }
26
+ });
27
+ return content;
28
+ };
29
+ export { contentStats, readZip };
30
+ //# sourceMappingURL=read-zip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-zip.js","sourceRoot":"","sources":["../../src/lib/read-zip.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAE5C,MAAM,YAAY,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAErF,OAAO;QACH,KAAK,EAAE,KAAK;KACf,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE;IAChC,IAAI,OAAO,GAAQ;QACf,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,EAAE;KACZ,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,SAAiB,EAAE,QAAa,EAAE,EAAE;QAC3D,sCAAsC;QACtC,IAAI,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5E,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;gBACtC,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;aAC5C,CAAC,CAAC;YAEP,sBAAsB;QACtB,CAAC;aAAM,IAAI,SAAS,KAAK,aAAa,IAAI,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAC3E,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,OAAO,EACV,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import { URL } from 'node:url';
2
+ import { readFileSync } from 'node:fs';
3
+ import assert from 'node:assert/strict';
4
+ import { join } from 'node:path';
5
+ import { mapContent } from '../lib/mapper.js';
6
+ const __dirname = new URL('.', import.meta.url).pathname;
7
+ const fixturesPath = join(__dirname, '../../src/test/fixtures');
8
+ const input = {
9
+ json: JSON.parse(readFileSync(join(fixturesPath, '/emails.json'), 'utf8')),
10
+ posts: [
11
+ {
12
+ name: 'plain-post.md',
13
+ html: readFileSync(join(fixturesPath, '/emails/plain-post.md'), 'utf8')
14
+ },
15
+ {
16
+ name: 'fancy-post.md',
17
+ html: readFileSync(join(fixturesPath, '/emails/fancy-post.md'), 'utf8')
18
+ }
19
+ ]
20
+ };
21
+ describe('Buttondown Mapper', () => {
22
+ it('Maps a post', async function () {
23
+ const result = await mapContent({
24
+ options: {
25
+ url: 'https://example.com'
26
+ },
27
+ posts: input.posts,
28
+ json: input.json
29
+ });
30
+ if (!('posts' in result)) {
31
+ return;
32
+ }
33
+ const mappedData = result;
34
+ assert.equal(mappedData.posts.length, 2);
35
+ assert.equal(mappedData.posts[0].url, 'https://example.com/plain-post');
36
+ assert.equal(mappedData.posts[0].data.slug, 'plain-post');
37
+ assert.equal(mappedData.posts[0].data.published_at.toISOString(), '2023-01-02T16:55:00.000Z');
38
+ assert.equal(mappedData.posts[0].data.updated_at.toISOString(), '2023-01-02T16:55:00.000Z');
39
+ assert.equal(mappedData.posts[0].data.created_at.toISOString(), '2023-01-02T16:55:00.000Z');
40
+ assert.equal(mappedData.posts[0].data.title, 'This is a Plain Post');
41
+ assert.equal(mappedData.posts[0].data.status, 'published');
42
+ assert.equal(mappedData.posts[0].data.custom_excerpt, null);
43
+ assert.equal(mappedData.posts[0].data.visibility, 'public');
44
+ assert.equal(mappedData.posts[0].data.type, 'post');
45
+ assert.equal(mappedData.posts[0].data.tags.length, 1);
46
+ assert.equal(mappedData.posts[0].data.tags[0].url, 'migrator-added-tag-hash-buttondown');
47
+ assert.equal(mappedData.posts[0].data.tags[0].data.slug, 'hash-buttondown');
48
+ assert.equal(mappedData.posts[0].data.tags[0].data.name, '#buttondown');
49
+ });
50
+ it('Returns error if no post files are provided', async function () {
51
+ let inputClone = JSON.parse(JSON.stringify(input));
52
+ inputClone.posts = [];
53
+ const result = await mapContent({
54
+ options: {},
55
+ posts: inputClone.posts,
56
+ json: inputClone.json
57
+ });
58
+ assert.ok(result instanceof Error);
59
+ assert.equal(result.message, 'Input file is empty');
60
+ });
61
+ it('Uses blank HTML if file provided for post', async function () {
62
+ let inputClone = JSON.parse(JSON.stringify(input));
63
+ inputClone.json.push({
64
+ subject: 'Does Not Exist',
65
+ publish_date: '2023-01-02 16:55:00+00:00',
66
+ slug: 'does-not-exist'
67
+ });
68
+ const result = await mapContent({
69
+ options: {},
70
+ posts: inputClone.posts,
71
+ json: inputClone.json
72
+ });
73
+ assert.equal(result.posts[2].data.html, '');
74
+ });
75
+ });
76
+ //# sourceMappingURL=mapper.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.test.js","sourceRoot":"","sources":["../../src/test/mapper.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AACrC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,C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M,UAAU,CAAC;YACjC,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,IAAI,EAAE,UAAU,CAAC,IAAI;SACxB,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import assert from 'node:assert/strict';
2
+ import { URL } from 'node:url';
3
+ import { readFileSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { processHTML } from '../lib/process.js';
6
+ const __dirname = new URL('.', import.meta.url).pathname;
7
+ const fixturesPath = join(__dirname, '../../src/test/fixtures');
8
+ const dummyPost = {
9
+ url: 'https://example.com/test-post',
10
+ data: {
11
+ slug: 'test-post',
12
+ published_at: new Date(),
13
+ updated_at: new Date(),
14
+ created_at: new Date(),
15
+ title: 'Test Post',
16
+ type: 'post',
17
+ html: '',
18
+ status: 'published',
19
+ custom_excerpt: null,
20
+ visibility: 'public',
21
+ tags: []
22
+ }
23
+ };
24
+ describe('Buttondown Processor', () => {
25
+ it('Handles no HTML', async function () {
26
+ const renderedHtml = processHTML({ postData: { ...dummyPost, data: { ...dummyPost.data } } });
27
+ assert.equal(renderedHtml, '');
28
+ });
29
+ it('Does not return body tags', async function () {
30
+ const sampleString = '<p>Hello world</p>';
31
+ const renderedHtml = processHTML({ postData: { ...dummyPost, data: { ...dummyPost.data, html: sampleString } } });
32
+ assert.equal(renderedHtml, sampleString);
33
+ });
34
+ it('Removes signup from shortcodes HTML', async function () {
35
+ const sampleString = '<p>{{ subscribe_form }}</p><p>Hello world</p>';
36
+ const renderedHtml = processHTML({ postData: { ...dummyPost, data: { ...dummyPost.data, html: sampleString } } });
37
+ assert.equal(renderedHtml, '<p>Hello world</p>');
38
+ });
39
+ it('Removes signup from shortcodes Markdown', async function () {
40
+ const sampleString = 'Hello world\r\r{{ subscribe_form }}';
41
+ const renderedHtml = processHTML({ postData: { ...dummyPost, data: { ...dummyPost.data, html: sampleString } } });
42
+ assert.equal(renderedHtml, '<p>Hello world</p>\n\n');
43
+ });
44
+ it('Processes Markdown', async function () {
45
+ const plainMd = readFileSync(join(fixturesPath, '/emails/plain-post.md'), 'utf8');
46
+ const renderedHtml = processHTML({ postData: { ...dummyPost, data: { ...dummyPost.data, html: plainMd } } });
47
+ assert.ok(!renderedHtml.includes('<!-- buttondown-editor-mode: plaintext -->'));
48
+ assert.ok(renderedHtml.includes('<h2>Lorem ipsum dolor sit amet.</h2>'));
49
+ assert.ok(!renderedHtml.includes('## Lorem ipsum dolor sit amet.'));
50
+ assert.ok(!renderedHtml.includes('```css\n' +
51
+ 'p {\n' +
52
+ ' color: #bada55;\n' +
53
+ '}'));
54
+ assert.ok(renderedHtml.includes('<pre><code class="language-css">p {\n' +
55
+ ' color: #bada55;\n' +
56
+ '}\n' +
57
+ '</code></pre>'));
58
+ assert.ok(!renderedHtml.includes('1. Excepteur sint occaecat\n' +
59
+ '2. cupidatat non proident\n' +
60
+ ' 3. Sunt in culpa qui officia\n' +
61
+ '4. deserunt mollit anim id est laborum.\n'));
62
+ assert.ok(renderedHtml.includes('<ol>\n' +
63
+ '<li>Excepteur sint occaecat</li>\n' +
64
+ '<li>cupidatat non proident\n' +
65
+ '3. Sunt in culpa qui officia</li>\n' +
66
+ '<li>deserunt mollit anim id est laborum.</li>\n' +
67
+ '</ol>'));
68
+ });
69
+ it('Processes HTML', async function () {
70
+ const fancyMd = readFileSync(join(fixturesPath, '/emails/fancy-post.md'), 'utf8');
71
+ const renderedHtml = processHTML({ postData: { ...dummyPost, data: { ...dummyPost.data, html: fancyMd } } });
72
+ assert.ok(!renderedHtml.includes('<!-- buttondown-editor-mode: fancy -->'));
73
+ assert.ok(renderedHtml.includes('<h2>Lorem ipsum dolor sit amet.</h2>'));
74
+ });
75
+ });
76
+ //# sourceMappingURL=process.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.test.js","sourceRoot":"","sources":["../../src/test/process.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AACrC,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAE9C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;AACzD,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;AAEhE,MAAM,SAAS,GAAqB;IAChC,GAAG,EAAE,+BAA+B;IACpC,IAAI,EAAE;QACF,IAAI,EAAE,WAAW;QACjB,YAAY,EAAE,IAAI,IAAI,EAAE;QACxB,UAAU,EAAE,IAAI,IAAI,EAAE;QACtB,UAAU,EAAE,IAAI,IAAI,EAAE;QACtB,KAAK,EAAE,WAAW;QAClB,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,WAAW;QACnB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,QAAQ;QACpB,IAAI,EAAE,EAAE;KACX;CACJ,CAAC;AAEF,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,iBAAiB,EAAE,KAAK;QACvB,MAAM,YAAY,GAAG,WAAW,CAAC,EAAC,QAAQ,EAAE,EAAC,GAAG,SAAS,EAAE,IAAI,EAAE,EAAC,GAAG,SAAS,CAAC,IAAI,EAAC,EAAC,EAAC,CAAC,CAAC;QAExF,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC,C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AAC,CAAC;QAEvG,MAAM,CAAC,EAAE,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,wCAAwC,CAAC,CAAC,CAAC;QAC5E,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,sCAAsC,CAAC,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
1
+ import { URL } from 'node:url';
2
+ import { unlink } from 'node:fs';
3
+ import assert from 'node:assert/strict';
4
+ import { join } from 'node:path';
5
+ import { execSync } from 'node:child_process';
6
+ import mapper, { contentStats, readZip } from '../index.js';
7
+ const __dirname = new URL('.', import.meta.url).pathname;
8
+ const fixturesPath = join(__dirname, '../../src/test/fixtures');
9
+ const inputZipPath = join(__dirname, '/export.zip');
10
+ describe('Buttondown Zip Reader', () => {
11
+ beforeAll(function () {
12
+ execSync(`zip -r ${inputZipPath} *`, {
13
+ cwd: fixturesPath
14
+ });
15
+ });
16
+ afterAll(function () {
17
+ unlink(inputZipPath, (err) => {
18
+ if (err) {
19
+ throw err;
20
+ }
21
+ });
22
+ });
23
+ it('Reads ZIP and gets stats', async function () {
24
+ const stats = await contentStats(inputZipPath);
25
+ assert.equal(stats.posts, 2);
26
+ });
27
+ it('Reads ZIP and combine contents', async function () {
28
+ const data = await readZip(inputZipPath);
29
+ assert.equal(data.json.length, 2);
30
+ assert.equal(data.json[0].subject, 'This is a Plain Post');
31
+ assert.equal(data.json[0].slug, 'plain-post');
32
+ assert.equal(data.posts.length, 2);
33
+ assert.equal(data.posts[0].name, 'plain-post.md');
34
+ });
35
+ it('Reads ZIP and maps', async function () {
36
+ const data = await mapper({
37
+ options: {
38
+ url: 'https://example.com',
39
+ pathToZip: inputZipPath
40
+ }
41
+ });
42
+ assert.equal(data.posts.length, 2);
43
+ assert.equal(data.posts[0].url, 'https://example.com/plain-post');
44
+ });
45
+ });
46
+ //# sourceMappingURL=read-zip.test.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,EAAE,KAAK;QACtC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC9C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oBAAoB,EAAE,KAAK;QAC1B,MAAM,IAAI,GAAQ,MAAM,MAAM,CAAC;YAC3B,OAAO,EAAE;gBACL,GAAG,EAAE,qBAAqB;gBAC1B,SAAS,EAAE,YAAY;aAC1B;SACJ,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,gCAAgC,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@tryghost/mg-buttondown",
3
+ "version": "0.1.1",
4
+ "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-buttondown",
5
+ "author": "Ghost Foundation",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "build/index.js",
9
+ "types": "build/types.d.ts",
10
+ "scripts": {
11
+ "dev": "echo \"Implement me!\"",
12
+ "build:watch": "tsc --watch --preserveWatchOutput --sourceMap",
13
+ "build": "rm -rf build && rm -rf tsconfig.tsbuildinfo && tsc --build --sourceMap",
14
+ "prepare": "yarn build",
15
+ "lint": "eslint src/ --ext .ts --cache",
16
+ "posttest": "yarn lint",
17
+ "test": "rm -rf build && yarn build --force && NODE_OPTIONS=--experimental-vm-modules c8 --src src --all --check-coverage --100 --reporter text --reporter cobertura jest build/test"
18
+ },
19
+ "files": [
20
+ "build"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "devDependencies": {
26
+ "@types/jest": "^30.0.0",
27
+ "@types/sinon": "^17.0.0",
28
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
29
+ "@typescript-eslint/parser": "^8.0.0",
30
+ "c8": "10.1.3",
31
+ "dotenv": "17.2.0",
32
+ "eslint": "8.57.0",
33
+ "jest": "30.0.5",
34
+ "sinon": "^21.0.0",
35
+ "typescript": "5.8.3"
36
+ },
37
+ "dependencies": {
38
+ "@tryghost/errors": "1.3.8",
39
+ "@tryghost/mg-fs-utils": "0.12.14",
40
+ "cheerio": "1.1.2",
41
+ "markdown-it": "14.1.0",
42
+ "markdown-it-footnote": "4.0.0"
43
+ },
44
+ "gitHead": "e4d324f13cba2bb4b2e8c6169eabfb79ea038373"
45
+ }