@tryghost/mg-jekyll-export 0.13.1 → 0.13.3
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/README.md +2 -2
- package/lib/process-html.js +5 -7
- package/lib/process-post.js +17 -15
- package/lib/process.js +1 -3
- package/lib/read-zip.js +1 -1
- package/package.json +5 -9
package/README.md
CHANGED
|
@@ -107,8 +107,8 @@ pnpm dev jekyll --pathToZip /path/to/site.zip
|
|
|
107
107
|
|
|
108
108
|
## Test
|
|
109
109
|
|
|
110
|
-
- `pnpm
|
|
111
|
-
-
|
|
110
|
+
- `pnpm test` runs the package tests
|
|
111
|
+
- Linting and formatting are run from the repo root (`pnpm lint`, `pnpm format`)
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
# Copyright & License
|
package/lib/process-html.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import {domUtils} from '@tryghost/mg-utils';
|
|
2
2
|
|
|
3
|
-
const {serializeChildren} = domUtils;
|
|
4
|
-
|
|
5
3
|
/*
|
|
6
4
|
Process the HTML of a single Jekyll Post.
|
|
7
5
|
|
|
@@ -9,7 +7,7 @@ Receives raw HTML, returns processed HTML
|
|
|
9
7
|
*/
|
|
10
8
|
|
|
11
9
|
export default (rawHtml, options = {}) => {
|
|
12
|
-
return domUtils.processFragment(rawHtml,
|
|
10
|
+
return domUtils.processFragment(rawHtml, parsed => {
|
|
13
11
|
// Convert relative links and image paths to absolute
|
|
14
12
|
if (options.url) {
|
|
15
13
|
const urlData = new URL(options.url);
|
|
@@ -18,7 +16,7 @@ export default (rawHtml, options = {}) => {
|
|
|
18
16
|
// in sub-directories so that relative and relative-to-root URLs resolve correctly.
|
|
19
17
|
const urlOrigin = urlData.origin;
|
|
20
18
|
|
|
21
|
-
parsed.$('a').forEach(
|
|
19
|
+
parsed.$('a').forEach(anchor => {
|
|
22
20
|
const thisURL = anchor.getAttribute('href');
|
|
23
21
|
|
|
24
22
|
// If it starts with a slash, append the base URL
|
|
@@ -28,7 +26,7 @@ export default (rawHtml, options = {}) => {
|
|
|
28
26
|
}
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
parsed.$('img').forEach(
|
|
29
|
+
parsed.$('img').forEach(img => {
|
|
32
30
|
const thisSrc = img.getAttribute('src');
|
|
33
31
|
|
|
34
32
|
// If it starts with a slash, append the base URL
|
|
@@ -40,11 +38,11 @@ export default (rawHtml, options = {}) => {
|
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
// Unwrap <p> tags that are in <li> tags
|
|
43
|
-
parsed.$('li').forEach(
|
|
41
|
+
parsed.$('li').forEach(li => {
|
|
44
42
|
const p = li.querySelector('p');
|
|
45
43
|
|
|
46
44
|
if (p) {
|
|
47
|
-
li.
|
|
45
|
+
li.replaceChildren(...p.childNodes);
|
|
48
46
|
}
|
|
49
47
|
});
|
|
50
48
|
|
package/lib/process-post.js
CHANGED
|
@@ -14,12 +14,12 @@ function _parseFrontMatterDate(fmDate) {
|
|
|
14
14
|
// The date was unquoted in the frontmatter, it gets parsed into a data object
|
|
15
15
|
if (typeof fmDate === 'object') {
|
|
16
16
|
postDate = fmDate;
|
|
17
|
-
|
|
17
|
+
// Otherwise the date gets parsed as a string
|
|
18
18
|
} else {
|
|
19
19
|
const frontMaterDateRegex = new RegExp('([0-9]{4})[-:/\\ ]([0-9]{2})[-:/\\ ]([0-9]{2})');
|
|
20
20
|
|
|
21
21
|
const dateParts = fmDate.match(frontMaterDateRegex);
|
|
22
|
-
postDate = new Date(Date.UTC(dateParts[1],
|
|
22
|
+
postDate = new Date(Date.UTC(dateParts[1], dateParts[2] - 1, dateParts[3])); // Months are zero-index, so 11 equals December
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
return postDate;
|
|
@@ -63,7 +63,7 @@ const processMeta = (fileName, fileContents, options) => {
|
|
|
63
63
|
slugParts = fileName.match(slugRegex);
|
|
64
64
|
postSlug = slugParts[2];
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
// If it's a post with no `date` frontmatter
|
|
67
67
|
} else {
|
|
68
68
|
const datedSlugRegex = new RegExp('([0-9a-zA-Z-_]+)/([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})-(.*).(md|markdown|html)');
|
|
69
69
|
slugParts = fileName.match(datedSlugRegex);
|
|
@@ -77,20 +77,23 @@ const processMeta = (fileName, fileContents, options) => {
|
|
|
77
77
|
const dateYear = slugParts[2].split(/[-/]/)[0];
|
|
78
78
|
const dateMonth = ('0' + slugParts[2].split(/[-/]/)[1]).slice(-2);
|
|
79
79
|
const dateDay = ('0' + slugParts[2].split(/[-/]/)[2]).slice(-2);
|
|
80
|
-
postDate = new Date(Date.UTC(dateYear,
|
|
80
|
+
postDate = new Date(Date.UTC(dateYear, dateMonth - 1, dateDay)); // Months are zero-index, so 11 equals December
|
|
81
81
|
if (!postSlug) {
|
|
82
82
|
postSlug = slugParts[3];
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const post = {
|
|
87
|
-
url:
|
|
87
|
+
url:
|
|
88
|
+
options && options.url
|
|
89
|
+
? `${options.url.replace(/^\/|\/$/g, '')}/${postSlug.replace(/^\/|\/$/g, '')}`
|
|
90
|
+
: postSlug, // Combine URL & slug, and replace extra slashes
|
|
88
91
|
data: {
|
|
89
92
|
slug: postSlug
|
|
90
93
|
}
|
|
91
94
|
};
|
|
92
95
|
|
|
93
|
-
const isDraft =
|
|
96
|
+
const isDraft = inDraftsDir || frontmatterAttributes.published === false;
|
|
94
97
|
|
|
95
98
|
// This will be processed more later and deleted
|
|
96
99
|
post._body = frontmatter.body;
|
|
@@ -101,7 +104,7 @@ const processMeta = (fileName, fileContents, options) => {
|
|
|
101
104
|
post.data.updated_at = postDate || dateNow;
|
|
102
105
|
|
|
103
106
|
post.data.type = 'post';
|
|
104
|
-
post.data.status =
|
|
107
|
+
post.data.status = isDraft ? 'draft' : 'published';
|
|
105
108
|
|
|
106
109
|
post.data.email_only = false;
|
|
107
110
|
|
|
@@ -111,12 +114,10 @@ const processMeta = (fileName, fileContents, options) => {
|
|
|
111
114
|
post.data.author = {
|
|
112
115
|
url: string.slugify(frontmatterAttributes.author),
|
|
113
116
|
data: {
|
|
114
|
-
email: `${string.slugify(frontmatterAttributes.author)}@${
|
|
117
|
+
email: `${string.slugify(frontmatterAttributes.author)}@${options.email ? options.email : 'example.com'}`,
|
|
115
118
|
name: frontmatterAttributes.author,
|
|
116
119
|
slug: string.slugify(frontmatterAttributes.author),
|
|
117
|
-
roles: [
|
|
118
|
-
'Contributor'
|
|
119
|
-
]
|
|
120
|
+
roles: ['Contributor']
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
123
|
}
|
|
@@ -146,7 +147,7 @@ const processMeta = (fileName, fileContents, options) => {
|
|
|
146
147
|
normalizedCats = frontmatterAttributes.categories.split(' ');
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
normalizedCats.forEach(
|
|
150
|
+
normalizedCats.forEach(tag => {
|
|
150
151
|
post.data.tags.push({
|
|
151
152
|
url: `migrator-added-tag-category-${string.slugify(tag)}`,
|
|
152
153
|
data: {
|
|
@@ -176,7 +177,7 @@ const processMeta = (fileName, fileContents, options) => {
|
|
|
176
177
|
normalizedTags = frontmatterAttributes.tags.split(' ');
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
normalizedTags.forEach(
|
|
180
|
+
normalizedTags.forEach(tag => {
|
|
180
181
|
post.data.tags.push({
|
|
181
182
|
url: `migrator-added-tag-${string.slugify(tag)}`,
|
|
182
183
|
data: {
|
|
@@ -233,7 +234,8 @@ export default (fileName, fileContents, globalUser = false, options = {}) => {
|
|
|
233
234
|
|
|
234
235
|
// Add extra tags
|
|
235
236
|
post.data.tags.push({
|
|
236
|
-
url: 'migrator-added-tag',
|
|
237
|
+
url: 'migrator-added-tag',
|
|
238
|
+
data: {
|
|
237
239
|
name: '#jekyll',
|
|
238
240
|
slug: 'hash-jekyll'
|
|
239
241
|
}
|
|
@@ -242,7 +244,7 @@ export default (fileName, fileContents, globalUser = false, options = {}) => {
|
|
|
242
244
|
if (options.addTags) {
|
|
243
245
|
let theTags = options.addTags.split(',').map(item => item.trim());
|
|
244
246
|
|
|
245
|
-
theTags.forEach(
|
|
247
|
+
theTags.forEach(tag => {
|
|
246
248
|
let tagSlug = string.slugify(tag.replace('#', 'hash-'));
|
|
247
249
|
|
|
248
250
|
post.data.tags.push({
|
package/lib/process.js
CHANGED
package/lib/read-zip.js
CHANGED
|
@@ -25,7 +25,7 @@ export default (zipPath, options) => {
|
|
|
25
25
|
fileContents: zipEntry.getData().toString('utf8')
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// Skip if not matched above, and report skipped files if `--verbose`
|
|
29
29
|
} else {
|
|
30
30
|
if (options.verbose) {
|
|
31
31
|
ui.log.info('Skipped: ' + zipEntry.entryName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-jekyll-export",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"description": "tbc",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,22 +18,18 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"eslint": "8.57.1"
|
|
23
|
-
},
|
|
21
|
+
"devDependencies": {},
|
|
24
22
|
"dependencies": {
|
|
25
23
|
"@tryghost/errors": "3.2.4",
|
|
26
24
|
"@tryghost/pretty-cli": "3.2.3",
|
|
27
25
|
"@tryghost/string": "0.3.5",
|
|
28
26
|
"front-matter": "4.0.2",
|
|
29
27
|
"markdown-it": "14.2.0",
|
|
30
|
-
"@tryghost/mg-fs-utils": "0.26.
|
|
31
|
-
"@tryghost/mg-utils": "0.11.
|
|
28
|
+
"@tryghost/mg-fs-utils": "0.26.3",
|
|
29
|
+
"@tryghost/mg-utils": "0.11.3"
|
|
32
30
|
},
|
|
33
31
|
"scripts": {
|
|
34
32
|
"dev": "echo \"Implement me!\"",
|
|
35
|
-
"test": "node --test 'test/**/*.test.js'"
|
|
36
|
-
"posttest": "pnpm lint",
|
|
37
|
-
"lint": "eslint . --ext .js --cache"
|
|
33
|
+
"test": "node --test 'test/**/*.test.js'"
|
|
38
34
|
}
|
|
39
35
|
}
|