Skip to content

Add markdown check for absolute URLs in links to previous posts#541

Open
frankieroberto wants to merge 4 commits into
mainfrom
add-markdown-check-for-absolute-urls
Open

Add markdown check for absolute URLs in links to previous posts#541
frankieroberto wants to merge 4 commits into
mainfrom
add-markdown-check-for-absolute-urls

Conversation

@frankieroberto

@frankieroberto frankieroberto commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Links to other posts on the site are to be encouraged!

But ideally they'd be relative links instead of full URLs. This means they'll work when previewing the site locally or in the review apps.

It will also be helpful in the (hopefully unlikely) case that the site moves to a different domain name in future.

Unlikely the existing check, for this one we can leave a direct suggestion on the pull request that authors can accept with a single click.

Will prevent this in future: #542

Screenshot

Screenshot 2026-06-22 at 11 00 34

Links to other posts on the site are to be encouraged!

But ideally they'd be relative links instead of full URLs. This means they'll work when previewing the site locally or in the review apps.

It will also be helpful in the (hopefully unlikely) case that the site moves to a different domain name in future.

Unlikely the existing check, for this one we can leave a direct suggestion on the pull request that authors can accept with a single click.
@edwardhorsford edwardhorsford temporarily deployed to dsps-design-add-markdow-ercy9m June 22, 2026 09:44 Inactive
Comment thread .github/scripts/check-markdown.mjs Fixed
Comment thread .github/scripts/check-markdown.mjs Fixed
references to the URL elsewhere are ok.
@frankieroberto frankieroberto temporarily deployed to dsps-design-add-markdow-ercy9m June 22, 2026 09:50 Inactive
@frankieroberto frankieroberto temporarily deployed to dsps-design-add-markdow-ercy9m June 22, 2026 10:00 Inactive

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 1 issue across 1 markdown file. Please address the inline comments below.

@frankieroberto frankieroberto temporarily deployed to dsps-design-add-markdow-ercy9m June 22, 2026 10:07 Inactive
@github-actions github-actions Bot dismissed their stale review June 22, 2026 10:09

No markdown issues found — all clear.

@edwardhorsford edwardhorsford left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include syntax looks like a mistake. Even if valid, is there a cleaner way of testing? Could compile the search string up front then do lineContent.startsWith(...) or similar?

path: currentFile,
line: lineNumber,
message: ABSOLUTE_URL_MESSAGE,
suggestion: lineContent.replaceAll(SITE_URL, '/')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this fail to work if they've not included the https:// bit?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@copilot update the code so that it also works if the https:// prefix has been dropped, or if http:// is used.

}
// Added line containing an absolute URL to the published site
const lineContent = rawLine.slice(1)
if (lineContent.includes('](' + SITE_URL)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax seems really weird. Is it even valid?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realise this is string concatenation. But I find it really hard to follow / it didn't look valid. Better would be string literal, though better still some variable that's described with a comment or regex.

if (/^# /.test(lines[i])) {
mistakes.push({ path: filePath, line: i + 1, message: H1_MESSAGE })
}
if (lines[i].includes('](' + SITE_URL)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is hard to follow

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realise this is string concatenation. But I find it really hard to follow / it didn't look valid. Better would be string literal, though better still some variable that's described with a comment or regex.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also won't work if there's a space in the markdown - eg [ Link text ]( url ), differences in casing (unlikely), if they don't include https://, or if it's an html link.

}
if (lines[i].includes('](' + SITE_URL)) {
mistakes.push({ path: filePath, line: i + 1, message: ABSOLUTE_URL_MESSAGE })
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will fail to work if https:// is not included

@edwardhorsford

Copy link
Copy Markdown
Collaborator

Another option would be:

lineContent.includes(`](${SITE_URL}`)

Though I think this still would fail if there are spaces in the markdown after the ]( or differences in casing or not included https::// - this is probably better as a regex test rather than string.includes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants