From cc1fb0f02a41ab25713498bc27aba69431f73dd6 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:06:45 -0400 Subject: [PATCH 1/4] Simplify isPublicContentRepo expression Since `isHcp` and `isSentinel` aren't used elsewhere, this expression can be simplified down to a one-liner Co-authored-by: Heat Hamilton <55773810+heatlikeheatwave@users.noreply.github.com> --- src/views/docs-view/server.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/views/docs-view/server.ts b/src/views/docs-view/server.ts index 84424c41ed..1856af3e7c 100644 --- a/src/views/docs-view/server.ts +++ b/src/views/docs-view/server.ts @@ -418,9 +418,8 @@ export function getStaticGenerationFunctions< * Note: If we need more granularity here, we could change this to be * part of `rootDocsPath` configuration in `src/data/.json`. */ - const isHcp = product.slug == 'hcp' - const isSentinel = product.slug == 'sentinel' - const isPublicContentRepo = !isHcp && !isSentinel + const isPublicContentRepo = + product.slug !== 'hcp' && product.slug !== 'sentinel' if (isPublicContentRepo) { layoutProps.githubFileUrl = githubFileUrl } From c991e259d0c5dabe00661f3b2a548ab005a7a461 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:32:10 -0400 Subject: [PATCH 2/4] Use URL to detect terraform enterprise This will hide the "Edit on GitHub" link for terraform enterprise only --- src/views/docs-view/server.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/views/docs-view/server.ts b/src/views/docs-view/server.ts index 1856af3e7c..80d06ea717 100644 --- a/src/views/docs-view/server.ts +++ b/src/views/docs-view/server.ts @@ -419,7 +419,9 @@ export function getStaticGenerationFunctions< * part of `rootDocsPath` configuration in `src/data/.json`. */ const isPublicContentRepo = - product.slug !== 'hcp' && product.slug !== 'sentinel' + product.slug !== 'hcp' && + product.slug !== 'sentinel' && + product.slug + currentPathUnderProduct !== 'terraform/enterprise' if (isPublicContentRepo) { layoutProps.githubFileUrl = githubFileUrl } From 66adda2a67632d402656a7567db5655751a81898 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:58:51 -0400 Subject: [PATCH 3/4] Move PTFE detection logic from server.ts to loader --- src/views/docs-view/loaders/remote-content.ts | 8 +++++++- src/views/docs-view/server.ts | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/views/docs-view/loaders/remote-content.ts b/src/views/docs-view/loaders/remote-content.ts index 36b55e43e2..65ff15b138 100644 --- a/src/views/docs-view/loaders/remote-content.ts +++ b/src/views/docs-view/loaders/remote-content.ts @@ -264,7 +264,13 @@ export default class RemoteContentLoader implements DataLoader { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion versionMetadataList.find((e) => e.version === document.version)! .isLatest - if (isLatest) { + + // We shouldn't be showing "Edit on GitHub" links for PTFE because + // it takes people to a 404 on GitHub if they're not members of the + // GitHub org + const isPtfe = document.product === 'ptfe-releases' + + if (isLatest && !isPtfe) { // GitHub only allows you to modify a file if you are on a branch, not a commit githubFileUrl = `https://github.com/hashicorp/${this.opts.product}/blob/${this.opts.mainBranch}/${document.githubFile}` } diff --git a/src/views/docs-view/server.ts b/src/views/docs-view/server.ts index 80d06ea717..1856af3e7c 100644 --- a/src/views/docs-view/server.ts +++ b/src/views/docs-view/server.ts @@ -419,9 +419,7 @@ export function getStaticGenerationFunctions< * part of `rootDocsPath` configuration in `src/data/.json`. */ const isPublicContentRepo = - product.slug !== 'hcp' && - product.slug !== 'sentinel' && - product.slug + currentPathUnderProduct !== 'terraform/enterprise' + product.slug !== 'hcp' && product.slug !== 'sentinel' if (isPublicContentRepo) { layoutProps.githubFileUrl = githubFileUrl } From b6253f4213472229870b41acc953766418e9123d Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:49:10 -0400 Subject: [PATCH 4/4] Move private repo logic from server.ts to loader Since logic was implemented in the loader to hide the "Edit this page on GitHub" link for PTFE, it makes sense to move the other (similar) logic there too to keep everything together. Additionally, this also allows the expression to be cleaned up to use `this.opts.product` and `Array.includes()` to detect private repos. --- src/views/docs-view/loaders/remote-content.ts | 21 +++++++++++++------ src/views/docs-view/server.ts | 13 +----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/views/docs-view/loaders/remote-content.ts b/src/views/docs-view/loaders/remote-content.ts index 65ff15b138..89d9862ba2 100644 --- a/src/views/docs-view/loaders/remote-content.ts +++ b/src/views/docs-view/loaders/remote-content.ts @@ -265,12 +265,21 @@ export default class RemoteContentLoader implements DataLoader { versionMetadataList.find((e) => e.version === document.version)! .isLatest - // We shouldn't be showing "Edit on GitHub" links for PTFE because - // it takes people to a 404 on GitHub if they're not members of the - // GitHub org - const isPtfe = document.product === 'ptfe-releases' - - if (isLatest && !isPtfe) { + /** + * We want to show "Edit on GitHub" links for public content repos only. + * Currently, HCP, PTFE and Sentinel docs are stored in private + * repositories. + * + * Note: If we need more granularity here, we could change this to be + * part of `rootDocsPath` configuration in `src/data/.json`. + */ + const isPrivateContentRepo = [ + 'hcp-docs', + 'sentinel', + 'ptfe-releases', + ].includes(this.opts.product) + + if (isLatest && !isPrivateContentRepo) { // GitHub only allows you to modify a file if you are on a branch, not a commit githubFileUrl = `https://github.com/hashicorp/${this.opts.product}/blob/${this.opts.mainBranch}/${document.githubFile}` } diff --git a/src/views/docs-view/server.ts b/src/views/docs-view/server.ts index 1856af3e7c..4376a74698 100644 --- a/src/views/docs-view/server.ts +++ b/src/views/docs-view/server.ts @@ -411,18 +411,7 @@ export function getStaticGenerationFunctions< validVersions.length > 0 && (validVersions.length > 1 || validVersions[0].version !== 'v0.0.x') - /** - * We want to show "Edit on GitHub" links for public content repos only. - * Currently, HCP and Sentinel docs are stored in private repositories. - * - * Note: If we need more granularity here, we could change this to be - * part of `rootDocsPath` configuration in `src/data/.json`. - */ - const isPublicContentRepo = - product.slug !== 'hcp' && product.slug !== 'sentinel' - if (isPublicContentRepo) { - layoutProps.githubFileUrl = githubFileUrl - } + layoutProps.githubFileUrl = githubFileUrl const { hideVersionSelector, projectName } = options