Skip to content

Commit

Permalink
Move private repo logic from server.ts to loader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmainwork committed Sep 11, 2024
1 parent 66adda2 commit b6253f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
21 changes: 15 additions & 6 deletions src/views/docs-view/loaders/remote-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<product>.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}`
}
Expand Down
13 changes: 1 addition & 12 deletions src/views/docs-view/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<product>.json`.
*/
const isPublicContentRepo =
product.slug !== 'hcp' && product.slug !== 'sentinel'
if (isPublicContentRepo) {
layoutProps.githubFileUrl = githubFileUrl
}
layoutProps.githubFileUrl = githubFileUrl

const { hideVersionSelector, projectName } = options

Expand Down

0 comments on commit b6253f4

Please sign in to comment.