Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('loadHashiConfigByEnvironment', () => {
"well-architected-framework",
"terraform-enterprise",
"sentinel",
"hcp-docs",
],
"foo": "bar",
}
Expand Down
3 changes: 2 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"ptfe-releases",
"well-architected-framework",
"terraform-enterprise",
"sentinel"
"sentinel",
"hcp-docs"
]
}
}
84 changes: 54 additions & 30 deletions src/lib/remark-plugins/remark-rewrite-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,72 @@ export function remarkRewriteAssets(args: {

return function plugin() {
return function transform(tree) {
// @ts-expect-error Types Should be correct here
visitParents<Image>(tree, 'image', (node, ancestors: Array<Parent>) => {
let url
const originalUrl = node.url
visitParents<Image>(
// @ts-expect-error Types Should be correct here
tree,
['image', 'definition'],
// @ts-expect-error Types Should be correct here
(node, ancestors: Array<Parent>) => {
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()
}
}
}
}
})
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/consul/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/hvn/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/identity/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/operations/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/packer/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/rbac/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/vagrant-box-registry/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/vault-secrets/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/vault/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/waypoint/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/hcp/api-docs/webhook/[[...page]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading