mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Fix undefined answer bug, start on example path
This commit is contained in:
+7
-14
@@ -22,13 +22,11 @@ export const all = [
|
||||
choices: [
|
||||
{
|
||||
name: 'Yes',
|
||||
value: true,
|
||||
description: '/my-post/index.md'
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: 'No',
|
||||
value: false,
|
||||
description: '/my-post.md'
|
||||
value: false
|
||||
}
|
||||
],
|
||||
prompt: inquirer.select
|
||||
@@ -41,13 +39,11 @@ export const all = [
|
||||
choices: [
|
||||
{
|
||||
name: 'Yes',
|
||||
value: true,
|
||||
description: ''
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: 'No',
|
||||
value: false,
|
||||
description: ''
|
||||
value: false
|
||||
}
|
||||
],
|
||||
prompt: inquirer.select
|
||||
@@ -60,18 +56,15 @@ export const all = [
|
||||
choices: [
|
||||
{
|
||||
name: 'Year folders',
|
||||
value: 'year',
|
||||
description: ''
|
||||
value: 'year'
|
||||
},
|
||||
{
|
||||
name: 'Year and month folders',
|
||||
value: 'year-month',
|
||||
description: ''
|
||||
value: 'year-month'
|
||||
},
|
||||
{
|
||||
name: 'No',
|
||||
value: 'none',
|
||||
description: ''
|
||||
value: 'none'
|
||||
}
|
||||
],
|
||||
prompt: inquirer.select
|
||||
|
||||
+27
-4
@@ -84,7 +84,6 @@ function getCommandLineAnswers(questions) {
|
||||
export async function getWizardAnswers(questions) {
|
||||
const answers = {};
|
||||
for (const question of questions) {
|
||||
// this will be set to the normalized answer during validation
|
||||
let normalizedAnswer;
|
||||
|
||||
const promptConfig = {
|
||||
@@ -106,8 +105,7 @@ export async function getWizardAnswers(questions) {
|
||||
}
|
||||
}
|
||||
|
||||
// don't care about the return value of prompt() because normalizedAnswer will be used
|
||||
await question.prompt(promptConfig).catch((ex) => {
|
||||
const answer = await question.prompt(promptConfig).catch((ex) => {
|
||||
// exit gracefully if user hits ctrl + c during wizard
|
||||
if (ex instanceof Error && ex.name === 'ExitPromptError') {
|
||||
console.log('\nUser quit wizard early.');
|
||||
@@ -117,7 +115,7 @@ export async function getWizardAnswers(questions) {
|
||||
}
|
||||
});
|
||||
|
||||
answers[camelcase(question.name)] = normalizedAnswer;
|
||||
answers[camelcase(question.name)] = normalizedAnswer ?? answer;
|
||||
}
|
||||
|
||||
return answers;
|
||||
@@ -135,3 +133,28 @@ function normalize(value, type, onError) {
|
||||
onError(ex.message);
|
||||
}
|
||||
}
|
||||
|
||||
function buildSamplePath(config) {
|
||||
const pathSegments = [];
|
||||
|
||||
if (config.dateFolders === 'year' || config.dateFolders === 'year-month') {
|
||||
pathSegments.push('2025');
|
||||
}
|
||||
|
||||
if (config.dateFolders === 'year-month') {
|
||||
pathSegments.push('01');
|
||||
}
|
||||
|
||||
let slugFragment = 'my-post';
|
||||
if (config.prefixDate) {
|
||||
slugFragment = '2025-01-31-' + slugFragment;
|
||||
}
|
||||
|
||||
if (config.postFolders) {
|
||||
pathSegments.push(slugFragment, 'index.md');
|
||||
} else {
|
||||
pathSegments.push(slugFragment + '.md');
|
||||
}
|
||||
|
||||
return '/' + pathSegments.join('/');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user