@@ -325,19 +325,29 @@ function buildInboundMarkdownIndex(fileCache) {
325325 return index ;
326326}
327327
328+ // Sidebar refs use version-agnostic doc IDs (Docusaurus resolves them per
329+ // version via the sidebar file's own version). Key the index by version|docId
330+ // so deleting `docs/foo.md` (current) does not flag versioned sidebars that
331+ // legitimately reference their own `versioned_docs/version-X.x/foo.md` copy.
328332function buildInboundSidebarIndex ( rootDir , manifest ) {
333+ const sidebarVersion = new Map ( ) ;
334+ for ( const entry of manifest . entries ) {
335+ if ( entry . sidebar_source && ! sidebarVersion . has ( entry . sidebar_source ) ) {
336+ sidebarVersion . set ( entry . sidebar_source , entry . version ) ;
337+ }
338+ }
329339 const index = new Map ( ) ;
330- const sidebars = new Set ( manifest . entries . map ( ( entry ) => entry . sidebar_source ) . filter ( Boolean ) ) ;
331- for ( const sidebarSource of sidebars ) {
340+ for ( const [ sidebarSource , version ] of sidebarVersion ) {
332341 const loaded = loadSidebarRefs ( rootDir , sidebarSource ) ;
333342 if ( loaded . missing ) {
334343 continue ;
335344 }
336345 for ( const docId of loaded . refs ) {
337- let bucket = index . get ( docId ) ;
346+ const key = `${ version } |${ docId } ` ;
347+ let bucket = index . get ( key ) ;
338348 if ( ! bucket ) {
339349 bucket = [ ] ;
340- index . set ( docId , bucket ) ;
350+ index . set ( key , bucket ) ;
341351 }
342352 bucket . push ( { path : sidebarSource , line : 1 } ) ;
343353 }
@@ -354,6 +364,14 @@ function oldPathToDocId(oldPath) {
354364 . replace ( / ^ i 1 8 n \/ z h - C N \/ d o c u s a u r u s - p l u g i n - c o n t e n t - d o c s - c o m m u n i t y \/ c u r r e n t \/ / , 'community:' ) ;
355365}
356366
367+ function oldPathToVersion ( oldPath ) {
368+ const versioned = oldPath . match (
369+ / ^ (?: v e r s i o n e d _ d o c s | i 1 8 n \/ z h - C N \/ d o c u s a u r u s - p l u g i n - c o n t e n t - d o c s ) \/ v e r s i o n - ( [ ^ / ] + ) \/ / ,
370+ ) ;
371+ if ( versioned ) return versioned [ 1 ] ;
372+ return 'current' ;
373+ }
374+
357375function lintMovedOrDeletedLinks ( rootDir , manifest , changedRecords , fileCache ) {
358376 const records = recordOldPaths ( changedRecords || [ ] ) ;
359377 if ( records . length === 0 ) {
@@ -365,10 +383,17 @@ function lintMovedOrDeletedLinks(rootDir, manifest, changedRecords, fileCache) {
365383 const findings = [ ] ;
366384
367385 for ( const record of records ) {
368- const rule = record . status === 'R' ? 'link-moved-file-inbound-reference' : 'link-deleted-file-inbound-reference' ;
386+ const isDelete = record . status === 'D' || ! record . path || record . path === record . oldPath ;
387+ const rule = isDelete ? 'link-deleted-file-inbound-reference' : 'link-moved-file-inbound-reference' ;
369388 const markdownRefs = markdownIndex . get ( record . oldPath ) || [ ] ;
370- const sidebarRefs = sidebarIndex . get ( oldPathToDocId ( record . oldPath ) ) || [ ] ;
371- const inboundMessage = `Inbound link still points to changed path ${ record . oldPath } ; review and update target ${ record . path || '' } .` . trim ( ) ;
389+ const sidebarKey = `${ oldPathToVersion ( record . oldPath ) } |${ oldPathToDocId ( record . oldPath ) } ` ;
390+ const sidebarRefs = sidebarIndex . get ( sidebarKey ) || [ ] ;
391+ const inboundMessage = isDelete
392+ ? `Inbound reference points to deleted path ${ record . oldPath } ; remove this reference.`
393+ : `Inbound reference points to old path ${ record . oldPath } ; update to new path ${ record . path } .` ;
394+ const redirectMessage = isDelete
395+ ? `Markdown path ${ record . oldPath } was deleted; review redirects and inbound references before merging.`
396+ : `Markdown path changed from ${ record . oldPath } to ${ record . path } ; review redirects and inbound links before merging.` ;
372397 const relatedPaths = [ record . oldPath , record . path ] . filter ( Boolean ) ;
373398
374399 for ( const ref of markdownRefs ) {
@@ -383,7 +408,7 @@ function lintMovedOrDeletedLinks(rootDir, manifest, changedRecords, fileCache) {
383408 'link-path-change-redirect-review' ,
384409 record . path || record . oldPath ,
385410 1 ,
386- `Markdown path changed from ${ record . oldPath } ; review redirects and inbound links before merging.` ,
411+ redirectMessage ,
387412 undefined ,
388413 relatedPaths ,
389414 ) ,
0 commit comments