1- const { JSDOM } = require ( 'jsdom' )
1+ const striptags = require ( 'striptags' ) ;
2+
3+ const output = [ ]
24
35module . exports . register = function ( ) {
4- this . once ( 'sitePublished ' , ( { playbook, contentCatalog } ) => {
6+ this . once ( 'documentsConverted ' , ( { playbook, contentCatalog } ) => {
57
68 console . time ( 'get-component-stats' )
79
810 contentCatalog . getComponents ( ) . forEach ( ( component ) => {
911 component . versions . forEach ( ( componentVersion , index ) => {
1012 const pages = contentCatalog . getPages ( it => it . src . component === componentVersion . name && it . src . version === componentVersion . version )
1113
12- const wc = pages . map ( page => {
13- const dom = new JSDOM ( page . contents . toString ( ) )
14- const node = dom . window . document . querySelector ( 'article' )
15- if ( node ) {
16- return wordcount ( node . textContent )
17- }
18- else { return 0 }
19- } )
20- console . log ( {
14+ const wc = pages . map ( page => wordcount ( striptags ( page . contents . toString ( ) ) ) )
15+ // const wc = pages.map(page => {
16+ // const dom = new JSDOM(page.contents.toString())
17+ // const node = dom.window.document.querySelector('article')
18+ // if (node) {
19+ // return wordcount(node.textContent)
20+ // }
21+ // else { return 0 }
22+ // })
23+
24+ output . push ( {
2125 component : componentVersion . name ,
2226 version : componentVersion . version ,
2327 pages : pages . length ,
@@ -27,6 +31,14 @@ module.exports.register = function () {
2731 } )
2832
2933 console . timeEnd ( 'get-component-stats' )
34+
35+ } )
36+
37+ this . once ( 'sitePublished' , ( { } ) => {
38+ console . log ( output )
39+
40+ const total_words = sum ( output . map ( c => c . words ) )
41+ console . log ( `Total words: ${ total_words } ` )
3042 } )
3143}
3244
0 commit comments