Skip to content

Commit 260f0a1

Browse files
authored
Add a "view page as markdown" button (#58578)
1 parent 2bdb367 commit 260f0a1

7 files changed

Lines changed: 60 additions & 1 deletion

File tree

data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pages:
9898
about_versions: About versions
9999
permissions_callout_title: Who can use this feature?
100100
video_from_transcript: See video for this transcript
101+
view_page_as_markdown: View page as Markdown
101102
support:
102103
still_need_help: Still need help?
103104
contact_support: Contact support

src/fixtures/fixtures/data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pages:
9898
about_versions: About versions
9999
permissions_callout_title: Who can use this feature?
100100
video_from_transcript: See video for this transcript
101+
view_page_as_markdown: View page as Markdown
101102
support:
102103
still_need_help: Still need help?
103104
contact_support: Contact support

src/frame/components/article/ArticlePage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useTranslation } from '@/languages/components/useTranslation'
2323
import { LinkPreviewPopover } from '@/links/components/LinkPreviewPopover'
2424
import { UtmPreserver } from '@/frame/components/UtmPreserver'
2525
import { JourneyTrackCard, JourneyTrackNav } from '@/journeys/components'
26+
import { ViewMarkdownButton } from './ViewMarkdownButton'
2627

2728
const ClientSideRefresh = dynamic(() => import('@/frame/components/ClientSideRefresh'), {
2829
ssr: false,
@@ -46,6 +47,7 @@ export const ArticlePage = () => {
4647
currentJourneyTrack,
4748
supportPortalVaIframeProps,
4849
currentLayout,
50+
currentPath,
4951
} = useArticleContext()
5052
const isLearningPath = !!currentLearningTrack?.trackName
5153
const isJourneyTrack = !!currentJourneyTrack?.trackId
@@ -74,6 +76,7 @@ export const ArticlePage = () => {
7476

7577
const toc = (
7678
<>
79+
<ViewMarkdownButton currentPath={currentPath} />
7780
{isLearningPath && <LearningTrackCard track={currentLearningTrack} />}
7881
{isJourneyTrack && <JourneyTrackCard journey={currentJourneyTrack} />}
7982
{miniTocItems.length > 1 && <MiniTocs miniTocItems={miniTocItems} />}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.button {
2+
font-size: 12px;
3+
padding: 4px 8px;
4+
border-color: #d1d9e0;
5+
background-color: transparent;
6+
border-radius: 6px;
7+
cursor: pointer;
8+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { FileIcon } from '@primer/octicons-react'
2+
import { Button } from '@primer/react'
3+
import { sendEvent } from '@/events/components/events'
4+
import { EventType } from '@/events/types'
5+
import { useTranslation } from '@/languages/components/useTranslation'
6+
import cx from 'classnames'
7+
import styles from './ViewMarkdownButton.module.scss'
8+
9+
interface ViewMarkdownButtonProps {
10+
currentPath: string
11+
}
12+
13+
export const ViewMarkdownButton = ({ currentPath }: ViewMarkdownButtonProps) => {
14+
const { t } = useTranslation('pages')
15+
16+
const encodedPath = encodeURIComponent(currentPath).replace(/%2F/g, '/').replace(/%40/g, '@')
17+
const markdownUrl = `/api/article/body?pathname=${encodedPath}`
18+
19+
const handleClick = () => {
20+
sendEvent({
21+
type: EventType.link,
22+
link_url: markdownUrl,
23+
link_samesite: false,
24+
link_container: 'view-markdown-button',
25+
})
26+
window.open(markdownUrl, '_blank')
27+
}
28+
29+
return (
30+
<div className="mb-3 ml-3">
31+
<Button
32+
onClick={handleClick}
33+
variant="default"
34+
className={cx(
35+
'd-inline-flex flex-items-center border text-decoration-none color-fg-default',
36+
styles.button,
37+
)}
38+
aria-label={t('view_page_as_markdown')}
39+
>
40+
<FileIcon size={12} className="mr-1" aria-hidden="true" />
41+
{t('view_page_as_markdown')}
42+
</Button>
43+
</div>
44+
)
45+
}

src/frame/components/context/ArticleContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type ArticleContextT = {
4242
allTools: Record<string, string>
4343
supportPortalVaIframeProps: SupportPortalVaIframeProps
4444
currentLayout?: string
45+
currentPath: string
4546
}
4647

4748
export const ArticleContext = createContext<ArticleContextT | null>(null)
@@ -107,5 +108,6 @@ export const getArticleContextFromRequest = (req: any): ArticleContextT => {
107108
allTools: page.allToolsParsed || [], // this is set at the page level, see lib/page.ts
108109
supportPortalVaIframeProps,
109110
currentLayout: req.context.currentLayoutName,
111+
currentPath: req.context.currentPath || '',
110112
}
111113
}

src/workflows/ready-for-docs-review.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
21
import { graphql } from '@octokit/graphql'
32

43
import {

0 commit comments

Comments
 (0)