tags.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 import { DOMAIN, SITE, gqlRequest } from './_helpers.js'; 3 cli({ 4 site: SITE, 5 name: 'tags', 6 description: 'List popular tags', 7 domain: DOMAIN, 8 strategy: Strategy.PUBLIC, 9 browser: false, 10 args: [{ name: 'limit', type: 'int', default: 20, help: 'Number of results' }], 11 columns: ['rank', 'name', 'posts'], 12 func: async (_page, kwargs) => { 13 const limit = Number(kwargs.limit ?? 20); 14 const query = `query Tags { 15 tags(input: {terms: {view: "coreTags", limit: ${limit}}}) { 16 results { _id name slug postCount } 17 } 18 }`; 19 const data = await gqlRequest(query); 20 const tags = (data?.tags?.results ?? []); 21 return tags.map((item, i) => ({ 22 rank: i + 1, 23 name: item.name ?? '', 24 posts: item.postCount ?? 0, 25 })); 26 }, 27 });