updated now function to apply markdown escaping for display text based on link format
This commit is contained in:
parent
904637fb56
commit
ec51f1c319
1 changed files with 10 additions and 2 deletions
12
index.js
12
index.js
|
|
@ -1,6 +1,7 @@
|
|||
import 'dotenv/config'
|
||||
|
||||
import { items } from './config.js'
|
||||
import { items, linkFormat } from './config.js'
|
||||
import { markdownCharEscape } from './utils.js'
|
||||
|
||||
const OMGLOL_API = `https://api.omg.lol/address/${process.env.OMGLOL_USERNAME}/now`
|
||||
|
||||
|
|
@ -36,6 +37,13 @@ export default async function now() {
|
|||
const latest = await getLatest()
|
||||
console.log(`${id}: ${latest.text}`)
|
||||
console.log(`${id} URL: ${latest.url}`)
|
||||
|
||||
// Apply markdown escaping only for markdown links
|
||||
const displayText =
|
||||
linkFormat === 'html'
|
||||
? latest.text
|
||||
: markdownCharEscape(latest.text)
|
||||
|
||||
if (latest && latest.text && latest.url) {
|
||||
newNow = newNow.replace(regex, (match, openTag, closeTag) => {
|
||||
// Replace href in opening tag
|
||||
|
|
@ -43,7 +51,7 @@ export default async function now() {
|
|||
/href=["'][^"']*["']/,
|
||||
`href="${latest.url}"`,
|
||||
)
|
||||
return `${updatedOpenTag}${latest.text}${closeTag}`
|
||||
return `${updatedOpenTag}${displayText}${closeTag}`
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue