Skip to content

Commit

Permalink
Add author filter to add-author
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulAdamDavis committed Jan 20, 2025
1 parent c85ebb4 commit 9e8ebd5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ gctools add-author --help

# Add author with the slug 'michael' to the posts with the tag 'news`
gctools add-author <apiURL> <adminAPIKey> --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 <apiURL> <adminAPIKey> --author 'richard' --tag 'news' --new_author 'michael'
```


Expand Down
4 changes: 4 additions & 0 deletions commands/add-author.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\''
Expand Down
9 changes: 9 additions & 0 deletions prompts/add-author.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions tasks/add-author.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}]`);
}
Expand Down

0 comments on commit 9e8ebd5

Please sign in to comment.