forked from hashicorp/terraform-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from DmytroHryshyn/next/13/pages-to-app/app/cl…
…oud-docs-yss-h126u5v58nlxdnhobn0n-rc next/13/pages-to-app/app/cloud-docs
- Loading branch information
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { productName } from 'data/metadata'; | ||
import DocsPage from 'components/docs-page'; | ||
import otherDocsData from 'data/other-docs-nav-data.json'; | ||
// Imports below are only used server-side | ||
import { getStaticGenerationFunctions } from '@hashicorp/react-docs-page/server'; | ||
import path from 'path'; | ||
import { rehypePlugins, remarkPlugins } from 'lib/remark-rehype-plugins'; | ||
import { remarkRewriteAssets } from 'lib/remark-rewrite-assets'; | ||
// Configure the docs path | ||
const BASE_ROUTE = 'cloud-docs'; | ||
const NAV_DATA = path.join( | ||
process.env.NAV_DATA_DIRNAME, | ||
BASE_ROUTE + '-nav-data.json', | ||
); | ||
const CONTENT_DIR = path.join(process.env.CONTENT_DIRNAME, BASE_ROUTE); | ||
const PRODUCT = { name: productName, slug: 'terraform' } as const; | ||
const SOURCE_REPO = 'terraform-docs-common'; | ||
const DEFAULT_BRANCH = 'main'; | ||
export default function CloudDocsLayout(props) { | ||
// add the "other docs" section to the bottom of the nav data | ||
const modifiedProps = Object.assign({}, props); | ||
modifiedProps.navData = modifiedProps.navData.concat(otherDocsData); | ||
return ( | ||
<DocsPage | ||
baseRoute={BASE_ROUTE} | ||
product={PRODUCT} | ||
staticProps={modifiedProps} | ||
showVersionSelect={false} | ||
/> | ||
); | ||
} | ||
const { getStaticPaths, getStaticProps } = getStaticGenerationFunctions( | ||
process.env.IS_CONTENT_PREVIEW && | ||
process.env.PREVIEW_FROM_REPO === SOURCE_REPO | ||
? { | ||
strategy: 'fs', | ||
localContentDir: CONTENT_DIR, | ||
navDataFile: NAV_DATA, | ||
product: SOURCE_REPO, | ||
githubFileUrl(filepath) { | ||
// This path rewriting is meant for local preview from `terraform-docs-common`. | ||
filepath = filepath.replace('preview/', ''); | ||
return `https://github.com/hashicorp/${SOURCE_REPO}/blob/${DEFAULT_BRANCH}/website/${filepath}`; | ||
}, | ||
remarkPlugins: (params) => [ | ||
...remarkPlugins, | ||
remarkRewriteAssets({ | ||
product: SOURCE_REPO, | ||
version: process.env.CURRENT_GIT_BRANCH, | ||
getAssetPathParts: (nodeUrl) => ['website', nodeUrl], | ||
}), | ||
], | ||
rehypePlugins, | ||
} | ||
: { | ||
fallback: 'blocking', | ||
revalidate: 3600, | ||
strategy: 'remote', | ||
basePath: BASE_ROUTE, | ||
product: SOURCE_REPO, | ||
remarkPlugins, | ||
rehypePlugins, | ||
}, | ||
); | ||
export { getStaticPaths, getStaticProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { productName } from 'data/metadata'; | ||
import DocsPage from 'components/docs-page'; | ||
// Imports below are only used server-side | ||
import { getStaticGenerationFunctions } from '@hashicorp/react-docs-page/server'; | ||
import path from 'path'; | ||
import { rehypePlugins, remarkPlugins } from 'lib/remark-rehype-plugins'; | ||
import { remarkRewriteAssets } from 'lib/remark-rewrite-assets'; | ||
// Configure the docs path | ||
const BASE_ROUTE = 'cloud-docs/agents'; | ||
const NAV_DATA_PREFIX = 'cloud-docs-agents'; | ||
const NAV_DATA = path.join( | ||
process.env.NAV_DATA_DIRNAME, | ||
NAV_DATA_PREFIX + '-nav-data.json', | ||
); | ||
// const CONTENT_DIR = 'content/cloud-docs/agents' | ||
const CONTENT_DIR = path.join(process.env.CONTENT_DIRNAME, BASE_ROUTE); | ||
const PRODUCT = { name: productName, slug: 'terraform' } as const; | ||
const SOURCE_REPO = 'terraform-docs-agents'; | ||
const DEFAULT_BRANCH = 'main'; | ||
const PROJECT_NAME = 'Terraform Cloud Agents'; | ||
export default function CloudDocsAgentsLayout(props) { | ||
// append additional nav data | ||
const modifiedProps = Object.assign({}, props); | ||
modifiedProps.navData = modifiedProps.navData.concat([ | ||
{ divider: true }, | ||
{ title: 'Terraform Cloud', href: '/cloud-docs' }, | ||
{ title: 'Terraform Enterprise', href: '/enterprise' }, | ||
]); | ||
return ( | ||
<DocsPage | ||
baseRoute={BASE_ROUTE} | ||
product={PRODUCT} | ||
staticProps={modifiedProps} | ||
projectName={PROJECT_NAME} | ||
showVersionSelect | ||
/> | ||
); | ||
} | ||
const { getStaticPaths, getStaticProps } = getStaticGenerationFunctions( | ||
process.env.IS_CONTENT_PREVIEW && | ||
process.env.PREVIEW_FROM_REPO === SOURCE_REPO | ||
? { | ||
strategy: 'fs', | ||
localContentDir: CONTENT_DIR, | ||
navDataFile: NAV_DATA, | ||
product: SOURCE_REPO, | ||
githubFileUrl(filepath) { | ||
// This path rewriting is meant for local preview from `terraform`. | ||
filepath = filepath.replace('preview/', ''); | ||
return `https://github.com/hashicorp/${SOURCE_REPO}/blob/${DEFAULT_BRANCH}/website/${filepath}`; | ||
}, | ||
remarkPlugins: (params) => [ | ||
...remarkPlugins, | ||
remarkRewriteAssets({ | ||
product: SOURCE_REPO, | ||
version: process.env.CURRENT_GIT_BRANCH, | ||
getAssetPathParts: (nodeUrl) => ['website', nodeUrl], | ||
}), | ||
], | ||
rehypePlugins, | ||
} | ||
: { | ||
fallback: 'blocking', | ||
revalidate: 3600, | ||
strategy: 'remote', | ||
basePath: BASE_ROUTE, | ||
navDataPrefix: NAV_DATA_PREFIX, | ||
product: SOURCE_REPO, | ||
remarkPlugins, | ||
rehypePlugins, | ||
enabledVersionedDocs: true, | ||
}, | ||
); | ||
export { getStaticPaths, getStaticProps }; |