From a0e08722d986e8d01f313beea9211f056b1f66c0 Mon Sep 17 00:00:00 2001 From: platane Date: Fri, 6 Jan 2023 08:25:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20adapt=20the=20parser=20to=20the?= =?UTF-8?q?=20new=20github=20page=20markup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/github-user-contribution/index.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/github-user-contribution/index.ts b/packages/github-user-contribution/index.ts index 14b0ce6..9d9b9e5 100644 --- a/packages/github-user-contribution/index.ts +++ b/packages/github-user-contribution/index.ts @@ -47,18 +47,22 @@ const parseUserPage = (content: string) => { let x = 0; let lastYAttribute = 0; - const rects = Array.from(block.matchAll(/]*>/g)).map(([m]) => { - const date = m.match(/data-date="([^"]+)"/)![1]; - const count = +m.match(/data-count="([^"]+)"/)![1]; - const level = +m.match(/data-level="([^"]+)"/)![1]; - const yAttribute = +m.match(/y="([^"]+)"/)![1]; + const rects = Array.from(block.matchAll(/]*>[^<]*<\/rect>/g)).map( + ([m]) => { + const date = m.match(/data-date="([^"]+)"/)![1]; + const level = +m.match(/data-level="([^"]+)"/)![1]; + const yAttribute = +m.match(/y="([^"]+)"/)![1]; - if (lastYAttribute > yAttribute) x++; + const literalCount = m.match(/(No|\d+) contributions? on/)![1]; + const count = literalCount === "No" ? 0 : +literalCount; - lastYAttribute = yAttribute; + if (lastYAttribute > yAttribute) x++; - return { date, count, level, x, yAttribute }; - }); + lastYAttribute = yAttribute; + + return { date, count, level, x, yAttribute }; + } + ); const yAttributes = Array.from( new Set(rects.map((c) => c.yAttribute)).keys()