@primer/doctocat-nextjs 0.0.0-20250620092520 → 0.0.0-20250620095814

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
@@ -1,18 +1,18 @@
1
1
  # @primer/doctocat-nextjs
2
2
 
3
- ## 0.0.0-20250620092520
3
+ ## 0.0.0-20250620095814
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - Fake entry to force publishing
8
8
 
9
- ## 0.0.0-20250620092519
9
+ ## 0.0.0-20250620095812
10
10
 
11
11
  ### Patch Changes
12
12
 
13
13
  - [#43](https://github.com/primer/doctocat-nextjs/pull/43) [`c5542e9`](https://github.com/primer/doctocat-nextjs/commit/c5542e915dc0fbe6e054e8fde96f7136498b9cc7) Thanks [@rezrah](https://github.com/rezrah)! - Fix lack of `basePath` support on index cards. `href` now prepends the `basePath`.
14
14
 
15
- - [`fea58bc`](https://github.com/primer/doctocat-nextjs/commit/fea58bc04c1cfb4897ef8f5921dbc9afd5b18dc8) Thanks [@rezrah](https://github.com/rezrah)! - Prepend basePath to paths in Doctocat UI, where it would previously not resolve correctly.
15
+ - [#46](https://github.com/primer/doctocat-nextjs/pull/46) [`fea58bc`](https://github.com/primer/doctocat-nextjs/commit/fea58bc04c1cfb4897ef8f5921dbc9afd5b18dc8) 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.
16
16
 
17
17
  ## 0.5.2
18
18
 
@@ -7,14 +7,13 @@ export const codeTransformer = (sourceCode: string, basePath: string): string =>
7
7
  // normalise for absolute (/path) and relative (path) values
8
8
  const transformSrc = (src: string) => (src.startsWith('/') ? `${basePath}${src}` : `${basePath}/${src}`)
9
9
 
10
- const transformElement =
11
- (imgTag: string) =>
12
- (match: string, before = '', src: string, after: string) => {
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) => {
13
14
  if (!shouldTransform(src)) return match
14
- return `<${imgTag} ${before}src="${transformSrc(src)}"${after}`
15
- }
16
15
 
17
- return sourceCode
18
- .replace(/<img\s+([^>]*\s+)?src=["']([^"']+)["']([^>]*>)/g, transformElement('img'))
19
- .replace(/<Image\s+([^>]*\s+)?src=["']([^"']+)["']([^>]*)/g, transformElement('Image'))
16
+ return `<${tagName} ${before}src="${transformSrc(src)}"${after}`
17
+ },
18
+ )
20
19
  }
@@ -18,6 +18,7 @@ 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'
21
22
 
22
23
  type IndexCardsProps = {
23
24
  route: string
@@ -43,6 +44,7 @@ const lightModePlaceholderThumbs = [
43
44
  ] as unknown as StaticImageData[]
44
45
 
45
46
  export function IndexCards({route, folderData}: IndexCardsProps) {
47
+ const {basePath} = useConfig()
46
48
  const lastPlaceholderIndexRef = useRef<number>(-1)
47
49
  // We don't want to show children of these pages. E.g. tabbed pages
48
50
  const onlyDirectChildren = folderData.filter(item => {
@@ -93,7 +95,7 @@ export function IndexCards({route, folderData}: IndexCardsProps) {
93
95
  <Grid.Column span={{xsmall: 12, small: 12, medium: 12, large: 6, xlarge: 4}} key={item.frontMatter.title}>
94
96
  <Link legacyBehavior passHref href={item.route}>
95
97
  <Card href="#" hasBorder>
96
- <Card.Image src={thumbnailUrl} alt="" aspectRatio="4:3" />
98
+ <Card.Image src={`${basePath ? basePath : ''}${thumbnailUrl}`} alt="" aspectRatio="4:3" />
97
99
  <Card.Heading>{item.frontMatter.title}</Card.Heading>
98
100
  {item.frontMatter.description && <Card.Description>{item.frontMatter.description}</Card.Description>}
99
101
  </Card>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/doctocat-nextjs",
3
- "version": "0.0.0-20250620092520",
3
+ "version": "0.0.0-20250620095814",
4
4
  "description": "A Next.js theme for building Primer documentation sites",
5
5
  "main": "index.js",
6
6
  "type": "module",