Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
813dfae
WIP initial refactor of DocsSidenav
zchsh Feb 25, 2021
8bc3213
Reorder props for clearer diff
zchsh Feb 25, 2021
756e163
Add back useProductMeta
zchsh Feb 25, 2021
455b8cc
Test out npx-based approach to migration script
zchsh Feb 25, 2021
644398e
Remove devdeps, not useful
zchsh Feb 25, 2021
8620fb5
Update comment
zchsh Feb 25, 2021
87bc56c
Fix issue with direct links
zchsh Feb 25, 2021
a6ca716
Refine DocsPage props API
zchsh Feb 25, 2021
d138f52
Update comment
zchsh Feb 25, 2021
c53eb2c
Add todo
zchsh Feb 25, 2021
231ed1d
Begin cleanup
zchsh Feb 26, 2021
4cd6b44
Fix up docs
zchsh Feb 26, 2021
dd7231e
Lerna please recognize that I've changed DocsSidenav
zchsh Feb 26, 2021
e0d6721
Bump docs-sidenav prerelease in DocsPage
zchsh Feb 26, 2021
00e0902
Pull in DocsPage server changes from Packer work
zchsh Feb 26, 2021
9f7a9e7
Pull in server work from Packer
zchsh Feb 26, 2021
60f6395
Fix issue with undefined default options object
zchsh Feb 26, 2021
1d7ee19
Change generateStaticPaths args for consistency
zchsh Feb 26, 2021
6d70cd3
Add content hook to allow modification of mdxString
zchsh Feb 26, 2021
db0e6f4
Delete reference file
zchsh Mar 4, 2021
5eff596
Add comment on productName arg
zchsh Mar 4, 2021
a794e0d
Use shared product slug prop
zchsh Mar 4, 2021
9785ada
Continue cleanup, update props specs
zchsh Mar 4, 2021
8b3f2f3
Nit to cleanup diff
zchsh Mar 4, 2021
e41cef7
Continue refining docs
zchsh Mar 4, 2021
7896cb4
Update readme
zchsh Mar 4, 2021
1ad98f6
Add comments, esp on migration script
zchsh Mar 4, 2021
62f36be
Implement highlighting of internal direct links
zchsh Mar 4, 2021
caed62f
Add further static validation of nav-data
zchsh Mar 4, 2021
45a6b73
Add clarifying comment
zchsh Mar 4, 2021
8d9b087
Remove console.log
zchsh Mar 4, 2021
fb2d4b8
Bump docs-sidenav in docs-page
zchsh Mar 4, 2021
84cf7ef
Plan out tests
zchsh Mar 4, 2021
42132c1
Update package-lock after fresh npm i & bootstrap
zchsh Mar 5, 2021
30bb2f2
Add tests for validate-file-paths
zchsh Mar 5, 2021
aacb8ff
Add tests for validate-route-structure
zchsh Mar 5, 2021
def68bc
Add tests for docs-sidenav
zchsh Mar 5, 2021
e9ffac9
Add reference file for docs-page
zchsh Mar 5, 2021
e9e8a66
A11y improvements, and split out utilities for clarity
zchsh Mar 5, 2021
9014586
Clean up comment
zchsh Mar 5, 2021
88965e3
Add tests for docs-page
zchsh Mar 6, 2021
30a45bf
Update DocsPage dep in GlossaryPage
zchsh Mar 6, 2021
2955bb9
Delete stale dev files
zchsh Mar 6, 2021
9f50a4d
Replace mainBranch prop with githubFileUrl
zchsh Mar 6, 2021
1a1d5d0
Fix issue with githubFileUrl
zchsh Mar 6, 2021
9c781fd
Bump content dep, glossary-page dep
zchsh Mar 6, 2021
dcc0280
Revert useless changes to package.jsons
zchsh Mar 6, 2021
38eb643
Remove unused imports
zchsh Mar 6, 2021
1944c79
Add delete fm script to docs-sidenav
zchsh Mar 6, 2021
6c09a1c
Fix issue with extra arg
zchsh Mar 6, 2021
4688cc9
Update comment
zchsh Mar 6, 2021
9c9cbc6
Remote outdated comment
zchsh Mar 6, 2021
132e9c9
Fix updated test value
zchsh Mar 6, 2021
0cd39d4
Bump docs-sidenav in docs-page
zchsh Mar 6, 2021
96bd152
Bump docs-page in glossary-page
zchsh Mar 6, 2021
661bbb3
Fix glossary-page β€œEdit this page” link
zchsh Mar 7, 2021
8d8092c
Fix issue with navData direct link edge case, add related test
zchsh Mar 8, 2021
36b794f
Bump docs-sidenav in docs-page
zchsh Mar 8, 2021
d860d4d
Bump docs-page in glossary-page
zchsh Mar 8, 2021
0102034
Add LICENSE to glossary-page
zchsh Mar 8, 2021
9ab4d62
Rm migration scripts from docs-sidenav, moving to mktg-codemods repo
zchsh Mar 8, 2021
89f85ae
Update tests to avoid unstable parentNode selection
zchsh Mar 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"dotenv": "^8.2.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed dotenv to run tests in docs-page that relied on ALGOLIA env for Search.

