added debug logging for regex matching and replacement in now function
This commit is contained in:
parent
185014493c
commit
147445df66
1 changed files with 18 additions and 3 deletions
21
index.js
21
index.js
|
|
@ -96,7 +96,7 @@ export default async function now() {
|
||||||
if (latest.image) console.log(`${item.id} Image: ${latest.image}`)
|
if (latest.image) console.log(`${item.id} Image: ${latest.image}`)
|
||||||
if (latest.video) console.log(`${item.id} Video: ${latest.video}`)
|
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 =
|
const displayText =
|
||||||
linkFormat === 'html'
|
linkFormat === 'html'
|
||||||
? latest.text
|
? latest.text
|
||||||
|
|
@ -109,13 +109,22 @@ export default async function now() {
|
||||||
? htmlServiceLinkRegex(item.id)
|
? htmlServiceLinkRegex(item.id)
|
||||||
: markdownServiceLinkRegex(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) => {
|
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(
|
const updatedOpenTag = openTag.replace(
|
||||||
/href=["'][^"']*["']/,
|
/href=["'][^"']*["']/,
|
||||||
`href="${latest.url}"`,
|
`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
|
// 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) {
|
if (now === newNow) {
|
||||||
console.log('\nNow page has no changes')
|
console.log('\nNow page has no changes')
|
||||||
} else {
|
} else {
|
||||||
|
console.log('\nChanges detected! Updating Now page...')
|
||||||
await setNow(newNow)
|
await setNow(newNow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue