Skip to content

Commit 90e3b91

Browse files
authored
fix(library): ignore sentence punctuation after bare internal URLs in check:library-content (#8540)
* fix(library): ignore sentence punctuation after bare internal URLs in check:library-content * fix(library): only strip trailing punctuation from bare URLs, not explicit link targets
1 parent 491ab88 commit 90e3b91

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎scripts/check-library-content.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('check-library-content', () => {
7777
[
7878
'## Overview',
7979
'See [the guide](/library/kept-guide) and https://www.sim.ai/library/kept-guide#intro.',
80+
'Read https://www.sim.ai/library/kept-guide. Then https://www.sim.ai/library/moved-post, too.',
8081
'![diagram](/library/clean/diagram.png) and [tags](/library/tags) are not posts.',
8182
'An apex https://sim.ai/library/missing link belongs to check:site-urls.',
8283
'| a | b |',
@@ -177,6 +178,8 @@ describe('check-library-content', () => {
177178
'[b](https://www.sim.ai/library/old-guide)',
178179
'<a href="/blog/moved-post">c</a>',
179180
'[d](/blog/kept-guide)',
181+
'Also see https://www.sim.ai/library/gone.',
182+
'[e](/library/kept-guide.) and <a href="https://www.sim.ai/library/kept-guide.">f</a>',
180183
].join('\n')
181184
)
182185
expect(await findingsFor('library', 'post')).toEqual([
@@ -200,6 +203,23 @@ describe('check-library-content', () => {
200203
rule: 'internal-link',
201204
message: '/blog/kept-guide does not exist (no apps/sim/content/blog/kept-guide/index.mdx).',
202205
},
206+
{
207+
line: 14,
208+
rule: 'internal-link',
209+
message: '/library/gone does not exist (no apps/sim/content/library/gone/index.mdx).',
210+
},
211+
{
212+
line: 15,
213+
rule: 'internal-link',
214+
message:
215+
'/library/kept-guide. does not exist (no apps/sim/content/library/kept-guide./index.mdx).',
216+
},
217+
{
218+
line: 15,
219+
rule: 'internal-link',
220+
message:
221+
'/library/kept-guide. does not exist (no apps/sim/content/library/kept-guide./index.mdx).',
222+
},
203223
])
204224
})
205225

‎scripts/check-library-content.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export interface PostRef {
7676
*/
7777
const INTERNAL_LINK =
7878
/(?:https?:\/\/www\.sim\.ai|(?<=\]\(\s*|href=\{?["'`]))\/(library|blog|customers)\/([^\s)"'`#?/<>\]]+)(\/[^\s)"'`#?<>\]]*)?/g
79+
/** Sentence punctuation that ends a bare URL in prose (`…see https://www.sim.ai/library/x.`). */
80+
const TRAILING_PUNCTUATION = /[.,;:!]+$/
81+
/** Text just before a Markdown link target or `href` value, whose URL ends at its delimiter. */
82+
const LINK_TARGET_OPENER = /(?:\]\(\s*|href=\{?["'`])$/
7983
const MARKDOWN_LINK = /\[[^\]\n]*\]\([^)\n]*\)/
8084
const FAQ_HEADING = /^#{1,6}\s+FAQs?\s*:?\s*$/i
8185
const CODE_FENCE = /^\s*(```|~~~)/
@@ -330,7 +334,8 @@ export async function checkPost(
330334
}
331335
for (const match of text.matchAll(INTERNAL_LINK)) {
332336
const linkSection = match[1] as Section
333-
const target = match[2]
337+
const isBareUrl = !LINK_TARGET_OPENER.test(text.slice(0, match.index))
338+
const target = isBareUrl ? match[2].replace(TRAILING_PUNCTUATION, '') : match[2]
334339
const rest = match[3] ?? ''
335340
// A deeper path is a public asset (`/library/<slug>/cover.jpg`) or a static sub-route.
336341
if (rest !== '' && rest !== '/') continue

0 commit comments

Comments
 (0)