-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add config file and logic #1
base: main
Are you sure you want to change the base?
Conversation
@@ -1,5 +1,6 @@ | |||
import fetch from 'node-fetch' | |||
import { load } from 'cheerio' | |||
import links from './links.json' assert { type: 'json' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize this feature is already available
Although it prints a warning every time https://nodejs.org/api/esm.html#json-modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just call it config.mjs
to avoid the warning. The user can't even configure this as its written.
@@ -8,6 +9,26 @@ export async function check(url = new URL('http://example.com'), referer, seen = | |||
} | |||
seen.add(url.href); | |||
const res = await fetch(url, { headers: { 'user-agent': 'npm:links-awakening' } }).catch(e => e); | |||
const html = res.ok ? await res.text() : null; | |||
|
|||
// deal with config cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// deal with config cases |
|
||
// deal with config cases | ||
for (const link of links.config) { | ||
if (url.href.includes(link.url)) { // TODO: this check needs precision in url comparison (www vs no www), etc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the very least, we need startsWith
. But we probably need something like this new feature in the future: https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
returns yellow status if: