@@ -6,6 +6,15 @@ import { hal } from './hal.js';
66// Get configuration, including URL parameters
77const config = newConfig ( ) ;
88
9+ const delay = ( ms ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
10+
11+ function abortSignal ( ms = 10000 ) { // 10s max per fetch request
12+ const controller = new AbortController ( ) ;
13+ const signal = controller . signal ;
14+ setTimeout ( ( ) => controller . abort ( ) , ms ) ;
15+ return signal ;
16+ }
17+
918// Define sources for fetching data
1019// Except for group, W3C API calls uses hal.js instead of direct fetch
1120function sources ( type ) {
@@ -60,19 +69,19 @@ window.addEventListener('load', init);
6069function loadSources ( ) {
6170 return Promise . all ( [
6271 fetchGroupData ( ) ,
63- html ( sources ( 'template' ) ) ,
64- html ( sources ( 'deliverables' ) , { credentials : 'include' } ) . then ( doc => {
72+ html ( sources ( 'template' ) , { signal : abortSignal ( ) } ) ,
73+ html ( sources ( 'deliverables' ) , { credentials : 'include' , signal : abortSignal ( ) } ) . then ( doc => {
6574 return doc . getElementById ( 'deliverables' ) . parentNode . querySelectorAll ( 'dl' ) ;
6675 } ) ,
67- html ( sources ( 'charter' ) , { credentials : 'include' } ) ,
76+ html ( sources ( 'charter' ) , { credentials : 'include' , signal : abortSignal ( ) } ) ,
6877 ] ) ;
6978}
7079
7180function generate ( ) {
72- loadSources ( ) . then ( ( [ group , template , deliverables , charter ] ) => {
73- return compute ( group , template , deliverables , charter ) ;
74- } ) . then ( ( draft ) => {
75- draft . querySelectorAll ( '.remove' ) . forEach ( s => s . remove ( ) ) ;
81+ Promise . all ( [
82+ loadSources ( ) . then ( ( [ group , template , deliverables , charter ] ) => compute ( group , template , deliverables , charter ) ) ,
83+ delay ( 3000 ) // ensure the status is shown for at least 3s
84+ ] ) . then ( ( [ draft , timeOut ] ) => {
7685 document . documentElement . replaceWith ( draft . documentElement ) ;
7786 addExportButton ( `charter-${ config . group } -${ new Date ( ) . getFullYear ( ) } .html` ) ;
7887 } ) . catch ( err => {
@@ -292,9 +301,8 @@ async function compute(group, template, deliverables, charter) {
292301 if ( a . href . startsWith ( 'http://' ) ) {
293302 a . href = a . href . replace ( 'http://' , 'https:/' ) ;
294303 }
295- if ( a . href . startsWith ( 'https://www.w3.org/' ) ) {
296- checkGroups . push ( a ) ;
297- }
304+ // add all W3C Groups for further checks.
305+ checkGroups . push ( a ) ;
298306 } ) ;
299307 }
300308
@@ -398,7 +406,9 @@ async function compute(group, template, deliverables, charter) {
398406 head . appendChild ( scriptConfig ) ;
399407 if ( config . debug ) console . log ( config ) ;
400408 }
401-
409+
410+ // clean up if needed
411+ draft . querySelectorAll ( '.remove' ) . forEach ( s => s . remove ( ) ) ;
402412
403413 return draft ;
404414}
@@ -460,7 +470,7 @@ function replaceAnchor(group, element=document) {
460470
461471async function fetchGroupData ( ) {
462472 status ( 'Loading group data...' ) ;
463- const group = await json ( sources ( 'group' ) ) . catch ( err => err ) ;
473+ const group = await json ( sources ( 'group' ) , { signal : abortSignal ( ) } ) . catch ( err => err ) ;
464474 if ( group instanceof Error ) {
465475 failed ( `Could not load group data from W3C Groups API: ${ group . message } ` ) ;
466476 throw new Error ( 'abort' , { cause : group } ) ;
0 commit comments