Skip to content

Commit

Permalink
Merge pull request #15 from DmytroHryshyn/next/13/pages-to-app/app/cl…
Browse files Browse the repository at this point in the history
…oud-docs-yss-h126u5v58nlxdnhobn0n-rc

next/13/pages-to-app/app/cloud-docs
  • Loading branch information
DmytroHryshyn authored Apr 24, 2023
2 parents ef04974 + c5f15ee commit 5418c3e
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
65 changes: 65 additions & 0 deletions app/cloud-docs/[[...page]]/page.tsx
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 };
74 changes: 74 additions & 0 deletions app/cloud-docs/agents/[[...page]]/page.tsx
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 };

0 comments on commit 5418c3e

Please sign in to comment.