@primer/doctocat-nextjs 0.5.3-rc.1ab2f8f → 0.5.3-rc.b406f16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,8 +6,6 @@
6
6
 
7
7
  - [#43](https://github.com/primer/doctocat-nextjs/pull/43) [`1b15bdf`](https://github.com/primer/doctocat-nextjs/commit/1b15bdfcf4b54996f38d20f1da711def23c636bd) Thanks [@rezrah](https://github.com/rezrah)! - Fix lack of `basePath` support on index cards. `href` now prepends the `basePath`.
8
8
 
9
- - [#46](https://github.com/primer/doctocat-nextjs/pull/46) [`2b99ba6`](https://github.com/primer/doctocat-nextjs/commit/2b99ba614d1bfe8f1c478b10a61c52df479901c9) Thanks [@rezrah](https://github.com/rezrah)! - Prepend `basePath` from `next.config.js` to paths in Doctocat UI components, where it would previously not resolve correctly.
10
-
11
9
  ## 0.5.2
12
10
 
13
11
  ### Patch Changes
@@ -10,7 +10,6 @@ export type ConfigContextLink = {
10
10
  export type ConfigContextValue = {
11
11
  headerLinks: ConfigContextLink[]
12
12
  sidebarLinks: ConfigContextLink[]
13
- basePath: string
14
13
  }
15
14
 
16
15
  export const ConfigContext = createContext<ConfigContextValue | null>(null)
@@ -1,38 +1,42 @@
1
1
  .Article {
2
2
  display: grid;
3
- grid-template-areas: 'main';
4
- grid-template-columns: 1fr;
5
3
  }
6
4
 
7
5
  .Article--withToc {
8
6
  gap: var(--base-size-48);
9
- grid-template-areas: 'main aside';
10
- grid-template-columns: 1fr 200px;
11
7
  }
12
8
 
13
9
  .main {
14
- grid-area: main;
15
- max-width: 100%;
16
- overflow-x: hidden;
10
+ order: 1;
17
11
  }
18
12
 
19
13
  .aside {
20
- grid-area: aside;
21
- position: relative;
14
+ order: 0;
22
15
  }
23
16
 
24
- @media screen and (max-width: 1023px) {
17
+ @media screen and (max-width: 48rem) {
25
18
  .Article--withToc {
26
- grid-template-areas:
27
- 'aside'
28
- 'main';
29
- grid-template-columns: 1fr;
19
+ display: flex; /* Prevents column overflow */
20
+ flex-direction: column;
21
+ }
22
+ }
23
+
24
+ @media screen and (min-width: 1023px) {
25
+ .main {
26
+ order: 0;
27
+ }
28
+
29
+ .aside {
30
+ order: 1;
31
+ }
32
+
33
+ .Article--withToc {
34
+ grid-template-columns: 1fr 200px;
30
35
  }
31
36
  }
32
37
 
33
38
  @media screen and (min-width: 2048px) {
34
39
  .Article--withToc {
35
- grid-template-areas: 'main';
36
40
  grid-template-columns: 1fr;
37
41
  }
38
42
  }
@@ -3,14 +3,12 @@ import React, {PropsWithChildren, useCallback, useState} from 'react'
3
3
  import clsx from 'clsx'
4
4
  import {LiveProvider, LiveEditor, LiveError, LivePreview} from 'react-live'
5
5
  import {useColorMode} from '../../context/color-modes/useColorMode'
6
- import {useConfig} from '../../context/useConfig'
7
6
  import styles from './ReactCodeBlock.module.css'
8
7
  import {ActionBar, Button, ThemeProvider} from '@primer/react'
9
8
  import {CopyIcon, MoonIcon, SunIcon, UndoIcon} from '@primer/octicons-react'
10
9
  import {colorModes} from '../../context/color-modes/context'
11
10
 
12
11
  import {lightTheme, darkTheme} from './syntax-highlighting-themes'
13
- import {codeTransformer} from './code-transformer'
14
12
 
15
13
  type ReactCodeBlockProps = {
16
14
  'data-language': string
@@ -20,19 +18,10 @@ type ReactCodeBlockProps = {
20
18
 
21
19
  export function ReactCodeBlock(props: ReactCodeBlockProps) {
22
20
  const {colorMode, setColorMode} = useColorMode()
23
- const {basePath} = useConfig()
24
21
  const initialCode = getCodeFromChildren(props.children)
25
22
  const [code, setCode] = useState(initialCode)
26
23
  const shouldShowPreview = ['tsx', 'jsx'].includes(props['data-language'])
27
24
 
28
- /**
29
- * Transforms code to prepend basePath to img src attributes
30
- */
31
- const transformCodeWithBasePath = useCallback(
32
- (sourceCode: string) => codeTransformer(sourceCode, basePath),
33
- [basePath],
34
- )
35
-
36
25
  const handleReset = useCallback(() => {
37
26
  setCode(initialCode)
38
27
  }, [initialCode, setCode])
@@ -45,7 +34,7 @@ export function ReactCodeBlock(props: ReactCodeBlockProps) {
45
34
 
46
35
  return (
47
36
  <>
48
- <LiveProvider transformCode={transformCodeWithBasePath} code={code} scope={props.jsxScope} noInline={noInline}>
37
+ <LiveProvider code={code} scope={props.jsxScope} noInline={noInline}>
49
38
  <div className={clsx(styles.CodeBlock, 'custom-component')}>
50
39
  {shouldShowPreview && (
51
40
  <div>
@@ -18,7 +18,6 @@ import placeholderLightFiveThumb from './images/light-5.png'
18
18
  import placeholderLightSixThumb from './images/light-6.png'
19
19
 
20
20
  import styles from './IndexCards.module.css'
21
- import {useConfig} from '../../context/useConfig'
22
21
 
23
22
  type IndexCardsProps = {
24
23
  route: string
@@ -44,7 +43,6 @@ const lightModePlaceholderThumbs = [
44
43
  ] as unknown as StaticImageData[]
45
44
 
46
45
  export function IndexCards({route, folderData}: IndexCardsProps) {
47
- const {basePath} = useConfig()
48
46
  const lastPlaceholderIndexRef = useRef<number>(-1)
49
47
  // We don't want to show children of these pages. E.g. tabbed pages
50
48
  const onlyDirectChildren = folderData.filter(item => {
@@ -88,16 +86,13 @@ export function IndexCards({route, folderData}: IndexCardsProps) {
88
86
 
89
87
  const thumbnailUrl =
90
88
  colorMode === 'dark'
91
- ? (item.frontMatter.thumbnail_darkMode
92
- ? `${basePath || ''}${item.frontMatter.thumbnail_darkMode}`
93
- : null) || getNextPlaceholderIndex(darkModePlaceholderThumbs).src
94
- : (item.frontMatter.thumbnail ? `${basePath || ''}${item.frontMatter.thumbnail}` : null) ||
95
- getNextPlaceholderIndex(lightModePlaceholderThumbs).src
89
+ ? item.frontMatter.thumbnail_darkMode || getNextPlaceholderIndex(darkModePlaceholderThumbs).src
90
+ : item.frontMatter.thumbnail || getNextPlaceholderIndex(lightModePlaceholderThumbs).src
96
91
 
97
92
  return (
98
93
  <Grid.Column span={{xsmall: 12, small: 12, medium: 12, large: 6, xlarge: 4}} key={item.frontMatter.title}>
99
94
  <Link legacyBehavior passHref href={item.route}>
100
- <Card href="#" hasBorder fullWidth>
95
+ <Card href="#" hasBorder>
101
96
  <Card.Image src={thumbnailUrl} alt="" aspectRatio="4:3" />
102
97
  <Card.Heading>{item.frontMatter.title}</Card.Heading>
103
98
  {item.frontMatter.description && <Card.Description>{item.frontMatter.description}</Card.Description>}
@@ -25,7 +25,6 @@ export default function Shell({children, headerLinks = [], sidebarLinks = [], ..
25
25
  value={{
26
26
  headerLinks,
27
27
  sidebarLinks,
28
- basePath: process.env.NEXT_PUBLIC_DOCTOCAT_BASE_PATH || '',
29
28
  }}
30
29
  >
31
30
  <Theme {...rest}>{children}</Theme>
@@ -26,6 +26,7 @@
26
26
  display: flex;
27
27
  flex-direction: column;
28
28
  min-width: 280px;
29
+ right: 0;
29
30
  overflow: auto;
30
31
  padding: var(--base-size-40) var(--base-size-40) var(--base-size-40) 0;
31
32
  top: 65px;
package/css/global.css CHANGED
@@ -18,8 +18,7 @@ body {
18
18
  margin-block-start: 0 !important;
19
19
  }
20
20
 
21
- /* Pre styles are scoped to Nextra code blocks to prevent unintended styling of other code blocks (e.g., ReactCodeBlock previews). */
22
- .nextra-code pre {
21
+ pre {
23
22
  background-color: var(--brand-color-canvas-subtle);
24
23
  border-radius: var(--brand-borderRadius-large);
25
24
  padding-top: 1rem;
@@ -10,7 +10,7 @@ const withNextra = nextra({
10
10
  * Relies on `transpilePackages: ['@primer/doctocat-nextjs'],` being set in the next.config
11
11
  */
12
12
  function withDoctocat(config = {}) {
13
- const finalConfig = {
13
+ return {
14
14
  ...withNextra(),
15
15
  images: {
16
16
  unoptimized: true,
@@ -18,13 +18,6 @@ function withDoctocat(config = {}) {
18
18
 
19
19
  ...config,
20
20
  }
21
-
22
- // Enables basePath in next.config.js to be used inside Doctocat
23
- if (finalConfig.basePath) {
24
- process.env.NEXT_PUBLIC_DOCTOCAT_BASE_PATH = finalConfig.basePath
25
- }
26
-
27
- return finalConfig
28
21
  }
29
22
 
30
23
  export default withDoctocat
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/doctocat-nextjs",
3
- "version": "0.5.3-rc.1ab2f8f",
3
+ "version": "0.5.3-rc.b406f16",
4
4
  "description": "A Next.js theme for building Primer documentation sites",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,19 +0,0 @@
1
- export const codeTransformer = (sourceCode: string, basePath: string): string => {
2
- if (!basePath) return sourceCode
3
-
4
- // to skip external URLs and other irrelevant paths
5
- const shouldTransform = (src: string) => !src.startsWith('http') && !src.startsWith('//') && !src.startsWith(basePath)
6
-
7
- // normalise for absolute (/path) and relative (path) values
8
- const transformSrc = (src: string) => (src.startsWith('/') ? `${basePath}${src}` : `${basePath}/${src}`)
9
-
10
- // Assumes all elements with a src attribute are trying to point at Next.js public folder
11
- return sourceCode.replace(
12
- /<(\w+)\s+([^>]*\s+)?src=["']([^"']+)["']([^>]*)/g,
13
- (match, tagName, before = '', src, after) => {
14
- if (!shouldTransform(src)) return match
15
-
16
- return `<${tagName} ${before}src="${transformSrc(src)}"${after}`
17
- },
18
- )
19
- }