Skip to content

Commit fc62d75

Browse files
committed
Add option to list empty authors
1 parent 87793b5 commit fc62d75

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

commands/content-stats.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const setup = (sywac) => {
2424
defaultValue: false,
2525
desc: 'Show verbose output'
2626
});
27+
sywac.boolean('--listEmptyAuthors', {
28+
defaultValue: false,
29+
desc: 'List the empty authors'
30+
});
2731
};
2832

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

49+
if (argv.listEmptyAuthors) {
50+
ui.log('\n\nAuthors with no posts:');
51+
ui.log(context.tables.emptyAuthors);
52+
}
53+
4554
// Report success
4655
ui.log.ok(`Successfully showed stats in ${Date.now() - timer}ms.`);
4756
} catch (error) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"inquirer": "9.3.7",
4646
"inquirer-datepicker-prompt": "0.4.3",
4747
"inquirer-search-checkbox": "1.0.0",
48+
"inquirer-search-list": "1.2.6",
4849
"jsonwebtoken": "9.0.2",
4950
"listr": "0.14.3",
5051
"lodash": "4.17.21",

tasks/content-stats.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ const initialise = (options) => {
5353
},
5454
members: {
5555
count: null
56-
}
56+
},
57+
emptyAuthors: []
5758
};
5859

5960
ctx.tables = {
6061
stats: null,
61-
users: null
62+
users: null,
63+
emptyAuthors: null
6264
};
6365

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

147149
const staffOwner = usersData.filter(word => word.roles[0].name === 'Owner');
148150
const staffAdministrator = usersData.filter(word => word.roles[0].name === 'Administrator');
@@ -158,6 +160,17 @@ const getFullTaskList = (options) => {
158160
author: {count: staffAuthor.length},
159161
contributor: {count: staffContributor.length}
160162
};
163+
164+
if (options?.listEmptyAuthors) {
165+
usersData.forEach((user) => {
166+
if (user.count.posts === 0) {
167+
ctx.stats.emptyAuthors.push([
168+
user.name,
169+
`${options.apiURL}/ghost/#/settings/staff/${user.slug}`
170+
]);
171+
}
172+
});
173+
}
161174
}
162175
},
163176
{
@@ -230,6 +243,25 @@ const getFullTaskList = (options) => {
230243
];
231244

232245
ctx.tables.users = Table(usersHeader, usersRows, {compact: true}).render();
246+
247+
if (options?.listEmptyAuthors && ctx.stats.emptyAuthors.length > 0) {
248+
const authorsHeader = [{
249+
value: 'Name',
250+
headerColor: 'cyan',
251+
color: 'white',
252+
headerAlign: 'left',
253+
align: 'left'
254+
},
255+
{
256+
value: 'URL',
257+
headerColor: 'cyan',
258+
color: 'white',
259+
headerAlign: 'left',
260+
align: 'left'
261+
}];
262+
263+
ctx.tables.emptyAuthors = Table(authorsHeader, ctx.stats.emptyAuthors, {compact: true}).render();
264+
}
233265
}
234266
}
235267
];

yarn.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3877,7 +3877,6 @@ eslint-plugin-es-x@^7.1.0:
38773877

38783878
eslint-plugin-filenames@allouis/eslint-plugin-filenames#15dc354f4e3d155fc2d6ae082dbfc26377539a18:
38793879
version "1.3.2"
3880-
uid "15dc354f4e3d155fc2d6ae082dbfc26377539a18"
38813880
resolved "https://codeload.github.com/allouis/eslint-plugin-filenames/tar.gz/15dc354f4e3d155fc2d6ae082dbfc26377539a18"
38823881
dependencies:
38833882
lodash.camelcase "4.3.0"
@@ -4925,6 +4924,16 @@ [email protected]:
49254924
fuzzy "^0.1.3"
49264925
inquirer "^3.3.0"
49274926

4927+
4928+
version "1.2.6"
4929+
resolved "https://registry.yarnpkg.com/inquirer-search-list/-/inquirer-search-list-1.2.6.tgz#ecb5672be4915883fa812b950ff37c7c83a8af42"
4930+
integrity sha512-C4pKSW7FOYnkAloH8rB4FiM91H1v08QFZZJh6KRt//bMfdDBIhgdX8wjHvrVH2bu5oIo6wYqGpzSBxkeClPxew==
4931+
dependencies:
4932+
chalk "^2.3.0"
4933+
figures "^2.0.0"
4934+
fuzzy "^0.1.3"
4935+
inquirer "^3.3.0"
4936+
49284937
49294938
version "9.3.7"
49304939
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.3.7.tgz#0b562bf843812208844741c9aec9244c939b83d4"

0 commit comments

Comments
 (0)