mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Updated headings and count logging
This commit is contained in:
+2
-2
@@ -24,7 +24,7 @@ export async function getConfig() {
|
||||
|
||||
let wizardAnswers;
|
||||
if (commandLineAnswers.wizard) {
|
||||
console.log('\nStarting wizard...');
|
||||
shared.logHeading('Starting wizard');
|
||||
|
||||
// run wizard for questions with prompts that were not answered via the command line
|
||||
const wizardQuestions = questions.load().filter((question) => {
|
||||
@@ -32,7 +32,7 @@ export async function getConfig() {
|
||||
});
|
||||
wizardAnswers = await getWizardAnswers(wizardQuestions, commandLineAnswers);
|
||||
} else {
|
||||
console.log('\nSkipping wizard...');
|
||||
shared.logHeading('Skipping wizard');
|
||||
}
|
||||
|
||||
Object.assign(shared.config, commandLineAnswers, wizardAnswers);
|
||||
|
||||
+2
-2
@@ -1,3 +1,4 @@
|
||||
import chalk from 'chalk';
|
||||
import fs from 'fs';
|
||||
import * as luxon from 'luxon';
|
||||
import * as data from './data.js';
|
||||
@@ -6,7 +7,7 @@ import * as shared from './shared.js';
|
||||
import * as translator from './translator.js';
|
||||
|
||||
export async function parseFilePromise() {
|
||||
console.log('\nParsing...');
|
||||
shared.logHeading('Parsing');
|
||||
const content = await fs.promises.readFile(shared.config.input, 'utf8');
|
||||
const rssData = await data.load(content);
|
||||
const allPostData = rssData.child('channel').children('item');
|
||||
@@ -197,4 +198,3 @@ function populateFrontmatter(posts) {
|
||||
function isAbsoluteUrl(url) {
|
||||
return (/^https?:\/\//i).test(url);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
|
||||
// simple data store, populated via intake, used everywhere
|
||||
@@ -11,6 +12,10 @@ export function getSlugWithFallback(post) {
|
||||
return post.slug ? post.slug : 'id-' + post.id;
|
||||
}
|
||||
|
||||
export function logHeading(text) {
|
||||
console.log(`\n${chalk.cyan(text + '...')}`);
|
||||
}
|
||||
|
||||
export function buildPostPath(post, overrideConfig) {
|
||||
const pathConfig = overrideConfig ?? config;
|
||||
|
||||
|
||||
+21
-14
@@ -43,13 +43,13 @@ async function writeFile(destinationPath, data) {
|
||||
|
||||
async function writeMarkdownFilesPromise(posts) {
|
||||
// package up posts into payloads
|
||||
let skipCount = 0;
|
||||
let existingCount = 0;
|
||||
let delay = 0;
|
||||
const payloads = posts.flatMap(post => {
|
||||
const destinationPath = shared.buildPostPath(post);
|
||||
if (checkFile(destinationPath)) {
|
||||
// already exists, don't need to save again
|
||||
skipCount++;
|
||||
existingCount++;
|
||||
return [];
|
||||
} else {
|
||||
const payload = {
|
||||
@@ -64,11 +64,8 @@ async function writeMarkdownFilesPromise(posts) {
|
||||
}
|
||||
});
|
||||
|
||||
const remainingCount = payloads.length;
|
||||
if (remainingCount + skipCount === 0) {
|
||||
console.log('\nNo posts to save...');
|
||||
} else {
|
||||
console.log(`\nSaving ${remainingCount} posts (${skipCount} already exist)...`);
|
||||
logSavingMessage('posts', existingCount, payloads.length);
|
||||
if (payloads.length > 0) {
|
||||
await processPayloadsPromise(payloads, loadMarkdownFilePromise);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +115,7 @@ async function loadMarkdownFilePromise(post) {
|
||||
|
||||
async function writeImageFilesPromise(posts) {
|
||||
// collect image data from all posts into a single flattened array of payloads
|
||||
let skipCount = 0;
|
||||
let existingCount = 0;
|
||||
let delay = 0;
|
||||
const payloads = posts.flatMap(post => {
|
||||
const postPath = shared.buildPostPath(post);
|
||||
@@ -128,7 +125,7 @@ async function writeImageFilesPromise(posts) {
|
||||
const destinationPath = path.join(imagesDir, filename);
|
||||
if (checkFile(destinationPath)) {
|
||||
// already exists, don't need to save again
|
||||
skipCount++;
|
||||
existingCount++;
|
||||
return [];
|
||||
} else {
|
||||
const payload = {
|
||||
@@ -144,11 +141,8 @@ async function writeImageFilesPromise(posts) {
|
||||
});
|
||||
});
|
||||
|
||||
const remainingCount = payloads.length;
|
||||
if (remainingCount + skipCount === 0) {
|
||||
console.log('\nNo images to download and save...');
|
||||
} else {
|
||||
console.log(`\nDownloading and saving ${remainingCount} images (${skipCount} already exist)...`);
|
||||
logSavingMessage('images', existingCount, payloads.length);
|
||||
if (payloads.length > 0) {
|
||||
await processPayloadsPromise(payloads, loadImageFilePromise);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +176,19 @@ function checkFile(path) {
|
||||
return fs.existsSync(path);
|
||||
}
|
||||
|
||||
function logSavingMessage(things, existingCount, remainingCount) {
|
||||
shared.logHeading(`Saving ${things}`);
|
||||
if (existingCount + remainingCount === 0) {
|
||||
console.log(`No ${things} to save.`);
|
||||
} else if (existingCount === 0) {
|
||||
console.log(`${remainingCount} ${things} to save.`);
|
||||
} else if (remainingCount === 0) {
|
||||
console.log(`All ${existingCount} ${things} already saved.`);
|
||||
} else {
|
||||
console.log(`${existingCount} ${things} already saved, ${remainingCount} remaining.`);
|
||||
}
|
||||
}
|
||||
|
||||
function logPayloadResult(payload, errorMessage) {
|
||||
const messageBits = [
|
||||
errorMessage ? chalk.red('✗') : chalk.green('✓'),
|
||||
|
||||
Reference in New Issue
Block a user