From fc62d7598b7da32a2fa0e00bc0edf0d4a35a15bd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 10 Dec 2024 12:25:13 +0000 Subject: [PATCH] Add option to list empty authors --- commands/content-stats.js | 9 +++++++++ package.json | 1 + tasks/content-stats.js | 38 +++++++++++++++++++++++++++++++++++--- yarn.lock | 11 ++++++++++- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/commands/content-stats.js b/commands/content-stats.js index bba6d1c9..367ebcb6 100644 --- a/commands/content-stats.js +++ b/commands/content-stats.js @@ -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 @@ -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) { diff --git a/package.json b/package.json index d7fa5398..d98a665d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tasks/content-stats.js b/tasks/content-stats.js index 902e98a5..56ad284a 100644 --- a/tasks/content-stats.js +++ b/tasks/content-stats.js @@ -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}`; @@ -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'); @@ -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}` + ]); + } + }); + } } }, { @@ -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(); + } } } ]; diff --git a/yarn.lock b/yarn.lock index 196dda1d..7b3a69a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -4925,6 +4924,16 @@ inquirer-search-checkbox@1.0.0: fuzzy "^0.1.3" inquirer "^3.3.0" +inquirer-search-list@1.2.6: + 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" + inquirer@9.3.7: version "9.3.7" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.3.7.tgz#0b562bf843812208844741c9aec9244c939b83d4"