Skip to content

Commit

Permalink
make sure remarkRewriteAssets does not run twice
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenSandwich committed Feb 6, 2025
1 parent f1c8406 commit d16807e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/views/docs-view/render-page-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ async function renderPageMdx(
mdxSource: MDXRemoteSerializeResult
frontMatter: Record<string, unknown>
}> {
const finalRemarkPlugins = remarkPlugins
if (
process.env.HASHI_ENV === 'unified-docs-sandbox' &&
__config.flags?.unified_docs_migrated_repos?.find(
(product) => product === scope.product
)
) {
console.log('finalRemarkPlugins 1', { finalRemarkPlugins })
finalRemarkPlugins.push(
remarkRewriteAssets({
product: scope.product as string,
version: scope.version as string,
getAssetPathParts: (nodeUrl) => [nodeUrl],
isInUDR: true,
})
)
}

console.log('finalRemarkPlugins 2', { finalRemarkPlugins })

return await trace
.getTracer('docs-view')
.startActiveSpan('renderPageMdx', async (span) => {
Expand All @@ -39,21 +59,7 @@ async function renderPageMdx(
const content = mdxContentHook(rawContent, scope)
const mdxSource = await serialize(content, {
mdxOptions: {
remarkPlugins:
process.env.HASHI_ENV === 'unified-docs-sandbox' &&
__config.flags?.unified_docs_migrated_repos?.find(
(product) => product === scope.product
)
? [
...remarkPlugins,
remarkRewriteAssets({
product: scope.product as string,
version: scope.version as string,
getAssetPathParts: (nodeUrl) => [nodeUrl],
isInUDR: true,
}),
]
: [...remarkPlugins],
remarkPlugins: finalRemarkPlugins,
rehypePlugins,
},
scope,
Expand Down
3 changes: 3 additions & 0 deletions src/views/docs-view/utils/get-deploy-preview-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export function getDeployPreviewLoader({
if (
currentRootDocsPath.productSlugForLoader?.match(
/^(terraform|ptfe-releases)/i
) &&
!__config.flags?.unified_docs_migrated_repos?.find(
(product) => product === currentRootDocsPath.productSlugForLoader
)
) {
remarkTerraformPlugins.push(
Expand Down

0 comments on commit d16807e

Please sign in to comment.