@@ -139,7 +139,9 @@ async function loadOutline(url_str: string):Promise<OpmlData> {
139
139
retVal . title = xmlTitle || "" ;
140
140
141
141
const outlineStart = Date . now ( ) ;
142
- processNode ( retVal , retVal . root , xml_data . opml . body . outline as OpmlOutline [ ] ) ;
142
+ const rawRoot = xml_data . opml . body . outline ;
143
+ const treeRoot = Array . isArray ( rawRoot ) ? rawRoot : [ rawRoot ] ;
144
+ processNode ( retVal , retVal . root , treeRoot as OpmlOutline [ ] ) ;
143
145
144
146
retVal . messages . push ( `Entries: ${ retVal . count } ` ) ;
145
147
retVal . messages . push ( `Outline parsing complete in ${ Date . now ( ) - outlineStart } ms.` ) ;
@@ -153,28 +155,30 @@ async function loadOutline(url_str: string):Promise<OpmlData> {
153
155
154
156
function processNode ( retVal : OpmlData , parent : TreeItem , data : OpmlOutline [ ] ) {
155
157
156
- //console.log(data);
157
-
158
- for ( const item of data ) {
159
- retVal . count ++ ;
160
-
161
- const newItem : TreeItem = {
162
- id : `ti- ${ retVal . count } ` ,
163
- label : item . title || item . text || "" ,
164
- htmlUrl : purifyUrl ( item . htmlUrl ) || purifyUrl ( item . url ) ,
165
- xmlUrl : purifyUrl ( item . xmlUrl ) ,
166
- children : [ ] ,
167
- } ;
168
- parent . children . push ( newItem ) ;
169
-
170
- if ( item . outline ) {
171
- const subtree : OpmlOutline [ ] = Array . isArray ( item . outline ) ? item . outline : [ item . outline ] ;
172
- processNode ( retVal , newItem , subtree ) ;
158
+ try {
159
+ for ( const item of data ) {
160
+ retVal . count ++ ;
161
+
162
+ const newItem : TreeItem = {
163
+ id : `ti- ${ retVal . count } ` ,
164
+ label : item . title || item . text || "" ,
165
+ htmlUrl : purifyUrl ( item . htmlUrl ) || purifyUrl ( item . url ) ,
166
+ xmlUrl : purifyUrl ( item . xmlUrl ) ,
167
+ children : [ ] ,
168
+ } ;
169
+ parent . children . push ( newItem ) ;
170
+
171
+ if ( item . outline ) {
172
+ const subtree : OpmlOutline [ ] = Array . isArray ( item . outline ) ? item . outline : [ item . outline ] ;
173
+ processNode ( retVal , newItem , subtree ) ;
174
+ }
173
175
}
176
+ } catch ( err : unknown ) {
177
+ retVal . errorCount ++ ;
178
+ retVal . messages . push ( "Error processing outline node: " + errorMessage ( err ) ) ;
174
179
}
175
180
}
176
181
177
-
178
182
export {
179
183
loadOutline ,
180
184
}
0 commit comments