mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-17 13:43:44 +09:00
Logging refactor, quote-date, type count fix
This commit is contained in:
+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