Skip to content

Commit 8112496

Browse files
authored
Fix install package name (#1377)
* Fix install package name * Fix url
1 parent 3f0bdc5 commit 8112496

1 file changed

Lines changed: 18 additions & 29 deletions

File tree

src/helpViewer/cran.ts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ type ParseFunction = (html: string, baseUrl: string) => Package[];
77

88
export 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

Comments
 (0)