From 147445df66a27d50bc3222964ce74e305402904e Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 31 Dec 2025 00:03:59 +0000 Subject: [PATCH 1/4] added debug logging for regex matching and replacement in now function --- index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6200e07..5e0afcb 100644 --- a/index.js +++ b/index.js @@ -96,7 +96,7 @@ export default async function now() { if (latest.image) console.log(`${item.id} Image: ${latest.image}`) if (latest.video) console.log(`${item.id} Video: ${latest.video}`) - // Apply markdown escaping only for markdown links + // apply markdown escaping only for markdown links const displayText = linkFormat === 'html' ? latest.text @@ -109,13 +109,22 @@ export default async function now() { ? htmlServiceLinkRegex(item.id) : markdownServiceLinkRegex(item.id) + console.log(`\nDEBUG: Testing regex for ${item.id}`) + console.log(`Regex: ${regex}`) + const matched = regex.test(newNow) + console.log(`Regex match found: ${matched}`) + newNow = newNow.replace(regex, (match, openTag, closeTag) => { - // Replace href in opening tag + console.log(`DEBUG: Replacing match for ${item.id}`) + console.log(`Old match: ${match}`) + // replace href in opening tag const updatedOpenTag = openTag.replace( /href=["'][^"']*["']/, `href="${latest.url}"`, ) - return `${updatedOpenTag}${displayText}${closeTag}` + const result = `${updatedOpenTag}${displayText}${closeTag}` + console.log(`New replacement: ${result}`) + return result }) // replace image/video placeholders if available, otherwise remove tags @@ -165,9 +174,15 @@ export default async function now() { }), ) + console.log('\n=== FINAL COMPARISON ===') + console.log(`Original length: ${now.length}`) + console.log(`New length: ${newNow.length}`) + console.log(`Strings are equal: ${now === newNow}`) + if (now === newNow) { console.log('\nNow page has no changes') } else { + console.log('\nChanges detected! Updating Now page...') await setNow(newNow) } } From 7740822918f83e948dc11944698862b9ebfe34fc Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 31 Dec 2025 00:19:02 +0000 Subject: [PATCH 2/4] updated regex to match service by data-service attribute in html anchor tags --- utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.js b/utils.js index 5a1dfb2..3be0f9a 100644 --- a/utils.js +++ b/utils.js @@ -6,11 +6,11 @@ import sanitizeHtml from 'sanitize-html' // helper functions // ======================================================================== -// regex to match service name within an html anchor tag +// regex to match service by data-service attribute within an html anchor tag // used when linkFormat is 'html' in config.js export function htmlServiceLinkRegex(serviceName) { return new RegExp( - `(]+href=["'][^"']*["'][^>]*>)${serviceName}(<\\/a>)`, + `(]*data-service=["']${serviceName}["'][^>]*>)([^<]*)(<\\/a>)`, 'i', ) } From 8d2c808c68a0ddf7d11c788dbacaff2f9c942083 Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 31 Dec 2025 00:19:26 +0000 Subject: [PATCH 3/4] updated regex replacement to include old text in debug logging --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5e0afcb..22e48dd 100644 --- a/index.js +++ b/index.js @@ -114,9 +114,10 @@ export default async function now() { const matched = regex.test(newNow) console.log(`Regex match found: ${matched}`) - newNow = newNow.replace(regex, (match, openTag, closeTag) => { + newNow = newNow.replace(regex, (match, openTag, oldText, closeTag) => { console.log(`DEBUG: Replacing match for ${item.id}`) console.log(`Old match: ${match}`) + console.log(`Old text: ${oldText}`) // replace href in opening tag const updatedOpenTag = openTag.replace( /href=["'][^"']*["']/, From 05904356b9d40f745ad593e9bc21c73a97dacbf5 Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 31 Dec 2025 00:19:37 +0000 Subject: [PATCH 4/4] updated now-page-template with new image handling and layout adjustments --- now-page-template.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/now-page-template.md b/now-page-template.md index eed971c..348c919 100644 --- a/now-page-template.md +++ b/now-page-template.md @@ -2,15 +2,15 @@

This page should update automatically with my latest activity.

-
I listened to this
lastfm
-
I watched this episode
trakt-episode
-
I watched this movie
trakt-movie
-
I rated this
letterboxd
-
I'm reading this
hardcover
-
I played this
steam
-
I shared this photo
some.pics
-
I wrote this
weblog
-
I pushed some (bad) code
source.tube
+
I listened to this
lastfm
+
I watched this episode
trakt-episode
+
I watched this movie
trakt-movie
+
I rated this
letterboxd
+
I'm reading this
hardcover
+
I played this
steam
+
I shared this photo
some.pics
+
I wrote this
weblog
+
I pushed some (bad) code
source.tube
{last-updated}