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] 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