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