diff --git a/components/article/ArticlePage.tsx b/components/article/ArticlePage.tsx index 316543a683..73c25d61c4 100644 --- a/components/article/ArticlePage.tsx +++ b/components/article/ArticlePage.tsx @@ -1,6 +1,6 @@ import { useRouter } from 'next/router' import cx from 'classnames' -import { Heading } from '@primer/components' +import { ActionList, Heading } from '@primer/components' import { ZapIcon, InfoIcon, ShieldLockIcon } from '@primer/octicons-react' import { Callout } from 'components/ui/Callout' @@ -45,12 +45,19 @@ export const ArticlePage = () => { const renderTocItem = (item: MiniTocItem) => { return ( -
  • -
    - {item.items && item.items.length > 0 ? ( - - ) : null} -
  • + +
    + {item.title} + {item.items && item.items.length > 0 ? ( + + ) : null} +
    +
    ) } @@ -111,13 +118,18 @@ export const ArticlePage = () => { {miniTocItems.length > 1 && ( <> - - {t('miniToc')} - + {t('miniToc')} - + + { + return { + key: title, + text: title, + renderItem: () => , + } + })} + /> )} diff --git a/components/context/ArticleContext.tsx b/components/context/ArticleContext.tsx index 21160819ee..be8a245804 100644 --- a/components/context/ArticleContext.tsx +++ b/components/context/ArticleContext.tsx @@ -9,7 +9,8 @@ export type LearningTrack = { export type MiniTocItem = { platform: string - contents: string + title: string + link: string items?: MiniTocItem[] } diff --git a/components/landing/CodeExampleCard.tsx b/components/landing/CodeExampleCard.tsx index dababb9d7a..d80aa495df 100644 --- a/components/landing/CodeExampleCard.tsx +++ b/components/landing/CodeExampleCard.tsx @@ -1,6 +1,7 @@ import { RepoIcon } from '@primer/octicons-react' import { CodeExample } from 'components/context/ProductLandingContext' import { TruncateLines } from 'components/ui/TruncateLines' +import { Label } from '@primer/components' type Props = { example: CodeExample @@ -21,12 +22,9 @@ export const CodeExampleCard = ({ example }: Props) => {
    {example.tags.map((tag) => { return ( - + + ) })}
    diff --git a/components/sublanding/ArticleCard.tsx b/components/sublanding/ArticleCard.tsx index 5e0f5c0644..3b48f5f5fe 100644 --- a/components/sublanding/ArticleCard.tsx +++ b/components/sublanding/ArticleCard.tsx @@ -1,4 +1,5 @@ import { ArticleGuide } from 'components/context/ProductSubLandingContext' +import { Label } from '@primer/components' type Props = { card: ArticleGuide @@ -18,13 +19,14 @@ export const ArticleCard = ({ card, typeLabel }: Props) => {
    {card.topics.map((topic) => { return ( - {topic} - + ) })}
    diff --git a/lib/get-mini-toc-items.js b/lib/get-mini-toc-items.js index dd17bd8cd8..c2ce162575 100644 --- a/lib/get-mini-toc-items.js +++ b/lib/get-mini-toc-items.js @@ -12,7 +12,7 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope // return an array of objects containing each heading's contents, level, and optional platform. // Article layout uses these as follows: - // - `contents` to render the mini TOC headings + // - `title` and `link` to render the mini TOC headings // - `headingLevel` the `2` in `h2`; used for determining required indentation // - `platform` to show or hide platform-specific headings via client JS @@ -38,7 +38,8 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope // remove any tags but leave content $('strong', item).map((i, el) => $(el).replaceWith($(el).contents())) - const contents = `${$(item).html()}` + const link = href + const title = $(item).html() const headingLevel = parseInt($(item)[0].name.match(/\d+/)[0], 10) || 0 // the `2` from `h2` const platform = $(item).parent('.extended-markdown').attr('class') || '' @@ -48,7 +49,7 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope mostImportantHeadingLevel = headingLevel } - return { contents, headingLevel, platform } + return { link, title, headingLevel, platform } }) .map((item) => { // set the indentation level for each item based on the most important diff --git a/tests/rendering/server.js b/tests/rendering/server.js index 95a3f80e0f..8e63c21602 100644 --- a/tests/rendering/server.js +++ b/tests/rendering/server.js @@ -328,7 +328,7 @@ describe('server', () => { test('renders mini TOC in articles with more than one heading', async () => { const $ = await getDOM('/en/github/getting-started-with-github/githubs-products') expect($('h2#in-this-article').length).toBe(1) - expect($('h2#in-this-article + ul li a').length).toBeGreaterThan(1) + expect($('h2#in-this-article + div div ul').length).toBeGreaterThan(1) }) test('renders mini TOC in articles that includes h3s when specified by frontmatter', async () => { @@ -336,8 +336,8 @@ describe('server', () => { '/en/admin/policies/enforcing-policies-for-your-enterprise/enforcing-policies-for-security-settings-in-your-enterprise' ) expect($('h2#in-this-article').length).toBe(1) - expect($('h2#in-this-article + ul li').length).toBeGreaterThan(0) // non-indented items - expect($('h2#in-this-article + ul li ul.ml-3').length).toBeGreaterThan(0) // indented items + expect($('h2#in-this-article + div div ul').length).toBeGreaterThan(0) // non-indented items + expect($('h2#in-this-article + div div ul a div div div ul.ml-3').length).toBeGreaterThan(0) // indented items }) test('does not render mini TOC in articles with only one heading', async () => { @@ -361,14 +361,14 @@ describe('server', () => { const $ = await getDOM( '/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates' ) - expect($('h2#in-this-article + ul li a[href="#package-ecosystem"]').length).toBe(1) + expect($('h2#in-this-article + div div ul a[href="#package-ecosystem"]').length).toBe(1) }) test('renders mini TOC with correct links when headings contain markup in localized content', async () => { const $ = await getDOM( '/ja/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates' ) - expect($('h2#in-this-article + ul li a[href="#package-ecosystem"]').length).toBe(1) + expect($('h2#in-this-article + div div ul a[href="#package-ecosystem"]').length).toBe(1) }) }) @@ -878,9 +878,15 @@ describe('extended Markdown', () => { test('renders expected mini TOC headings in platform-specific content', async () => { const $ = await getDOM('/en/github/using-git/associating-text-editors-with-git') expect($('h2#in-this-article').length).toBe(1) - expect($('h2#in-this-article + ul li.extended-markdown.mac').length).toBeGreaterThan(1) - expect($('h2#in-this-article + ul li.extended-markdown.windows').length).toBeGreaterThan(1) - expect($('h2#in-this-article + ul li.extended-markdown.linux').length).toBeGreaterThan(1) + expect( + $('h2#in-this-article + div div ul a div div div.extended-markdown.mac').length + ).toBeGreaterThan(1) + expect( + $('h2#in-this-article + div div ul a div div div.extended-markdown.windows').length + ).toBeGreaterThan(1) + expect( + $('h2#in-this-article + div div ul a div div div.extended-markdown.linux').length + ).toBeGreaterThan(1) }) })