From 9e8ebd5203b41ae93dfdb4c84bed7b1e205dc283 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 20 Jan 2025 19:58:26 +0000 Subject: [PATCH] Add author filter to add-author --- README.md | 3 +++ commands/add-author.js | 4 ++++ prompts/add-author.js | 9 +++++++++ tasks/add-author.js | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/README.md b/README.md index a4f0608..d288d2a 100644 --- a/README.md +++ b/README.md @@ -359,6 +359,9 @@ gctools add-author --help # Add author with the slug 'michael' to the posts with the tag 'news` gctools add-author --tag 'news' --new_author 'michael' + +# For posts that have 'richard' as an author and with the tag 'news', add 'michael' as an author +gctools add-author --author 'richard' --tag 'news' --new_author 'michael' ``` diff --git a/commands/add-author.js b/commands/add-author.js index 6e987ae..ea71e0b 100644 --- a/commands/add-author.js +++ b/commands/add-author.js @@ -24,6 +24,10 @@ const setup = (sywac) => { defaultValue: false, desc: 'Show verbose output' }); + sywac.string('--author', { + defaultValue: null, + desc: 'Current author slug' + }); sywac.string('--tag', { defaultValue: null, desc: 'Select posts with these tag slugs, inside single quotes. i.e. \'existing-tag, newsletter\'' diff --git a/prompts/add-author.js b/prompts/add-author.js index e3a5a72..37a7bf0 100644 --- a/prompts/add-author.js +++ b/prompts/add-author.js @@ -14,6 +14,15 @@ const choice = { const options = [ ...ghostAPICreds, + { + type: 'list', + name: 'author', + message: 'Current Author:', + pageSize: 20, + choices: function () { + return getAPIAuthorsObj(); + } + }, { type: 'search-checkbox', name: 'tag', diff --git a/tasks/add-author.js b/tasks/add-author.js index d7487b3..183fbac 100644 --- a/tasks/add-author.js +++ b/tasks/add-author.js @@ -54,6 +54,10 @@ const getFullTaskList = (options) => { try { let discoveryFilter = []; + if (ctx.args.author) { + discoveryFilter.push(`author:[${ctx.args.author.slug}]`); + } + if (ctx.args.tag && ctx.args.tag.length > 0) { discoveryFilter.push(`tags:[${transformToCommaString(ctx.args.tag, 'slug')}]`); }