@@ -172,6 +172,9 @@ async function main(opts, nameTuple) {
172
172
// the file is a folder or not. It just needs to know the old and new hrefs.
173
173
changeFeaturedLinks ( oldHref , newHref )
174
174
175
+ // Update any links in ChildGroups on the homepage.
176
+ changeHomepageLinks ( oldHref , newHref , verbose )
177
+
175
178
if ( ! undo ) {
176
179
if ( verbose ) {
177
180
console . log (
@@ -581,14 +584,31 @@ function changeLearningTracks(filePath, oldHref, newHref) {
581
584
fs . writeFileSync ( filePath , newContent , 'utf-8' )
582
585
}
583
586
587
+ function changeHomepageLinks ( oldHref , newHref , verbose ) {
588
+ // Can't deserialize and serialize the Yaml because it would lose
589
+ // formatting and comments. So regex replace it.
590
+ // Homepage childGroup links do not have a leading '/', so we need to remove that.
591
+ const homepageOldHref = oldHref . replace ( '/' , '' )
592
+ const homepageNewHref = newHref . replace ( '/' , '' )
593
+ const escapedHomepageOldHref = escapeStringRegexp ( homepageOldHref )
594
+ const regex = new RegExp ( `- ${ escapedHomepageOldHref } $` , 'gm' )
595
+ const homepage = path . join ( CONTENT_ROOT , 'index.md' )
596
+ const oldContent = fs . readFileSync ( homepage , 'utf-8' )
597
+ const newContent = oldContent . replace ( regex , `- ${ homepageNewHref } ` )
598
+ if ( oldContent !== newContent ) {
599
+ fs . writeFileSync ( homepage , newContent , 'utf-8' )
600
+ if ( verbose ) console . log ( `Updated homepage links` )
601
+ }
602
+ }
603
+
584
604
function changeFeaturedLinks ( oldHref , newHref ) {
585
605
const allFiles = walk ( CONTENT_ROOT , {
586
606
globs : [ '**/*.md' ] ,
587
607
includeBasePath : true ,
588
608
directories : false ,
589
609
} ) . filter ( ( file ) => ! file . includes ( 'README.md' ) )
590
610
591
- const regex = new RegExp ( `(^|%})${ escapeStringRegexp ( oldHref ) } ($|{%)` )
611
+ const regex = new RegExp ( `(^|%} )${ escapeStringRegexp ( oldHref ) } ($| {%)` )
592
612
593
613
for ( const file of allFiles ) {
594
614
let changed = false
0 commit comments