Skip to content

Commit

Permalink
HVD: Add product logo, and make TOC h2+ only (#2305)
Browse files Browse the repository at this point in the history
Add product logo, and make TOC h2+ only
  • Loading branch information
RubenSandwich committed Jan 22, 2024
1 parent fdae19e commit 42d318d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/views/validated-designs/guide/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import s from './detail-view.module.css'
import type { HvdPage, HvdPageMenuItem } from '../types'
import type { MDXRemoteSerializeResult } from 'next-mdx-remote'
import type { OutlineLinkItem } from 'components/outline-nav/types'
import { ProductSlug } from 'types/products'

export interface ValidatedDesignsGuideProps {
title: string
productSlug: Exclude<ProductSlug, 'sentinel'>
markdown: {
mdxSource: MDXRemoteSerializeResult
title: string
Expand All @@ -41,6 +43,7 @@ export interface ValidatedDesignsGuideProps {

export default function ValidatedDesignGuideView({
title,
productSlug,
markdown,
headers,
currentPageIndex,
Expand Down Expand Up @@ -103,7 +106,7 @@ export default function ValidatedDesignGuideView({
showResourcesList: false,
children: (
<>
<SidebarSectionBrandedHeading text={title} theme={'hcp'} />
<SidebarSectionBrandedHeading text={title} theme={productSlug} />
<SidebarHorizontalRule />
<SidebarNavList>
{pages.map((page: HvdPageMenuItem, index: number) => (
Expand Down
24 changes: 19 additions & 5 deletions src/views/validated-designs/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import remarkPluginAnchorLinkData, {
import { rewriteStaticHVDAssetsPlugin } from 'lib/remark-plugins/rewrite-static-hvd-assets'
import grayMatter from 'gray-matter'
import { ProductSlug } from 'types/products'
import { OutlineLinkItem } from 'components/outline-nav/types'

const basePath = '/validated-designs'

Expand Down Expand Up @@ -189,6 +190,7 @@ export async function getHvdGuidePropsFromSlug(

const validatedDesignsGuideProps: ValidatedDesignsGuideProps = {
title: '',
productSlug: 'hcp', // default to hcp
markdown: {
description: '',
title: '',
Expand All @@ -203,6 +205,8 @@ export async function getHvdGuidePropsFromSlug(
for (const categoryGroup of categoryGroups) {
for (const guide of categoryGroup.guides) {
if (guide.slug === guideSlug) {
validatedDesignsGuideProps.productSlug = categoryGroup.product

for (let index = 0; index < guide.pages.length; index++) {
const page = guide.pages[index]

Expand All @@ -212,7 +216,6 @@ export async function getHvdGuidePropsFromSlug(

let mdxFileString: string
try {
// TODO: this should be guarded with a try catch
mdxFileString = fs.readFileSync(page.filePath, 'utf8')
} catch (err) {
console.error(err)
Expand All @@ -231,10 +234,21 @@ export async function getHvdGuidePropsFromSlug(
},
})

const headers = anchorLinks.map((anchorLink: AnchorLinkItem) => ({
title: anchorLink.title,
url: `#${anchorLink.id}`,
}))
// only show heading level 1 & 2
const headers = anchorLinks.reduce(
(acc: OutlineLinkItem[], anchorLink: AnchorLinkItem) => {
if (anchorLink.level < 3) {
acc.push({
title: anchorLink.title,
url: `#${anchorLink.id}`,
})
}

return acc
},
[]
)

validatedDesignsGuideProps.headers = headers
validatedDesignsGuideProps.markdown = {
// this is temporary as we should always have these fields in the markdown
Expand Down

1 comment on commit 42d318d

@vercel
Copy link

@vercel vercel bot commented on 42d318d Jan 22, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.