@@ -3,10 +3,11 @@ const path = require('path')
33const cheerio = require ( 'cheerio' )
44const LDP = require ( '../../lib/ldp' )
55const { URL } = require ( 'url' )
6+ const debug = require ( '../../lib/debug' )
67
78const { compileTemplate, writeTemplate } = require ( '../../lib/common/template-utils' )
89const { getAccountManager, loadConfig, loadUsernames } = require ( './cli-utils' )
9- const { getWebId } = require ( '../../lib/common/user-utils' )
10+ const { getName , getWebId } = require ( '../../lib/common/user-utils' )
1011const { initConfigDir, initTemplateDirs } = require ( '../../lib/server-config' )
1112
1213module . exports = function ( program ) {
@@ -22,18 +23,23 @@ module.exports = function (program) {
2223 const ldp = new LDP ( config )
2324 const accountManager = getAccountManager ( config , { ldp } )
2425 const usernames = loadUsernames ( config )
25- const usersProcessed = usernames . map ( async name => {
26- const accountDirectory = accountManager . accountDirFor ( name )
26+ const usersProcessed = usernames . map ( async username => {
27+ const accountDirectory = accountManager . accountDirFor ( username )
2728 const indexFilePath = path . join ( accountDirectory , 'index.html' )
2829 if ( ! isUpdateAllowed ( indexFilePath ) ) {
2930 return
3031 }
31- const accountUrl = getAccountUrl ( name , config )
32- const webId = await getWebId ( accountDirectory , accountUrl , { ldp } )
33- writeTemplate ( indexFilePath , indexTemplate , { name, webId } )
32+ const accountUrl = getAccountUrl ( username , config )
33+ try {
34+ const webId = await getWebId ( accountDirectory , accountUrl , { ldp } )
35+ const name = await getName ( webId , { ldp } )
36+ writeTemplate ( indexFilePath , indexTemplate , { name, webId } )
37+ } catch ( err ) {
38+ debug . errors ( `Failed to create new index for ${ username } : ${ JSON . stringify ( err , null , 2 ) } ` )
39+ }
3440 } )
3541 await Promise . all ( usersProcessed )
36- console . log ( `Processed ${ usersProcessed . length } users` )
42+ debug . accounts ( `Processed ${ usersProcessed . length } users` )
3743 } )
3844}
3945
0 commit comments