Skip to content

Commit

Permalink
Add option to list empty authors
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulAdamDavis committed Dec 10, 2024
1 parent 87793b5 commit fc62d75
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
9 changes: 9 additions & 0 deletions commands/content-stats.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.boolean('--listEmptyAuthors', {
defaultValue: false,
desc: 'List the empty authors'
});
};

// What to do when this command is executed
Expand All @@ -42,6 +46,11 @@ const run = async (argv) => {
ui.log(context.tables.stats);
ui.log(context.tables.users);

if (argv.listEmptyAuthors) {
ui.log('\n\nAuthors with no posts:');
ui.log(context.tables.emptyAuthors);
}

// Report success
ui.log.ok(`Successfully showed stats in ${Date.now() - timer}ms.`);
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"inquirer": "9.3.7",
"inquirer-datepicker-prompt": "0.4.3",
"inquirer-search-checkbox": "1.0.0",
"inquirer-search-list": "1.2.6",
"jsonwebtoken": "9.0.2",
"listr": "0.14.3",
"lodash": "4.17.21",
Expand Down
38 changes: 35 additions & 3 deletions tasks/content-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ const initialise = (options) => {
},
members: {
count: null
}
},
emptyAuthors: []
};

ctx.tables = {
stats: null,
users: null
users: null,
emptyAuthors: null
};

task.output = `Initialised API connection for ${options.apiURL}`;
Expand Down Expand Up @@ -142,7 +144,7 @@ const getFullTaskList = (options) => {
{
title: 'Counting staff',
task: async (ctx) => {
const usersData = await ctx.api.users.browse({limit: 'all', include: 'roles'});
const usersData = await ctx.api.users.browse({limit: 'all', include: 'roles,count.posts'});

const staffOwner = usersData.filter(word => word.roles[0].name === 'Owner');
const staffAdministrator = usersData.filter(word => word.roles[0].name === 'Administrator');
Expand All @@ -158,6 +160,17 @@ const getFullTaskList = (options) => {
author: {count: staffAuthor.length},
contributor: {count: staffContributor.length}
};

if (options?.listEmptyAuthors) {
usersData.forEach((user) => {
if (user.count.posts === 0) {
ctx.stats.emptyAuthors.push([
user.name,
`${options.apiURL}/ghost/#/settings/staff/${user.slug}`
]);
}
});
}
}
},
{
Expand Down Expand Up @@ -230,6 +243,25 @@ const getFullTaskList = (options) => {
];

ctx.tables.users = Table(usersHeader, usersRows, {compact: true}).render();

if (options?.listEmptyAuthors && ctx.stats.emptyAuthors.length > 0) {
const authorsHeader = [{
value: 'Name',
headerColor: 'cyan',
color: 'white',
headerAlign: 'left',
align: 'left'
},
{
value: 'URL',
headerColor: 'cyan',
color: 'white',
headerAlign: 'left',
align: 'left'
}];

ctx.tables.emptyAuthors = Table(authorsHeader, ctx.stats.emptyAuthors, {compact: true}).render();
}
}
}
];
Expand Down
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3877,7 +3877,6 @@ eslint-plugin-es-x@^7.1.0:

eslint-plugin-filenames@allouis/eslint-plugin-filenames#15dc354f4e3d155fc2d6ae082dbfc26377539a18:
version "1.3.2"
uid "15dc354f4e3d155fc2d6ae082dbfc26377539a18"
resolved "https://codeload.github.com/allouis/eslint-plugin-filenames/tar.gz/15dc354f4e3d155fc2d6ae082dbfc26377539a18"
dependencies:
lodash.camelcase "4.3.0"
Expand Down Expand Up @@ -4925,6 +4924,16 @@ [email protected]:
fuzzy "^0.1.3"
inquirer "^3.3.0"

[email protected]:
version "1.2.6"
resolved "https://registry.yarnpkg.com/inquirer-search-list/-/inquirer-search-list-1.2.6.tgz#ecb5672be4915883fa812b950ff37c7c83a8af42"
integrity sha512-C4pKSW7FOYnkAloH8rB4FiM91H1v08QFZZJh6KRt//bMfdDBIhgdX8wjHvrVH2bu5oIo6wYqGpzSBxkeClPxew==
dependencies:
chalk "^2.3.0"
figures "^2.0.0"
fuzzy "^0.1.3"
inquirer "^3.3.0"

[email protected]:
version "9.3.7"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.3.7.tgz#0b562bf843812208844741c9aec9244c939b83d4"
Expand Down

0 comments on commit fc62d75

Please sign in to comment.