diff --git a/config/__tests__/index.test.js b/config/__tests__/index.test.js index 85a49fe466..7f01b33064 100644 --- a/config/__tests__/index.test.js +++ b/config/__tests__/index.test.js @@ -42,6 +42,7 @@ describe('loadHashiConfigByEnvironment', () => { "well-architected-framework", "terraform-enterprise", "sentinel", + "hcp-docs", ], "foo": "bar", } diff --git a/config/production.json b/config/production.json index 6ef5cc7b15..2e798b12ee 100644 --- a/config/production.json +++ b/config/production.json @@ -32,7 +32,8 @@ "ptfe-releases", "well-architected-framework", "terraform-enterprise", - "sentinel" + "sentinel", + "hcp-docs" ] } } diff --git a/src/lib/remark-plugins/remark-rewrite-assets.ts b/src/lib/remark-plugins/remark-rewrite-assets.ts index f3f1f21047..7c9bc4c0cb 100644 --- a/src/lib/remark-plugins/remark-rewrite-assets.ts +++ b/src/lib/remark-plugins/remark-rewrite-assets.ts @@ -28,48 +28,72 @@ export function remarkRewriteAssets(args: { return function plugin() { return function transform(tree) { - // @ts-expect-error Types Should be correct here - visitParents(tree, 'image', (node, ancestors: Array) => { - let url - const originalUrl = node.url + visitParents( + // @ts-expect-error Types Should be correct here + tree, + ['image', 'definition'], + // @ts-expect-error Types Should be correct here + (node, ancestors: Array) => { + let url + const originalUrl = node.url - if (isInUDR) { - let domain + /** + * The Definition node could be used by an image or link reference + * This regex checks if the path starts with /img or /public/img. While + * a brittle check, it prevents links references from breaking. + * + * We need to follow with a more comprehensive, long-term solution + * to selectively delineate image from link. + */ + const regex = /^\/img|\/public\/img/ // Ensures non-image links aren't rewritten + const isImagePath = regex.test(originalUrl) - if (process.env.NODE_ENV === 'development') { - domain = `http://localhost:${process.env.UNIFIED_DOCS_PORT}` - } else { - domain = process.env.UNIFIED_DOCS_API - } + if (isImagePath) { + if (isInUDR) { + let domain - url = new URL(`${domain}/api/assets/${product}/${version}${node.url}`) - } else { - const asset = path.posix.join(...getAssetPathParts(originalUrl)) + if (process.env.NODE_ENV === 'development') { + domain = `http://localhost:${process.env.UNIFIED_DOCS_PORT}` + } else { + domain = process.env.UNIFIED_DOCS_API + } - url = new URL(`${process.env.MKTG_CONTENT_DOCS_API}/api/assets`) - url.searchParams.append('asset', asset) - url.searchParams.append('version', version) - url.searchParams.append('product', product) - } + url = new URL( + `${domain}/api/assets/${product}/${version}${node.url}` + ) + } else { + const asset = path.posix.join(...getAssetPathParts(originalUrl)) + + url = new URL(`${process.env.MKTG_CONTENT_DOCS_API}/api/assets`) + url.searchParams.append('asset', asset) + url.searchParams.append('version', version) + url.searchParams.append('product', product) + } - node.url = url.toString() - logOnce( - node.url, - `Rewriting asset url for local preview: + node.url = url.toString() + logOnce( + node.url, + `Rewriting asset url for local preview: - Found: ${originalUrl} - Replaced with: ${node.url} If this is a net-new asset, you'll need to commit and push it to GitHub.\n` - ) + ) - // if the image is wrapped in a link, and shares the same url as the original image, then update the link's url to the new asset url - if (isInUDR) { - const parent = ancestors[ancestors.length - 1] - if (parent && parent.type === 'link' && parent.url === originalUrl) { - parent.url = url.toString() + // if the image is wrapped in a link, and shares the same url as the original image, then update the link's url to the new asset url + if (isInUDR) { + const parent = ancestors[ancestors.length - 1] + if ( + parent && + parent.type === 'link' && + parent.url === originalUrl + ) { + parent.url = url.toString() + } + } } } - }) + ) } } } diff --git a/src/pages/hcp/api-docs/consul/[[...page]].tsx b/src/pages/hcp/api-docs/consul/[[...page]].tsx index 1eaf840b61..d4aaed27e7 100644 --- a/src/pages/hcp/api-docs/consul/[[...page]].tsx +++ b/src/pages/hcp/api-docs/consul/[[...page]].tsx @@ -36,8 +36,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { serviceProductSlug: 'consul', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-global-network-manager-service', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-global-network-manager-service', ref: 'main', }, statusIndicatorConfig: { diff --git a/src/pages/hcp/api-docs/hvn/[[...page]].tsx b/src/pages/hcp/api-docs/hvn/[[...page]].tsx index dcbe44cfd4..eab69a96d1 100644 --- a/src/pages/hcp/api-docs/hvn/[[...page]].tsx +++ b/src/pages/hcp/api-docs/hvn/[[...page]].tsx @@ -33,8 +33,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { basePath: '/hcp/api-docs/hvn', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-network', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-network', ref: 'main', }, groupOperationsByPath: true, diff --git a/src/pages/hcp/api-docs/identity/[[...page]].tsx b/src/pages/hcp/api-docs/identity/[[...page]].tsx index e63c4d6c8b..fbd75a8bc2 100644 --- a/src/pages/hcp/api-docs/identity/[[...page]].tsx +++ b/src/pages/hcp/api-docs/identity/[[...page]].tsx @@ -33,8 +33,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { basePath: '/hcp/api-docs/identity', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-iam', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-iam', ref: 'main', }, groupOperationsByPath: true, diff --git a/src/pages/hcp/api-docs/operations/[[...page]].tsx b/src/pages/hcp/api-docs/operations/[[...page]].tsx index 6c0a693459..6eada857aa 100644 --- a/src/pages/hcp/api-docs/operations/[[...page]].tsx +++ b/src/pages/hcp/api-docs/operations/[[...page]].tsx @@ -33,8 +33,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { basePath: '/hcp/api-docs/operations', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-operation', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-operation', ref: 'main', }, groupOperationsByPath: true, diff --git a/src/pages/hcp/api-docs/packer/[[...page]].tsx b/src/pages/hcp/api-docs/packer/[[...page]].tsx index dc8dbb0266..502ae4e6c3 100644 --- a/src/pages/hcp/api-docs/packer/[[...page]].tsx +++ b/src/pages/hcp/api-docs/packer/[[...page]].tsx @@ -35,8 +35,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { serviceProductSlug: 'packer', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-packer-service', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-packer-service', ref: 'main', }, statusIndicatorConfig: { diff --git a/src/pages/hcp/api-docs/rbac/[[...page]].tsx b/src/pages/hcp/api-docs/rbac/[[...page]].tsx index 7fb7913500..cd1f2f7928 100644 --- a/src/pages/hcp/api-docs/rbac/[[...page]].tsx +++ b/src/pages/hcp/api-docs/rbac/[[...page]].tsx @@ -33,8 +33,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { productSlug: 'hcp', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-resource-manager', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-resource-manager', ref: 'main', }, navResourceItems: [ diff --git a/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx b/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx index 49ccadbec4..9eb07754f9 100644 --- a/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx +++ b/src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx @@ -34,8 +34,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { basePath: '/hcp/api-docs/vagrant-box-registry', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-vagrant-box-registry', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-vagrant-box-registry', ref: 'main', }, groupOperationsByPath: true, diff --git a/src/pages/hcp/api-docs/vault-secrets/[[...page]].tsx b/src/pages/hcp/api-docs/vault-secrets/[[...page]].tsx index ab75dc35c3..567be27d4e 100644 --- a/src/pages/hcp/api-docs/vault-secrets/[[...page]].tsx +++ b/src/pages/hcp/api-docs/vault-secrets/[[...page]].tsx @@ -49,8 +49,8 @@ const PAGE_CONFIG: OpenApiDocsViewV2Config = { ], schemaSource: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-vault-secrets', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-vault-secrets', ref: 'main', }, productContext: 'hcp', diff --git a/src/pages/hcp/api-docs/vault/[[...page]].tsx b/src/pages/hcp/api-docs/vault/[[...page]].tsx index d87376bc0c..8d9dd9fb56 100644 --- a/src/pages/hcp/api-docs/vault/[[...page]].tsx +++ b/src/pages/hcp/api-docs/vault/[[...page]].tsx @@ -49,8 +49,8 @@ const PAGE_CONFIG: OpenApiDocsViewV2Config = { ], schemaSource: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-vault-service', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-vault-service', ref: 'main', }, productContext: 'hcp', diff --git a/src/pages/hcp/api-docs/waypoint/[[...page]].tsx b/src/pages/hcp/api-docs/waypoint/[[...page]].tsx index 2500c769c8..7228b20633 100644 --- a/src/pages/hcp/api-docs/waypoint/[[...page]].tsx +++ b/src/pages/hcp/api-docs/waypoint/[[...page]].tsx @@ -30,8 +30,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { basePath: '/hcp/api-docs/waypoint', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-waypoint-service', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-waypoint-service', ref: 'main', }, groupOperationsByPath: true, diff --git a/src/pages/hcp/api-docs/webhook/[[...page]].tsx b/src/pages/hcp/api-docs/webhook/[[...page]].tsx index 2d311338c1..4fb8169256 100644 --- a/src/pages/hcp/api-docs/webhook/[[...page]].tsx +++ b/src/pages/hcp/api-docs/webhook/[[...page]].tsx @@ -29,8 +29,8 @@ const PAGE_CONFIG: OpenApiDocsPageConfig = { productSlug: 'hcp', githubSourceDirectory: { owner: 'hashicorp', - repo: 'hcp-specs', - path: 'specs/cloud-webhook', + repo: 'web-unified-docs', + path: 'content/hcp-docs/specs/cloud-webhook', ref: 'main', }, statusIndicatorConfig: {