Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(license): table parsing #138

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const processTable = (tableHTML: string) => {
const results: Licenses = {};
let id: string | undefined;
let license: License | undefined;
for (const element of document.querySelectorAll('tr').values()) {
if (element.className === 'header') {
for (const element of document.querySelectorAll('td').values()) {
if (element.querySelector('.heading') != null) {
// Hello World -> hello-world
const idQuery = element
.querySelector('.family')
Expand All @@ -31,14 +31,30 @@ const processTable = (tableHTML: string) => {
.toLowerCase();
if (idQuery) id = idQuery;

const licenseQuery = element.querySelector('a')?.textContent?.trim();
const licenseHref = element.querySelector('a')?.href;
if (licenseQuery && licenseHref)
let licenseQuery = element.querySelector('a')?.textContent?.trim();
let licenseHref = element.querySelector('a')?.href;
if (licenseQuery && licenseHref) {
// Google changed their attribution page with shortened names.
switch (licenseQuery) {
case 'Open Font License':
licenseQuery = 'SIL Open Font License, 1.1';
break;
case 'Ubuntu Font License':
licenseQuery = 'Ubuntu Font License, 1.0';
break;
default:
break;
}
if (licenseHref.includes('scripts.sil.org')) {
licenseHref = 'https://openfontlicense.org';
}

license = { type: licenseQuery, url: licenseHref };
}
}

const copyrightString = element
.querySelector('.copyright')
.querySelector('p.ng-star-inserted')
?.textContent?.trim()
.split(' ');
if (id && license && copyrightString) {
Expand Down Expand Up @@ -128,7 +144,7 @@ export const parseLicenses = async () => {
await page.goto(url, { waitUntil: 'networkidle0' });

const tableHTML = await page.evaluate(() => {
const query = document.querySelector('section > table > tbody');
const query = document.querySelector('gf-attribution > section > table');
if (query) return query.outerHTML;
throw new Error('No table found for license data to parse.');
});
Expand Down
Loading