Skip to content

Commit 94b56e8

Browse files
sarahsgithub-advanced-security[bot]Copilot
authored
Script to update filepaths to match short titles (#56749)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
1 parent 68355b8 commit 94b56e8

File tree

6 files changed

+292
-192
lines changed

6 files changed

+292
-192
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"unallowed-contributions": "tsx src/workflows/unallowed-contributions.ts",
101101
"update-data-and-image-paths": "tsx src/early-access/scripts/update-data-and-image-paths.ts",
102102
"update-enterprise-dates": "tsx src/ghes-releases/scripts/update-enterprise-dates.ts",
103+
"update-filepaths": "tsx src/content-render/scripts/update-filepaths.ts",
103104
"update-internal-links": "tsx src/links/scripts/update-internal-links.ts",
104105
"validate-asset-images": "tsx src/assets/scripts/validate-asset-images.ts",
105106
"validate-github-github-docs-urls": "tsx src/links/scripts/validate-github-github-docs-urls/index.ts",

src/content-render/scripts/move-content.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ async function main(opts, nameTuple) {
172172
// the file is a folder or not. It just needs to know the old and new hrefs.
173173
changeFeaturedLinks(oldHref, newHref)
174174

175+
// Update any links in ChildGroups on the homepage.
176+
changeHomepageLinks(oldHref, newHref, verbose)
177+
175178
if (!undo) {
176179
if (verbose) {
177180
console.log(
@@ -581,14 +584,31 @@ function changeLearningTracks(filePath, oldHref, newHref) {
581584
fs.writeFileSync(filePath, newContent, 'utf-8')
582585
}
583586

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+
584604
function changeFeaturedLinks(oldHref, newHref) {
585605
const allFiles = walk(CONTENT_ROOT, {
586606
globs: ['**/*.md'],
587607
includeBasePath: true,
588608
directories: false,
589609
}).filter((file) => !file.includes('README.md'))
590610

591-
const regex = new RegExp(`(^|%})${escapeStringRegexp(oldHref)}($|{%)`)
611+
const regex = new RegExp(`(^|%} )${escapeStringRegexp(oldHref)}($| {%)`)
592612

593613
for (const file of allFiles) {
594614
let changed = false

src/content-render/scripts/reconcile-category-dirs-with-ids.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/content-render/scripts/reconcile-filenames-with-ids.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)