wordpress-to-kirby 0.2.0 → 0.3.0
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/.github/wordpress-to-kirby.svg +1 -0
- package/README.md +66 -10
- package/index.js +229 -142
- package/package.json +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="401.42" height="207.25" viewBox="0 0 401.42 207.25"><path d="M98.43,5.2C44.07,5.2,0,49.26,0,103.63s44.07,98.43,98.43,98.43,98.43-44.07,98.43-98.43S152.79,5.2,98.43,5.2ZM98.43,187.06c-46,0-83.43-37.43-83.43-83.43S52.43,20.2,98.43,20.2s83.43,37.43,83.43,83.43-37.43,83.43-83.43,83.43ZM311.67,0l-89.74,51.81v103.63l89.74,51.81,89.74-51.81V51.81L311.67,0ZM386.42,146.78l-74.74,43.15-74.74-43.15V60.47l74.74-43.15,74.74,43.15v86.31ZM339.73,117.54l15.64-10.65v35.93l-15.64-9.09h-57.78l-15.3,9.65v-35.49l15.3,9.65h57.78ZM310.64,111.91l-44-24.64v-18.96c2.15,1.7,4.82,3.94,8.04,6.71,3.22,2.77,6.65,5.82,10.31,9.15,3.66,3.33,7.28,6.75,10.87,10.26,2.72,2.67,5.26,5.26,7.62,7.77,8.64-5.37,16.97-11.24,24.98-17.64,8.47-6.76,16.62-13.66,24.45-20.68.81,1.63,1.65,3.31,2.5,5.05.85,1.74,1.27,3.75,1.27,6.04,0,3.55-1.02,6.99-3.05,10.31-2.03,3.33-4.97,6.29-8.82,8.87l-31.16,20.85-3.03-3.08ZM158.26,68.75l-8.87,15.42-28.39,73.3h-3.77l-19.53-49.53-17.07,49.53h-3.77l-28.83-73.42-9.43-15.3h27.95l.22,15.3,14.88,39.99,15.15-18.39-8.52-21.6-7.32-15.3h20.52l21.53,58.61,13.18-43.3-2.33-15.3h24.4Z"/></svg>
|
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# wordpress-to-kirby
|
|
2
2
|
|
|
3
|
+
<img src="./.github/wordpress-to-kirby.svg" height='60'>
|
|
4
|
+
|
|
5
|
+
<a href="https://www.npmjs.org/package/wordpress-to-kirby"><img src="https://img.shields.io/npm/v/wordpress-to-kirby.svg?style=flat-square&labelColor=EEEEEE&color=black" alt="npm version"></a>
|
|
6
|
+
|
|
3
7
|
A Node.js-based command-line utility to convert a WordPress XML export to a directory of Kirby CMS files.
|
|
4
8
|
|
|
5
9
|
## Getting started
|
|
@@ -38,21 +42,31 @@ wordpress-to-kirby download [options] <wordpress-xml-file>
|
|
|
38
42
|
|
|
39
43
|
## Options
|
|
40
44
|
|
|
41
|
-
###
|
|
42
|
-
|
|
43
|
-
#### `-h, --help`
|
|
45
|
+
### `-h, --help`
|
|
44
46
|
|
|
45
47
|
Prints out this help information.
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
```bash
|
|
50
|
+
wordpress-to-kirby --help
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### `-v, --version`
|
|
48
54
|
|
|
49
55
|
Shows the program version.
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
```bash
|
|
58
|
+
wordpress-to-kirby --version
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `-o, --outdir=<path>`
|
|
52
62
|
|
|
53
63
|
Root directory to which to write the output, relative to the current working directory. Default: `wordpress-to-kirby`.
|
|
54
64
|
|
|
55
|
-
|
|
65
|
+
```bash
|
|
66
|
+
wordpress-to-kirby generate my-blog.xml -o my-blog
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `--contentdir=<path>`
|
|
56
70
|
|
|
57
71
|
For the `download` command, point to the location of a `wp-content` directory from which to download attachments.
|
|
58
72
|
|
|
@@ -61,9 +75,15 @@ The path can be:
|
|
|
61
75
|
* an absolute or relative local path;
|
|
62
76
|
* a fully-qualified URL, including the `wp-content` segment, e.g. `https://mywebsite.local/wp-content/`
|
|
63
77
|
|
|
64
|
-
|
|
78
|
+
```bash
|
|
79
|
+
wordpress-to-kirby download my-blog.xml -o my-blog --contentdir=path/to/downloaded-wp-content
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `--parse=<rules>`
|
|
65
83
|
|
|
66
84
|
Instructions to parse some fields, specified as `<key>=<parser>,<key>=<parser>,…`.
|
|
85
|
+
|
|
86
|
+
The `--parse` option can be used multiple times.
|
|
67
87
|
|
|
68
88
|
Supported parsers:
|
|
69
89
|
|
|
@@ -72,10 +92,16 @@ Supported parsers:
|
|
|
72
92
|
* `json`: parse as JSON;
|
|
73
93
|
* `html`: parse as HTML.
|
|
74
94
|
|
|
75
|
-
|
|
95
|
+
```bash
|
|
96
|
+
wordpress-to-kirby generate my-blog.xml --parse=content=html
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `--serialize=<rules>`
|
|
76
100
|
|
|
77
101
|
Instructions to serialize some fields, specified as `<key>=<serializer>,<key>=<serializer>,…`.
|
|
78
102
|
|
|
103
|
+
The `--serialize` option can be used multiple times.
|
|
104
|
+
|
|
79
105
|
Supported serializers:
|
|
80
106
|
|
|
81
107
|
* `php`: serialize as PHP object;
|
|
@@ -83,23 +109,53 @@ Supported serializers:
|
|
|
83
109
|
* `json`: serialize as JSON;
|
|
84
110
|
* `html`: serialize as HTML.
|
|
85
111
|
|
|
112
|
+
```bash
|
|
113
|
+
wordpress-to-kirby generate my-blog.xml --serialize=content=html
|
|
114
|
+
```
|
|
115
|
+
|
|
86
116
|
### `--exclude-fields=<fields>`
|
|
87
117
|
|
|
88
118
|
Exclude certain fields from the output, specified as a comma-separated list of fields.
|
|
89
119
|
|
|
120
|
+
The `--exclude-fields` option can be used multiple times.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
wordpress-to-kirby generate my-blog.xml --exclude-fields=guid_isPermalink,comment_status,ping_status
|
|
124
|
+
```
|
|
125
|
+
|
|
90
126
|
### `--include-fields=<fields>`
|
|
91
127
|
|
|
92
128
|
Only include certain fields from the output, specified as a comma-separated list of fields. When `--include-fields` is specified, the `--exclude-fields` option is ignored.
|
|
93
129
|
|
|
130
|
+
The `--include-fields` option can be used multiple times.
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
wordpress-to-kirby generate my-blog.xml --include-fields=title,content,uuid
|
|
134
|
+
```
|
|
135
|
+
|
|
94
136
|
### `--exclude-types=<types>`
|
|
95
137
|
|
|
96
138
|
Exclude certain post types from the output, specified as a comma-separated list of post types.
|
|
97
139
|
|
|
140
|
+
The `--exclude-types` option can be used multiple times.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
wordpress-to-kirby generate my-blog.xml --exclude-types=nav_menu_item
|
|
144
|
+
```
|
|
145
|
+
|
|
98
146
|
### `--include-types=<types>`
|
|
99
147
|
|
|
100
|
-
Only include certain post types from the output, specified as a comma-separated list of post types.
|
|
148
|
+
Only include certain post types from the output, specified as a comma-separated list of post types. When `--include-types` is specified, the `--exclude-types` option is ignored.
|
|
149
|
+
|
|
150
|
+
The `--include-types` option can be used multiple times.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
wordpress-to-kirby generate my-blog.xml --include-types=post,page,film,venue
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `--only-metadata`
|
|
101
157
|
|
|
102
|
-
|
|
158
|
+
For the `generate` command, only generate the `metadata.json` file.
|
|
103
159
|
|
|
104
160
|
## Keys extracted from the XML
|
|
105
161
|
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFile, writeFile, copyFile, mkdir } from 'node:fs/promises';
|
|
3
3
|
import { join, dirname, extname, relative, sep } from 'node:path';
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
4
5
|
|
|
5
|
-
import opsh from 'opsh';
|
|
6
6
|
import { JSDOM } from 'jsdom';
|
|
7
7
|
import { load, dump } from 'js-yaml';
|
|
8
8
|
import { serialize, unserialize } from 'php-serialize';
|
|
@@ -16,17 +16,61 @@ async function getPackage() {
|
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const { operands, options } =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const { positionals: operands, values: options } = parseArgs({
|
|
20
|
+
options: {
|
|
21
|
+
help: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
short: 'h'
|
|
24
|
+
},
|
|
25
|
+
version: {
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
short: 'v'
|
|
28
|
+
},
|
|
29
|
+
parse: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
multiple: true
|
|
32
|
+
},
|
|
33
|
+
stringify: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
multiple: true
|
|
36
|
+
},
|
|
37
|
+
outdir: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
short: 'o',
|
|
40
|
+
default: 'wordpress-to-kirby'
|
|
41
|
+
},
|
|
42
|
+
contentdir: {
|
|
43
|
+
type: 'string'
|
|
44
|
+
},
|
|
45
|
+
'include-fields': {
|
|
46
|
+
type: 'string',
|
|
47
|
+
multiple: true
|
|
48
|
+
},
|
|
49
|
+
'exclude-fields': {
|
|
50
|
+
type: 'string',
|
|
51
|
+
multiple: true
|
|
52
|
+
},
|
|
53
|
+
'include-types': {
|
|
54
|
+
type: 'string',
|
|
55
|
+
multiple: true
|
|
56
|
+
},
|
|
57
|
+
'exclude-types': {
|
|
58
|
+
type: 'string',
|
|
59
|
+
multiple: true
|
|
60
|
+
},
|
|
61
|
+
'only-metadata': {
|
|
62
|
+
type: 'boolean'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
allowPositionals: true
|
|
66
|
+
});
|
|
23
67
|
|
|
24
|
-
if (options.
|
|
25
|
-
|
|
68
|
+
if (options.help) {
|
|
69
|
+
printHelp();
|
|
26
70
|
process.exit();
|
|
27
71
|
}
|
|
28
72
|
|
|
29
|
-
if (options.
|
|
73
|
+
if (options.version) {
|
|
30
74
|
const pkg = await getPackage();
|
|
31
75
|
console.log(pkg.version);
|
|
32
76
|
process.exit();
|
|
@@ -51,8 +95,11 @@ const serializers = {
|
|
|
51
95
|
'postmeta_wp_attachment_metadata': 'json'
|
|
52
96
|
};
|
|
53
97
|
|
|
54
|
-
function commasep(
|
|
55
|
-
return
|
|
98
|
+
function commasep(arr = []) {
|
|
99
|
+
return arr
|
|
100
|
+
.map(val => (val || '').split(/\s*,\s*/))
|
|
101
|
+
.flat()
|
|
102
|
+
.filter(Boolean);
|
|
56
103
|
}
|
|
57
104
|
|
|
58
105
|
commasep(options.parse).forEach(pair => {
|
|
@@ -91,12 +138,22 @@ function process_item(item) {
|
|
|
91
138
|
return Object.fromEntries(
|
|
92
139
|
entries.map(entry => [
|
|
93
140
|
entry[0],
|
|
94
|
-
serialize_value(entry[0], entry[1])
|
|
141
|
+
serialize_value(entry[0], entry[1], item.post_id)
|
|
95
142
|
])
|
|
96
143
|
);
|
|
97
144
|
}
|
|
98
145
|
|
|
99
|
-
function
|
|
146
|
+
function abbr(value, len = 64) {
|
|
147
|
+
if (typeof value !== 'string') {
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
if (value.length <= len) {
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
return value.slice(0, len) + '…';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function parse_value(key, value, id) {
|
|
100
157
|
if (!value) {
|
|
101
158
|
return value;
|
|
102
159
|
}
|
|
@@ -105,21 +162,21 @@ function parse_value(key, value) {
|
|
|
105
162
|
try {
|
|
106
163
|
return unserialize(value);
|
|
107
164
|
} catch(err) {
|
|
108
|
-
console.error(`Warn: Can’t
|
|
165
|
+
console.error(`Warn: Can’t parse PHP value in post ${id}, skipping: ${abbr(value)}`);
|
|
109
166
|
return value;
|
|
110
167
|
}
|
|
111
168
|
case 'yaml':
|
|
112
169
|
try {
|
|
113
170
|
return load(value);
|
|
114
171
|
} catch (err) {
|
|
115
|
-
console.error(`Warn: Can’t
|
|
172
|
+
console.error(`Warn: Can’t parse YAML value in post ${id}, skipping: ${abbr(value)}`);
|
|
116
173
|
return value;
|
|
117
174
|
}
|
|
118
175
|
case 'json':
|
|
119
176
|
try {
|
|
120
177
|
return JSON.parse(value);
|
|
121
178
|
} catch(err) {
|
|
122
|
-
console.error(`Warn: Can’t
|
|
179
|
+
console.error(`Warn: Can’t parse JSON value in post ${id}, skipping: ${abbr(value)}`);
|
|
123
180
|
return value;
|
|
124
181
|
}
|
|
125
182
|
case 'html':
|
|
@@ -128,7 +185,7 @@ function parse_value(key, value) {
|
|
|
128
185
|
`<!doctype html><html><head></head><body>${value}</body></html>`
|
|
129
186
|
).window.document;
|
|
130
187
|
} catch(err) {
|
|
131
|
-
console.error(`Warn: Can’t
|
|
188
|
+
console.error(`Warn: Can’t parse HTML value in post ${id}, skipping: ${abbr(value)}`);
|
|
132
189
|
return value;
|
|
133
190
|
}
|
|
134
191
|
default:
|
|
@@ -136,7 +193,7 @@ function parse_value(key, value) {
|
|
|
136
193
|
}
|
|
137
194
|
}
|
|
138
195
|
|
|
139
|
-
function serialize_value(key, value) {
|
|
196
|
+
function serialize_value(key, value, id) {
|
|
140
197
|
if (!value) {
|
|
141
198
|
return value;
|
|
142
199
|
}
|
|
@@ -145,28 +202,28 @@ function serialize_value(key, value) {
|
|
|
145
202
|
try {
|
|
146
203
|
return serialize(value);
|
|
147
204
|
} catch(err) {
|
|
148
|
-
console.error(`Warn: Can’t
|
|
205
|
+
console.error(`Warn: Can’t serialize PHP value in post ${id}, skipping: ${abbr(value)}`);
|
|
149
206
|
return value;
|
|
150
207
|
}
|
|
151
208
|
case 'yaml':
|
|
152
209
|
try {
|
|
153
210
|
return dump(value);
|
|
154
211
|
} catch (err) {
|
|
155
|
-
console.error(`Warn: Can’t
|
|
212
|
+
console.error(`Warn: Can’t serialize YAML value in post ${id}, skipping: ${abbr(value)}`);
|
|
156
213
|
return value;
|
|
157
214
|
}
|
|
158
215
|
case 'json':
|
|
159
216
|
try {
|
|
160
217
|
return JSON.stringify(value);
|
|
161
218
|
} catch(err) {
|
|
162
|
-
console.error(`Warn: Can’t
|
|
219
|
+
console.error(`Warn: Can’t serialize JSON value in post ${id}, skipping: ${abbr(value)}`);
|
|
163
220
|
return value;
|
|
164
221
|
}
|
|
165
222
|
case 'html':
|
|
166
223
|
try {
|
|
167
224
|
return value.body.innerHTML;
|
|
168
225
|
} catch(err) {
|
|
169
|
-
console.error(`Warn: Can’t
|
|
226
|
+
console.error(`Warn: Can’t serialize HTML value in post ${id}, skipping: ${abbr(value)}`);
|
|
170
227
|
return value;
|
|
171
228
|
}
|
|
172
229
|
default:
|
|
@@ -202,37 +259,39 @@ function extract(item) {
|
|
|
202
259
|
return (el ?? item).querySelector(sel);
|
|
203
260
|
}
|
|
204
261
|
|
|
205
|
-
const
|
|
262
|
+
const post_id = parse_value('post_id', select('post_id', 'wp').textContent);
|
|
263
|
+
|
|
264
|
+
const post_type = parse_value('post_type', select('post_type', 'wp').textContent, post_id);
|
|
206
265
|
|
|
207
266
|
return {
|
|
208
|
-
|
|
209
|
-
link: parse_value('link', select('link').textContent),
|
|
210
|
-
pubDate: parse_value('pubDate', select('pubDate').textContent),
|
|
211
|
-
creator: parse_value('creator', select('creator', 'dc').textContent),
|
|
212
|
-
guid: parse_value('guid', select('guid').textContent),
|
|
213
|
-
guid_isPermaLink: parse_value('guid_isPermaLink', select('guid').getAttribute('isPermaLink')),
|
|
214
|
-
description: parse_value('description', select('description').textContent),
|
|
215
|
-
content: parse_value('content', select('encoded', 'content').textContent),
|
|
216
|
-
excerpt: parse_value('excerpt', select('encoded', 'excerpt').textContent),
|
|
217
|
-
post_id: parse_value('post_id', select('post_id', 'wp').textContent),
|
|
218
|
-
post_date: parse_value('post_date', select('post_date', 'wp').textContent),
|
|
219
|
-
post_date_gmt: parse_value('post_date_gmt', select('post_date_gmt', 'wp').textContent),
|
|
220
|
-
post_modified: parse_value('post_modified', select('post_modified', 'wp').textContent),
|
|
221
|
-
post_modified_gmt: parse_value('post_modified_gmt', select('post_modified_gmt', 'wp').textContent),
|
|
222
|
-
comment_status: parse_value('comment_status', select('comment_status', 'wp').textContent),
|
|
223
|
-
ping_status: parse_value('ping_status', select('ping_status', 'wp').textContent),
|
|
224
|
-
post_name: parse_value('post_name', select('post_name', 'wp').textContent),
|
|
225
|
-
status: parse_value('status', select('status', 'wp').textContent),
|
|
226
|
-
post_parent: parse_value('post_parent', select('post_parent', 'wp').textContent),
|
|
227
|
-
menu_order: parse_value('menu_order', select('menu_order', 'wp').textContent),
|
|
267
|
+
post_id,
|
|
228
268
|
post_type,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
269
|
+
title: parse_value('title', select('title').textContent, post_id),
|
|
270
|
+
link: parse_value('link', select('link').textContent, post_id),
|
|
271
|
+
pubDate: parse_value('pubDate', select('pubDate').textContent, post_id),
|
|
272
|
+
creator: parse_value('creator', select('creator', 'dc').textContent, post_id),
|
|
273
|
+
guid: parse_value('guid', select('guid').textContent, post_id),
|
|
274
|
+
guid_isPermaLink: parse_value('guid_isPermaLink', select('guid').getAttribute('isPermaLink'), post_id),
|
|
275
|
+
description: parse_value('description', select('description').textContent, post_id),
|
|
276
|
+
content: parse_value('content', select('encoded', 'content').textContent, post_id),
|
|
277
|
+
excerpt: parse_value('excerpt', select('encoded', 'excerpt').textContent, post_id),
|
|
278
|
+
post_date: parse_value('post_date', select('post_date', 'wp').textContent, post_id),
|
|
279
|
+
post_date_gmt: parse_value('post_date_gmt', select('post_date_gmt', 'wp').textContent, post_id),
|
|
280
|
+
post_modified: parse_value('post_modified', select('post_modified', 'wp').textContent, post_id),
|
|
281
|
+
post_modified_gmt: parse_value('post_modified_gmt', select('post_modified_gmt', 'wp').textContent, post_id),
|
|
282
|
+
comment_status: parse_value('comment_status', select('comment_status', 'wp').textContent, post_id),
|
|
283
|
+
ping_status: parse_value('ping_status', select('ping_status', 'wp').textContent, post_id),
|
|
284
|
+
post_name: parse_value('post_name', select('post_name', 'wp').textContent, post_id),
|
|
285
|
+
status: parse_value('status', select('status', 'wp').textContent, post_id),
|
|
286
|
+
post_parent: parse_value('post_parent', select('post_parent', 'wp').textContent, post_id),
|
|
287
|
+
menu_order: parse_value('menu_order', select('menu_order', 'wp').textContent, post_id),
|
|
288
|
+
post_password: parse_value('post_password', select('post_password', 'wp').textContent, post_id),
|
|
289
|
+
attachment_url: parse_value('attachment_url', select('attachment_url', 'wp')?.textContent, post_id),
|
|
290
|
+
is_sticky: parse_value('is_sticky', select('is_sticky', 'wp').textContent, post_id),
|
|
232
291
|
...select('postmeta', 'wp', true).reduce((acc, it) => {
|
|
233
292
|
const key = select('meta_key', 'wp', false, it).textContent;
|
|
234
293
|
const value = select('meta_value', 'wp', false, it).textContent;
|
|
235
|
-
acc['postmeta' + key] = parse_value('postmeta' + key, value);
|
|
294
|
+
acc['postmeta' + key] = parse_value('postmeta' + key, value, post_id);
|
|
236
295
|
return acc;
|
|
237
296
|
}, {}),
|
|
238
297
|
uuid: uuid(),
|
|
@@ -240,7 +299,7 @@ function extract(item) {
|
|
|
240
299
|
}
|
|
241
300
|
}
|
|
242
301
|
|
|
243
|
-
const outdir = options.
|
|
302
|
+
const outdir = options.outdir;
|
|
244
303
|
|
|
245
304
|
function outpath(item) {
|
|
246
305
|
let parts = (new URL(item.link)).pathname.split('/').filter(Boolean);
|
|
@@ -255,118 +314,134 @@ function outpath(item) {
|
|
|
255
314
|
}
|
|
256
315
|
|
|
257
316
|
if (command === 'generate') {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
await mkdir(dirname(destination), { recursive: true });
|
|
261
|
-
await writeFile(destination, serialize_item(process_item(item)));
|
|
262
|
-
};
|
|
317
|
+
|
|
318
|
+
const processed_items = items.map(process_item);
|
|
263
319
|
|
|
264
320
|
const metadata = {
|
|
265
321
|
output: [],
|
|
266
322
|
types: {}
|
|
267
323
|
};
|
|
268
324
|
|
|
269
|
-
|
|
325
|
+
processed_items.forEach((item, idx) => {
|
|
326
|
+
/*
|
|
327
|
+
Some of these fields may have been omitted from the object,
|
|
328
|
+
but we still need them for metadata purposes.
|
|
329
|
+
*/
|
|
330
|
+
const full_item = items[idx];
|
|
270
331
|
metadata.output.push({
|
|
271
|
-
post_id: +
|
|
272
|
-
post_type:
|
|
273
|
-
url:
|
|
274
|
-
uuid:
|
|
275
|
-
path: relative(outdir, outpath(
|
|
332
|
+
post_id: +full_item.post_id,
|
|
333
|
+
post_type: full_item.post_type,
|
|
334
|
+
url: full_item.attachment_url ?? full_item.link,
|
|
335
|
+
uuid: full_item.uuid,
|
|
336
|
+
path: relative(outdir, outpath(full_item))
|
|
276
337
|
});
|
|
277
|
-
metadata.types[
|
|
278
|
-
.
|
|
338
|
+
metadata.types[full_item.post_type] = [].concat(
|
|
339
|
+
metadata.types[full_item.post_type],
|
|
340
|
+
Object.keys(item)
|
|
341
|
+
);
|
|
279
342
|
});
|
|
280
343
|
|
|
281
|
-
const blueprints_path = join(outdir, 'site', 'blueprints');
|
|
282
|
-
await mkdir(join(blueprints_path, 'pages'), { recursive: true });
|
|
283
|
-
await mkdir(join(blueprints_path, 'files'), { recursive: true });
|
|
284
|
-
|
|
285
344
|
Object.keys(metadata.types).forEach(key => {
|
|
286
345
|
metadata.types[key] = Array.from(new Set(metadata.types[key])).sort();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
await mkdir(outdir, { recursive: true });
|
|
349
|
+
await writeFile(join(outdir, 'metadata.json'), JSON.stringify(metadata, null, '\t'));
|
|
350
|
+
|
|
351
|
+
if (!options['only-metadata']) {
|
|
352
|
+
|
|
353
|
+
for (let item of processed_items) {
|
|
354
|
+
const destination = outpath(item);
|
|
355
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
356
|
+
await writeFile(destination, serialize_item(item));
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const blueprints_path = join(outdir, 'site', 'blueprints');
|
|
360
|
+
await mkdir(join(blueprints_path, 'pages'), { recursive: true });
|
|
361
|
+
await mkdir(join(blueprints_path, 'files'), { recursive: true });
|
|
362
|
+
|
|
287
363
|
// Make blueprints
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
364
|
+
Object.keys(metadata.types).forEach(key => {
|
|
365
|
+
const blueprint_content = metadata.types[key].reduce((acc, curr) => {
|
|
366
|
+
acc[curr] = {
|
|
367
|
+
type: 'text'
|
|
368
|
+
};
|
|
369
|
+
return acc;
|
|
370
|
+
}, {});
|
|
371
|
+
|
|
372
|
+
if (key === 'attachment') {
|
|
373
|
+
const blueprint_dest = join(
|
|
374
|
+
blueprints_path,
|
|
375
|
+
'files',
|
|
376
|
+
key + '.yml'
|
|
377
|
+
);
|
|
294
378
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
'files',
|
|
299
|
-
key + '.yml'
|
|
300
|
-
);
|
|
379
|
+
writeFile(blueprint_dest, dump({
|
|
380
|
+
fields: blueprint_content
|
|
381
|
+
}));
|
|
301
382
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
383
|
+
} else {
|
|
384
|
+
const blueprint_dest = join(
|
|
385
|
+
blueprints_path,
|
|
386
|
+
'pages',
|
|
387
|
+
key + '.yml'
|
|
388
|
+
);
|
|
305
389
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
fields: {
|
|
316
|
-
label: 'Fields',
|
|
317
|
-
sections: {
|
|
318
|
-
fields: {
|
|
319
|
-
type: 'fields',
|
|
320
|
-
fields: blueprint_content
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
pages: {
|
|
325
|
-
label: 'Pages',
|
|
326
|
-
sections: {
|
|
327
|
-
pages: {
|
|
328
|
-
type: 'pages'
|
|
390
|
+
writeFile(blueprint_dest, dump({
|
|
391
|
+
tabs: {
|
|
392
|
+
fields: {
|
|
393
|
+
label: 'Fields',
|
|
394
|
+
sections: {
|
|
395
|
+
fields: {
|
|
396
|
+
type: 'fields',
|
|
397
|
+
fields: blueprint_content
|
|
398
|
+
}
|
|
329
399
|
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
400
|
+
},
|
|
401
|
+
pages: {
|
|
402
|
+
label: 'Pages',
|
|
403
|
+
sections: {
|
|
404
|
+
pages: {
|
|
405
|
+
type: 'pages'
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
files: {
|
|
410
|
+
label: 'Files',
|
|
411
|
+
sections: {
|
|
412
|
+
files: {
|
|
413
|
+
type: 'files'
|
|
414
|
+
}
|
|
337
415
|
}
|
|
338
416
|
}
|
|
339
417
|
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
});
|
|
345
421
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
422
|
+
const default_blueprint = {
|
|
423
|
+
tabs: {
|
|
424
|
+
pages: {
|
|
425
|
+
label: 'Pages',
|
|
426
|
+
sections: {
|
|
427
|
+
pages: {
|
|
428
|
+
type: 'pages'
|
|
429
|
+
}
|
|
353
430
|
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
431
|
+
},
|
|
432
|
+
files: {
|
|
433
|
+
label: 'Files',
|
|
434
|
+
sections: {
|
|
435
|
+
files: {
|
|
436
|
+
type: 'files'
|
|
437
|
+
}
|
|
361
438
|
}
|
|
362
439
|
}
|
|
363
440
|
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
await writeFile(join(outdir, 'metadata.json'), JSON.stringify(metadata, null, '\t'));
|
|
441
|
+
};
|
|
442
|
+
await writeFile(join(blueprints_path, 'pages', 'default.yml'), dump(default_blueprint));
|
|
443
|
+
await writeFile(join(blueprints_path, 'site.yml'), dump(default_blueprint));
|
|
444
|
+
}
|
|
370
445
|
}
|
|
371
446
|
|
|
372
447
|
if (command === 'download') {
|
|
@@ -379,7 +454,7 @@ if (command === 'download') {
|
|
|
379
454
|
|
|
380
455
|
const fetched = new Set();
|
|
381
456
|
|
|
382
|
-
for
|
|
457
|
+
for (let item of items.filter(it => it.post_type === 'attachment')) {
|
|
383
458
|
const attachment = process_item(item);
|
|
384
459
|
const dest = outpath(attachment).replace(/\.txt$/, '');
|
|
385
460
|
if (contentdir) {
|
|
@@ -388,6 +463,7 @@ if (command === 'download') {
|
|
|
388
463
|
.filter(p => p && p !== 'wp-content')
|
|
389
464
|
.join(sep);
|
|
390
465
|
if (typeof contentdir === 'string') {
|
|
466
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
391
467
|
await copyFile(join(contentdir, pathname), dest);
|
|
392
468
|
} else {
|
|
393
469
|
const url = new URL(pathname, contentdir);
|
|
@@ -435,9 +511,11 @@ Usage:
|
|
|
435
511
|
Commands available:
|
|
436
512
|
|
|
437
513
|
generate
|
|
514
|
+
|
|
438
515
|
Generate a Kirby CMS file structure from the provided XML file.
|
|
439
516
|
|
|
440
517
|
download
|
|
518
|
+
|
|
441
519
|
Download attachments.
|
|
442
520
|
|
|
443
521
|
Options available:
|
|
@@ -450,14 +528,14 @@ Options available:
|
|
|
450
528
|
|
|
451
529
|
Shows the program version.
|
|
452
530
|
|
|
453
|
-
-o
|
|
531
|
+
-o <path>, --outdir=<path>
|
|
454
532
|
|
|
455
533
|
Root directory to which to write the output,
|
|
456
534
|
relative to the current working directory.
|
|
457
535
|
|
|
458
536
|
Default: 'wordpress-to-kirby'
|
|
459
537
|
|
|
460
|
-
--contentdir
|
|
538
|
+
--contentdir=<path>
|
|
461
539
|
|
|
462
540
|
For the 'download' command, point to the location
|
|
463
541
|
of a 'wp-content' directory from which to download attachments.
|
|
@@ -471,7 +549,9 @@ Options available:
|
|
|
471
549
|
--parse=<rules>
|
|
472
550
|
|
|
473
551
|
Instructions to parse some fields, specified as:
|
|
474
|
-
"<key>=<parser>,<key>=<parser>,…"
|
|
552
|
+
"<key>=<parser>,<key>=<parser>,…".
|
|
553
|
+
|
|
554
|
+
The option can be used multiple times.
|
|
475
555
|
|
|
476
556
|
Supported parsers:
|
|
477
557
|
* php: deserialize PHP object.
|
|
@@ -484,6 +564,8 @@ Options available:
|
|
|
484
564
|
Instructions to serialize some fields, specified as:
|
|
485
565
|
"<key>=<serializer>,<key>=<serializer>,…"
|
|
486
566
|
|
|
567
|
+
The option can be used multiple times.
|
|
568
|
+
|
|
487
569
|
Supported serializers:
|
|
488
570
|
* php: serialize as PHP object.
|
|
489
571
|
* yaml: serialize as YAML.
|
|
@@ -493,12 +575,12 @@ Options available:
|
|
|
493
575
|
--exclude-fields=<fields>
|
|
494
576
|
|
|
495
577
|
Exclude certain fields from the output, specified as a
|
|
496
|
-
comma-separated list of fields.
|
|
578
|
+
comma-separated list of fields. Can be used multiple times.
|
|
497
579
|
|
|
498
580
|
--include-fields=<fields>
|
|
499
581
|
|
|
500
582
|
Only include certain fields from the output, specified as a
|
|
501
|
-
comma-separated list of fields.
|
|
583
|
+
comma-separated list of fields. Can be used multiple times.
|
|
502
584
|
|
|
503
585
|
When '--include-fields' is specified, the '--exclude-fields'
|
|
504
586
|
option is ignored.
|
|
@@ -506,15 +588,20 @@ Options available:
|
|
|
506
588
|
--exclude-types=<types>
|
|
507
589
|
|
|
508
590
|
Exclude certain post types from the output, specified as a
|
|
509
|
-
comma-separated list of post types.
|
|
591
|
+
comma-separated list of post types. Can be used multiple times.
|
|
510
592
|
|
|
511
593
|
--include-types=<types>
|
|
594
|
+
|
|
512
595
|
Only include certain post types from the output, specified as a
|
|
513
|
-
comma-separated list of post types.
|
|
596
|
+
comma-separated list of post types. Can be used multiple times.
|
|
514
597
|
|
|
515
598
|
When '--include-types' is specified, the '--exclude-types'
|
|
516
599
|
option is ignored.
|
|
517
600
|
|
|
601
|
+
--only-metadata
|
|
602
|
+
|
|
603
|
+
For the 'generate' command, only generate the 'metadata.json' file.
|
|
604
|
+
|
|
518
605
|
Keys extracted from the XML:
|
|
519
606
|
|
|
520
607
|
Top-level:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wordpress-to-kirby",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A CLI to convert WordPress XML to Kirby CMS files",
|
|
5
5
|
"homepage": "https://github.com/tocmai/wordpress-to-kirby#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"js-yaml": "^5.5.0",
|
|
23
23
|
"jsdom": "^31.0.1",
|
|
24
|
-
"opsh": "^1.1.0",
|
|
25
24
|
"php-serialize": "^5.1.3"
|
|
26
25
|
}
|
|
27
26
|
}
|