diff --git a/productConfig.mjs b/productConfig.mjs index 3d1717b6ef..d3f2549070 100644 --- a/productConfig.mjs +++ b/productConfig.mjs @@ -202,6 +202,7 @@ export const PRODUCT_CONFIG = { * See note at top of this document on `pages` directories for details. */ assetDir: 'public/images', + basePaths: ['sentinel'], /** * TODO: consider implications of Sentinel's `contentDir`. * @@ -444,6 +445,7 @@ export const PRODUCT_CONFIG = { * See note at top of this document on `pages` directories for details. */ assetDir: 'public/img', + basePaths: ['api-docs', 'docs'], contentDir: 'content', dataDir: 'data', productSlug: 'vault', diff --git a/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.mjs b/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.mjs index 3cab0a9477..ee04691ed5 100644 --- a/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.mjs +++ b/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.mjs @@ -20,6 +20,14 @@ import { PRODUCT_CONFIG } from '#productConfig.mjs' * @returns {Function} A transformer function that rewrites internal links in the document tree. */ export const rewriteInternalLinksPlugin = ({ entry, versionMetadata }) => { + /** This REGEX is used to parse a product version from a URL */ + const VERSION_IN_PATH_REGEX = /^v\d+\.\d+\.(\d+|\w+)/i + + /** This REGEX is used to parse a product version that does not include 'v' at the beginning */ + const NO_V_VERSION_IN_PATH_REGEX = /^\d+\.\d+\.(\d+|\w+)/i + + /** This REGEX is used to parse a Terraform Enterprise version from a URL */ + const TFE_VERSION_IN_PATH_REGEXP = /^v[0-9]{6}-\d+/i const relativePath = entry.filePath.split('content/')[1] /** * product and version variables, which are assigned based on the @@ -65,8 +73,18 @@ export const rewriteInternalLinksPlugin = ({ entry, versionMetadata }) => { return flatMap(tree, (node) => { // Check if the node is a link and matches the pattern for links to rewrite if (node.type === 'link' && isLinkToRewritePattern.test(node.url)) { - // Replace the matched part of the URL with the versioned path - node.url = node.url.replace(replacePattern, `/$1/${cleanVersion}$2`) + const splitUrl = node.url.split('/') + const hasVersionInPath = splitUrl.find((el) => { + return ( + TFE_VERSION_IN_PATH_REGEXP.test(el) || + VERSION_IN_PATH_REGEX.test(el) || + NO_V_VERSION_IN_PATH_REGEX.test(el) + ) + }) + // Replace the matched part of the URL with the versioned path if no version is present + if (!hasVersionInPath) { + node.url = node.url.replace(replacePattern, `/$1/${cleanVersion}$2`) + } } // Return the node (those with and without a versioned path) return [node] diff --git a/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.test.mjs b/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.test.mjs index bbb22d7c56..e471fb5124 100644 --- a/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.test.mjs +++ b/scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.test.mjs @@ -316,4 +316,49 @@ describe('transformRewriteInternalLinks', () => { ) expect(result).toBe(expectedOutput) }) + + it('should not rewrite links if they already contain a version that starts with v', async () => { + const content = `[Link to versioned path](/terraform/language/v1.7.x/some-page)` + const entry = { + filePath: 'content/terraform/v1.8.x/docs/language/some-file.mdx', + } + const expectedOutput = + '[Link to versioned path](/terraform/language/v1.7.x/some-page)\n' + const result = await transformRewriteInternalLinks( + content, + entry, + versionMetadata, + ) + expect(result).toBe(expectedOutput) + }) + + it('should not rewrite links if they already contain a version that does not start with v', async () => { + const content = `[Link to versioned path](/terraform/language/1.7.x/some-page)` + const entry = { + filePath: 'content/terraform/1.8.x/docs/language/some-file.mdx', + } + const expectedOutput = + '[Link to versioned path](/terraform/language/1.7.x/some-page)\n' + const result = await transformRewriteInternalLinks( + content, + entry, + versionMetadata, + ) + expect(result).toBe(expectedOutput) + }) + + it('should not rewrite links if they already contain a special terraform version', async () => { + const content = `[Link to versioned path](/terraform/language/v202509-01/some-page)` + const entry = { + filePath: 'content/terraform/v202509-02/docs/language/some-file.mdx', + } + const expectedOutput = + '[Link to versioned path](/terraform/language/v202509-01/some-page)\n' + const result = await transformRewriteInternalLinks( + content, + entry, + versionMetadata, + ) + expect(result).toBe(expectedOutput) + }) }) diff --git a/scripts/prebuild/prebuild-arm-linux-binary.gz b/scripts/prebuild/prebuild-arm-linux-binary.gz index c68a65e594..8c2f739639 100755 Binary files a/scripts/prebuild/prebuild-arm-linux-binary.gz and b/scripts/prebuild/prebuild-arm-linux-binary.gz differ diff --git a/scripts/prebuild/prebuild-arm-mac-binary.gz b/scripts/prebuild/prebuild-arm-mac-binary.gz index 132d354846..bb7bc95adc 100755 Binary files a/scripts/prebuild/prebuild-arm-mac-binary.gz and b/scripts/prebuild/prebuild-arm-mac-binary.gz differ diff --git a/scripts/prebuild/prebuild-x64-linux-binary.gz b/scripts/prebuild/prebuild-x64-linux-binary.gz index eda8f30f87..722dd174a7 100755 Binary files a/scripts/prebuild/prebuild-x64-linux-binary.gz and b/scripts/prebuild/prebuild-x64-linux-binary.gz differ