mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Logging refactor, quote-date, type count fix
This commit is contained in:
+2
-5
@@ -62,16 +62,13 @@ function collectPosts(channelData, postTypes, config) {
|
||||
.filter(postData => !(postType === 'page' && postData.post_name[0] === 'sample-page'))
|
||||
.map(postData => buildPost(postData, turndownService, config));
|
||||
|
||||
if (postTypes.length > 1) {
|
||||
console.log(`${postsForType.length} "${postType}" posts found.`);
|
||||
if (postsForType.length > 0) {
|
||||
console.log(`${postsForType.length} posts of type "${postType}" found.`);
|
||||
}
|
||||
|
||||
allPosts.push(...postsForType);
|
||||
});
|
||||
|
||||
if (postTypes.length === 1) {
|
||||
console.log(allPosts.length + ' posts found.');
|
||||
}
|
||||
return allPosts;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,11 @@ export const all = [
|
||||
type: 'string',
|
||||
default: 'utc'
|
||||
},
|
||||
{
|
||||
name: 'quote-date',
|
||||
type: 'boolean',
|
||||
default: false
|
||||
},
|
||||
{
|
||||
name: 'strict-ssl',
|
||||
type: 'boolean',
|
||||
|
||||
+22
-3
@@ -18,10 +18,10 @@ async function processPayloadsPromise(payloads, loadFunc, config) {
|
||||
try {
|
||||
const data = await loadFunc(payload.item, config);
|
||||
await writeFile(payload.destinationPath, data);
|
||||
console.log(chalk.green('[OK]') + ' ' + payload.name);
|
||||
logPayloadResult(payload);
|
||||
resolve();
|
||||
} catch (ex) {
|
||||
console.log(chalk.red('[FAILED]') + ' ' + payload.name + ' ' + chalk.red('(' + ex.message + ')'));
|
||||
logPayloadResult(payload, ex.message);
|
||||
reject();
|
||||
}
|
||||
}, payload.delay);
|
||||
@@ -54,7 +54,8 @@ async function writeMarkdownFilesPromise(posts, config) {
|
||||
} else {
|
||||
const payload = {
|
||||
item: post,
|
||||
name: post.type + ' - ' + post.slug,
|
||||
type: post.type,
|
||||
name: post.slug,
|
||||
destinationPath,
|
||||
delay
|
||||
};
|
||||
@@ -88,6 +89,10 @@ async function loadMarkdownFilePromise(post, config) {
|
||||
} else {
|
||||
outputValue = config.includeTimeWithDate ? value.toISO() : value.toISODate();
|
||||
}
|
||||
|
||||
if (config.quoteDate) {
|
||||
outputValue = `"${outputValue}"`;
|
||||
}
|
||||
} else {
|
||||
// single string value
|
||||
const escapedValue = (value || '').replace(/"/g, '\\"');
|
||||
@@ -122,6 +127,7 @@ async function writeImageFilesPromise(posts, config) {
|
||||
} else {
|
||||
const payload = {
|
||||
item: imageUrl,
|
||||
type: 'image',
|
||||
name: filename,
|
||||
destinationPath,
|
||||
delay
|
||||
@@ -183,3 +189,16 @@ function buildPostPath(post, config) {
|
||||
function checkFile(path) {
|
||||
return fs.existsSync(path);
|
||||
}
|
||||
|
||||
function logPayloadResult(payload, errorMessage) {
|
||||
const messageBits = [
|
||||
errorMessage ? chalk.red('✗') : chalk.green('✓'),
|
||||
chalk.gray(`[${payload.type}]`),
|
||||
payload.name
|
||||
];
|
||||
if (errorMessage) {
|
||||
messageBits.push(chalk.red(`(${errorMessage})`));
|
||||
}
|
||||
|
||||
console.log(messageBits.join(' '));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user