@primer/doctocat-nextjs 0.5.2-rc.3d762f6 → 0.5.2-rc.7482d32
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 +7 -3
- package/components/layout/index-cards/IndexCards.tsx +52 -4
- package/components/layout/index-cards/images/dark-1.png +0 -0
- package/components/layout/index-cards/images/dark-2.png +0 -0
- package/components/layout/index-cards/images/dark-3.png +0 -0
- package/components/layout/index-cards/images/dark-4.png +0 -0
- package/components/layout/index-cards/images/dark-5.png +0 -0
- package/components/layout/index-cards/images/dark-6.png +0 -0
- package/components/layout/index-cards/images/light-1.png +0 -0
- package/components/layout/index-cards/images/light-2.png +0 -0
- package/components/layout/index-cards/images/light-3.png +0 -0
- package/components/layout/index-cards/images/light-4.png +0 -0
- package/components/layout/index-cards/images/light-5.png +0 -0
- package/components/layout/index-cards/images/light-6.png +0 -0
- package/global.types.d.ts +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
- Added active header link as sidebar heading.
|
|
10
10
|
- Made active header the root item of breadcrumbs, if available.
|
|
11
|
-
- Made sidebar group
|
|
11
|
+
- Made sidebar group headlines link to the index page.
|
|
12
12
|
|
|
13
|
-
- [#39](https://github.com/primer/doctocat-nextjs/pull/39) [`9090a35`](https://github.com/primer/doctocat-nextjs/commit/9090a3516de8657321ff2217e944cca6466ec9a0) Thanks [@danielguillan](https://github.com/danielguillan)! - Updated index pages to use a grid of Cards with thumbnails
|
|
13
|
+
- [#39](https://github.com/primer/doctocat-nextjs/pull/39) [`9090a35`](https://github.com/primer/doctocat-nextjs/commit/9090a3516de8657321ff2217e944cca6466ec9a0) Thanks [@danielguillan](https://github.com/danielguillan)! - Updated index pages to use a grid of Cards with thumbnails.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Use `thumbnail` and `thumbnail_darkMode` to set custom thumbnail URLs for light and dark color modes respectively.
|
|
16
|
+
|
|
17
|
+
- [#38](https://github.com/primer/doctocat-nextjs/pull/38) [`e950c9a`](https://github.com/primer/doctocat-nextjs/commit/e950c9af9ad410025437510113172e207e2e30a2) Thanks [@danielguillan](https://github.com/danielguillan)! - Updated Primer Brand library to `v0.54.0`
|
|
18
|
+
|
|
19
|
+
- [#42](https://github.com/primer/doctocat-nextjs/pull/42) [`c9c2d16`](https://github.com/primer/doctocat-nextjs/commit/c9c2d16aa12ad56c71ec5ddbc008a028a378d81d) Thanks [@rezrah](https://github.com/rezrah)! - Added placeholder images to the Index page cards, where `thumbnail` and `thumbnail_darkMode` aren't provided through the frontmatter
|
|
16
20
|
|
|
17
21
|
## 0.5.1
|
|
18
22
|
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, {useCallback, useRef} from 'react'
|
|
2
2
|
import {Card, Grid} from '@primer/react-brand'
|
|
3
3
|
import {DocsItem} from '../../../types'
|
|
4
4
|
import {useColorMode} from '../../context/color-modes/useColorMode'
|
|
5
|
+
import type {StaticImageData} from 'next/image'
|
|
6
|
+
import placeholderDarkOneThumb from './images/dark-1.png'
|
|
7
|
+
import placeholderDarkTwoThumb from './images/dark-2.png'
|
|
8
|
+
import placeholderDarkThreeThumb from './images/dark-3.png'
|
|
9
|
+
import placeholderDarkFourThumb from './images/dark-4.png'
|
|
10
|
+
import placeholderDarkFiveThumb from './images/dark-5.png'
|
|
11
|
+
import placeholderDarkSixThumb from './images/dark-6.png'
|
|
12
|
+
import placeholderLightOneThumb from './images/light-1.png'
|
|
13
|
+
import placeholderLightTwoThumb from './images/light-2.png'
|
|
14
|
+
import placeholderLightThreeThumb from './images/light-3.png'
|
|
15
|
+
import placeholderLightFourThumb from './images/light-4.png'
|
|
16
|
+
import placeholderLightFiveThumb from './images/light-5.png'
|
|
17
|
+
import placeholderLightSixThumb from './images/light-6.png'
|
|
5
18
|
|
|
6
19
|
import styles from './IndexCards.module.css'
|
|
7
20
|
|
|
@@ -10,7 +23,26 @@ type IndexCardsProps = {
|
|
|
10
23
|
folderData: DocsItem[]
|
|
11
24
|
}
|
|
12
25
|
|
|
26
|
+
const darkModePlaceholderThumbs = [
|
|
27
|
+
placeholderDarkOneThumb,
|
|
28
|
+
placeholderDarkTwoThumb,
|
|
29
|
+
placeholderDarkThreeThumb,
|
|
30
|
+
placeholderDarkFourThumb,
|
|
31
|
+
placeholderDarkFiveThumb,
|
|
32
|
+
placeholderDarkSixThumb,
|
|
33
|
+
] as unknown as StaticImageData[]
|
|
34
|
+
|
|
35
|
+
const lightModePlaceholderThumbs = [
|
|
36
|
+
placeholderLightOneThumb,
|
|
37
|
+
placeholderLightTwoThumb,
|
|
38
|
+
placeholderLightThreeThumb,
|
|
39
|
+
placeholderLightFourThumb,
|
|
40
|
+
placeholderLightFiveThumb,
|
|
41
|
+
placeholderLightSixThumb,
|
|
42
|
+
] as unknown as StaticImageData[]
|
|
43
|
+
|
|
13
44
|
export function IndexCards({route, folderData}: IndexCardsProps) {
|
|
45
|
+
const lastPlaceholderIndexRef = useRef<number>(-1)
|
|
14
46
|
// We don't want to show children of these pages. E.g. tabbed pages
|
|
15
47
|
const onlyDirectChildren = folderData.filter(item => {
|
|
16
48
|
// Normalize paths regardless of trailing slash enablement
|
|
@@ -30,15 +62,31 @@ export function IndexCards({route, folderData}: IndexCardsProps) {
|
|
|
30
62
|
|
|
31
63
|
const {colorMode} = useColorMode()
|
|
32
64
|
|
|
65
|
+
// This is a better approach to straight randomisation, as it ensures that no adjacent placeholder images will be the same.
|
|
66
|
+
const getNextPlaceholderIndex = useCallback((placeholderArray: StaticImageData[]): StaticImageData => {
|
|
67
|
+
if (placeholderArray.length <= 1) {
|
|
68
|
+
return placeholderArray[0]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const numImagesByIndex = placeholderArray.map((_, index) => index)
|
|
72
|
+
|
|
73
|
+
const filteredIndexes = numImagesByIndex.filter(index => index !== lastPlaceholderIndexRef.current)
|
|
74
|
+
|
|
75
|
+
const nextIndex = filteredIndexes[Math.floor(Math.random() * filteredIndexes.length)]
|
|
76
|
+
|
|
77
|
+
lastPlaceholderIndexRef.current = nextIndex
|
|
78
|
+
return placeholderArray[nextIndex]
|
|
79
|
+
}, [])
|
|
80
|
+
|
|
33
81
|
return (
|
|
34
82
|
<Grid className={styles.IndexCards}>
|
|
35
83
|
{filteredData.map((item: DocsItem) => {
|
|
36
84
|
if (item.type !== 'doc' || !item.frontMatter) return null
|
|
37
85
|
|
|
38
86
|
const thumbnailUrl =
|
|
39
|
-
colorMode === 'dark'
|
|
40
|
-
? item.frontMatter.thumbnail_darkMode
|
|
41
|
-
: item.frontMatter.thumbnail
|
|
87
|
+
colorMode === 'dark'
|
|
88
|
+
? item.frontMatter.thumbnail_darkMode || getNextPlaceholderIndex(darkModePlaceholderThumbs).src
|
|
89
|
+
: item.frontMatter.thumbnail || getNextPlaceholderIndex(lightModePlaceholderThumbs).src
|
|
42
90
|
|
|
43
91
|
return (
|
|
44
92
|
<Grid.Column span={{xsmall: 12, small: 12, medium: 12, large: 6, xlarge: 4}} key={item.frontMatter.title}>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|