-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sidebar for open-api-docs (#2099)
* chore: enable flags for dev and review * feat: stub in final sidebar and menu contents * fix: mobile menu detect hash changes for anchors * chore: extract extract-hash-slug * chore: remove console.log * refactor: rm extractHashSlug * refactor: generate nav items in getStaticProps * chore: rename type * docs: add comment on MenuItem issue * style: shift code for clarity * fix: icon issue in sidebar highlight item * feat: generate top-level page item * chore: split out newUrl fn to src/lib * docs: add comment to new-url * chore: revert flags for dev and review
- Loading branch information
Showing
13 changed files
with
216 additions
and
36 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
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
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
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,22 @@ | ||
/** | ||
* Given a string, and an _optional_ domain name, | ||
* Return a new URL object built from the string with `new URL()`. | ||
* | ||
* This function is intended as a light wrapper around the URL | ||
* constructor, with the sole purpose of not requiring a domain | ||
* name, and instead supply a default domain name, | ||
* since there are several uses through our codebase where we want | ||
* the functionality and reliability of URL objects, but do not | ||
* have a meaningful domain name to supply. | ||
* | ||
* Note that we use `example.com` here since we do _not_ want to rely | ||
* on a specific domain name value here. If a specific domain name | ||
* is needed, consumers should pass that domain to the `base` argument, | ||
* or use `new URL(url, base)` directly. | ||
*/ | ||
export default function newUrl( | ||
url: string | URL, | ||
base: string | URL = 'https://www.example.com' | ||
): URL { | ||
return new URL(url, base) | ||
} |
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
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
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
6 changes: 6 additions & 0 deletions
6
...n-api-docs-view/components/open-api-sidebar-contents/open-api-sidebar-contents.module.css
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,6 @@ | ||
.listResetStyles { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
} |
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
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
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
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,48 @@ | ||
import { ProductSlug } from 'types/products' | ||
import { OperationGroup, OpenApiNavItem } from '../types' | ||
|
||
/** | ||
* Build nav items for each operation, group-by-group. | ||
*/ | ||
export function getNavItems({ | ||
basePath, | ||
operationGroups, | ||
productSlug, | ||
title, | ||
}: { | ||
basePath: string | ||
operationGroups: OperationGroup[] | ||
productSlug: ProductSlug | ||
title: string | ||
}): OpenApiNavItem[] { | ||
// Build the top-level page nav item | ||
const pageNavItem = { | ||
title, | ||
fullPath: basePath, | ||
theme: productSlug, | ||
} | ||
// Include grouped operation items | ||
const operationGroupItems = getOperationGroupItems(operationGroups) | ||
// Return the full set of nav items | ||
return [pageNavItem, ...operationGroupItems] | ||
} | ||
|
||
/** | ||
* Build nav items for each operation, group-by-group. | ||
*/ | ||
function getOperationGroupItems( | ||
operationGroups: OperationGroup[] | ||
): OpenApiNavItem[] { | ||
const navItems: OpenApiNavItem[] = [] | ||
// Build items for each group | ||
for (const { heading, items } of Object.values(operationGroups)) { | ||
// Start each group with a divider and heading | ||
navItems.push({ divider: true }) | ||
navItems.push({ heading }) | ||
// Then include each group's items | ||
for (const { slug, operationId } of items) { | ||
navItems.push({ title: operationId, fullPath: `#${slug}` }) | ||
} | ||
} | ||
return navItems | ||
} |
Oops, something went wrong.
9c71ee1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dev-portal – ./
dev-portal-hashicorp.vercel.app
dev-portal-git-main-hashicorp.vercel.app
docs.hashicorp.com
developer.hashicorp.com