"eslint": "^7.18.0",
"husky": "^4.3.8",
"identity-obj-proxy": "^3.0.0",
Expand Down
41 changes: 22 additions & 19 deletions packages/docs-page/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
# DocsPage

The **DocsPage** component lets you create a Hashicorp branded docs page in NextJS projects using `next-mdx-remote`. This is a very highly abstracted component with slightly more involved usage since it renders an entire page.
The **DocsPage** component lets you create a Hashicorp branded docs page in NextJS projects using `next-mdx-remote`. This is a very highly abstracted component with slightly more involved usage since it renders an entire collection of pages.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the plain ol README, just keeping the same gist of the old content but with the new API.


## Example Usage

This component is intended to be used on an [optional catch-all route](https://nextjs.org/docs/routing/dynamic-routes#optional-catch-all-routes) page, like `pages/docs/[[slug]].mdx` - example source shown below:
This component is intended to be used on an [optional catch-all route](https://nextjs.org/docs/routing/dynamic-routes#optional-catch-all-routes) page, like `pages/docs/[[...page]].mdx` - example source shown below:

```js
import order from 'data/docs-navigation.js'
```jsx
import DocsPage from '@hashicorp/react-docs-page'
// Imports below are only used server-side
import {
generateStaticPaths,
generateStaticProps,
} from '@hashicorp/react-docs-page/server'

const productName = 'Vault'
const productSlug = 'vault'
// this example is at `pages/docs/[[slug]].mdx` - if the path is different
// this 'subpath' prop should be adjusted to match
const subpath = 'docs'
// Set up DocsPage settings
const BASE_ROUTE = 'docs'
const NAV_DATA = 'data/docs-nav-data.json'
const CONTENT_DIR = 'content/docs'
const PRODUCT = {
name: 'Packer',
slug: 'packer',
}

function DocsLayout(props) {
return (
<DocsPage
productName={productName}
productSlug={productSlug}
subpath={subpath}
order={order}
showEditPage={true}
staticProps={props}
/>
<DocsPage baseRoute={BASE_ROUTE} product={PRODUCT} staticProps={props} />
)
}

export async function getStaticPaths() {
return generateStaticPaths(subpath)
const paths = await generateStaticPaths(NAV_DATA, CONTENT_DIR)
return { paths, fallback: false }
}

export async function getStaticProps({ params }) {
return generateStaticProps({ subpath, productName, params })
const props = await generateStaticProps(
NAV_DATA,
CONTENT_DIR,
params,
PRODUCT
)
return { props }
}

export default DocsLayout
Expand Down
61 changes: 13 additions & 48 deletions packages/docs-page/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,24 @@ We have a lot of docs sites, all of which render content in exactly the same way
<LiveComponent
components={{
staticPropsResult: {
mdxSource: {
compiledSource:
'"use strict";\n' +
'\n' +
'function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n' +
'\n' +
'function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n' +
'\n' +
'function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n' +
'\n' +
'/* @jsxRuntime classic */\n' +
'\n' +
'/* @jsx mdx */\n' +
'var layoutProps = {};\n' +
'var MDXLayout = "wrapper";\n' +
'\n' +
'function MDXContent(_ref) {\n' +
' var components = _ref.components,\n' +
' props = _objectWithoutProperties(_ref, ["components"]);\n' +
'\n' +
' return mdx(MDXLayout, _extends({}, layoutProps, props, {\n' +
' components: components,\n' +
' mdxType: "MDXLayout"\n' +
' }), mdx("h1", { className: "g-type-display-2" }, "Example Page"), mdx("p", null, "This is a cool docs page!"));\n' +
'}\n' +
'\n' +
';\n' +
'MDXContent.isMDXComponent = true;',
renderedOutput:
'<h1 className="g-type-display-2">Example Page</h1><p>This is a cool docs page!</p>',
scope: {},
mdxSource: componentProps.staticProps.properties.mdxSource.testValue,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pulling testValues from props here - would be nice to have access to swingset's getTestValues - Have added a task to the platform board to capture that need slash discuss whether it feels like a worthwhile addition to swingset.

frontMatter: {
page_title:
componentProps.staticProps.properties.frontMatter.properties
.page_title.testValue,
description:
componentProps.staticProps.properties.frontMatter.properties
.description.testValue,
},
data: [
{
__resourcePath: 'docs/test.mdx',
page_title: 'Testing Page',
sidebar_title: 'Testing Page',
},
{
__resourcePath: 'docs/test2.mdx',
page_title: 'Other Testing Page',
sidebar_title: 'Other Testing Page',
},
],
frontMatter: { page_title: 'Test Page', description: 'test description' },
pagePath: '/docs/test',
filePath: 'test.mdx',
githubFileUrl:
componentProps.staticProps.properties.githubFileUrl.testValue,
currentPath: componentProps.staticProps.properties.currentPath.testValue,
navData: componentProps.staticProps.properties.navData.testValue,
},
}}
>{`<DocsPage
product={{ name: 'Nomad', slug: 'nomad' }}
subpath='docs'
order={['test', 'test2']}
baseRoute='docs'
// pass in the results of executing the 'generateStaticProps' function from '@hashicorp/react-docs-page/server'
staticProps={staticPropsResult}
>
Expand Down
39 changes: 14 additions & 25 deletions packages/docs-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ import Content from '@hashicorp/react-content'
import DocsSidenav from '@hashicorp/react-docs-sidenav'
import HashiHead from '@hashicorp/react-head'
import Head from 'next/head'
import Link from 'next/link'
import hydrate from 'next-mdx-remote/hydrate'
import { SearchProvider } from '@hashicorp/react-search'
import SearchBar from './search-bar'
import generateComponents from './components'
import temporary_injectJumpToSection from './temporary_jump-to-section'

export function DocsPageWrapper({
allPageData,
canonicalUrl,
children,
description,
filePath,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filePath has been removed - it's no longer needed, as filepath validation now happens in server-side functions.

mainBranch = 'main',
order,
pagePath,
navData,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allPageData and order have been replaced by navData.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’―

currentPath,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagePath has been renamed to currentPath - this prop is used to highlight the currently active page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the clarity!

pageTitle,
baseRoute,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseRoute is formerly-known-as subpath. We have a task to consider using router in docs-sidenav to eliminate the need for this prop entirely, but felt a bit much to squish it into this update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think baseRoute makes sense. I'll keep this in mind as I'm using the supbath terminology throughout the versioned docs work.

githubFileUrl,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainBranch has been replaced by githubFileUrl - the latter allows for more flexibility, eg for remote plugin docs we want to link to the remote repo link.

product: { name, slug },
showEditPage = true,
subpath,
}) {
// TEMPORARY (https://app.asana.com/0/1100423001970639/1160656182754009)
// activates the "jump to section" feature
Expand All @@ -49,11 +46,9 @@ export function DocsPageWrapper({
<div className="nav docs-nav">
<DocsSidenav
product={slug}
Link={Link}
category={subpath}
currentPage={pagePath}
data={allPageData}
order={order}
baseRoute={baseRoute}
currentPath={currentPath}
navData={navData}
/>
</div>
</div>
Expand All @@ -75,9 +70,7 @@ export function DocsPageWrapper({
{/* if desired, show an "edit this page" link on the bottom right, linking to github */}
{showEditPage && (
<div id="edit-this-page" className="g-container">
<a
href={`https://github.com/hashicorp/${slug}/blob/${mainBranch}/website/content/${filePath}`}
>
<a href={githubFileUrl}>
<img src={require('./img/github-logo.svg')} alt="github logo" />
<span>Edit this page</span>
</a>
Expand All @@ -89,12 +82,10 @@ export function DocsPageWrapper({

export default function DocsPage({
product,
subpath,
order,
mainBranch = 'main',
baseRoute,
showEditPage = true,
additionalComponents,
staticProps: { mdxSource, data, frontMatter, pagePath, filePath },
staticProps: { mdxSource, frontMatter, currentPath, navData, githubFileUrl },
}) {
// This component is written to work with next-mdx-remote -- here it hydrates the content
const content = hydrate(mdxSource, {
Expand All @@ -103,17 +94,15 @@ export default function DocsPage({

return (
<DocsPageWrapper
allPageData={data}
canonicalUrl={frontMatter.canonical_url}
description={frontMatter.description}
filePath={filePath}
mainBranch={mainBranch}
order={order}
pagePath={pagePath}
githubFileUrl={githubFileUrl}
navData={navData}
currentPath={currentPath}
pageTitle={frontMatter.page_title}
product={product}
showEditPage={showEditPage}
subpath={subpath}
baseRoute={baseRoute}
>
{content}
</DocsPageWrapper>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor is excellent, really clean

Expand Down
Loading