@@ -7,10 +7,11 @@ type ParseFunction = (html: string, baseUrl: string) => Package[];
77
88export async function getPackagesFromCran ( cranUrl : string ) : Promise < Package [ ] > {
99 const cranSites : { url : string , parseFunction : ParseFunction } [ ] = [
10- {
11- url : new URL ( 'stats/descriptions' , cranUrl ) . toString ( ) ,
12- parseFunction : parseCranJson
13- } ,
10+ // NOTE: Not working any more
11+ // {
12+ // url: new URL('stats/descriptions', cranUrl).toString(),
13+ // parseFunction: parseCranJson
14+ // },
1415 {
1516 url : new URL ( 'web/packages/available_packages_by_date.html' , cranUrl ) . toString ( ) ,
1617 parseFunction : parseCranTable
@@ -83,35 +84,23 @@ function parseCranTable(html: string, baseUrl: string): Package[] {
8384 tables . each ( ( tableIndex , table ) => {
8485 const rows = $ ( 'tr' , table ) ;
8586 rows . each ( ( rowIndex , row ) => {
86- const elements = $ ( 'td' , row ) ;
87- if ( elements . length === 3 ) {
88-
89- const e0 = elements [ 0 ] ;
90- const e1 = elements [ 1 ] ;
91- const e2 = elements [ 2 ] ;
92- if (
93- e0 . type === 'tag' && e1 . type === 'tag' &&
94- e0 . firstChild ?. type === 'text' && e1 . children [ 1 ] . type === 'tag' &&
95- e2 . type === 'tag'
96- ) {
97- const href = e1 . children [ 1 ] . attribs [ 'href' ] ;
98- const url = new URL ( href , baseUrl ) . toString ( ) ;
99- ret . push ( {
100- date : ( e0 . firstChild . data || '' ) . trim ( ) ,
101- name : ( e1 . children [ 1 ] . firstChild ?. data || '' ) . trim ( ) ,
102- href : url ,
103- description : ( e2 . firstChild ?. data || '' ) . trim ( ) ,
104- isCran : true
105- } ) ;
106- }
107- }
87+ if ( rowIndex === 0 ) return ; // Skip the header row
88+ const date = $ ( row ) . find ( 'td:nth-child(1)' ) . text ( ) . trim ( ) ;
89+ const href = $ ( row ) . find ( 'td:nth-child(2) a' ) . attr ( 'href' ) ;
90+ const url = href ? new URL ( href , baseUrl ) . toString ( ) : undefined ;
91+ const name = $ ( row ) . find ( 'td:nth-child(2) span' ) . text ( ) . trim ( ) ;
92+ const title = $ ( row ) . find ( 'td:nth-child(3)' ) . text ( ) . trim ( ) ;
93+ ret . push ( {
94+ date : date ,
95+ name : name ,
96+ href : url ,
97+ description : title ,
98+ isCran : true
99+ } ) ;
108100 } ) ;
109101 } ) ;
110102
111103 const retSorted = ret . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
112104
113105 return retSorted ;
114106}
115-
116-
117-
0 commit comments