@@ -42,14 +42,46 @@ const WWAds = dynamic(() => import('@/components/WWAds'), { ssr: false })
42
42
const ThemeGlobalGitbook = createContext ( )
43
43
export const useGitBookGlobal = ( ) => useContext ( ThemeGlobalGitbook )
44
44
45
+ /**
46
+ * 给最新的文章标一个红点
47
+ */
48
+ function getNavPagesWithLatest ( allNavPages , latestPosts , post ) {
49
+ // 检测需要去除红点的文章 ; localStorage 的 posts_read = {"${post.id}":"Date()"} 保存了所有已读的页面id,和阅读时间;
50
+ // 如果页面在这里面则不显示红点
51
+ const postRead = JSON . parse ( localStorage . getItem ( 'post_read' ) || '[]' ) ;
52
+ if ( post && ! postRead . includes ( post . id ) ) {
53
+ postRead . push ( post . id ) ;
54
+ }
55
+ localStorage . setItem ( 'post_read' , JSON . stringify ( postRead ) ) ;
56
+
57
+ return allNavPages ?. map ( item => {
58
+ const res = {
59
+ id : item . id ,
60
+ title : item . title || '' ,
61
+ pageCoverThumbnail : item . pageCoverThumbnail || '' ,
62
+ category : item . category || null ,
63
+ tags : item . tags || null ,
64
+ summary : item . summary || null ,
65
+ slug : item . slug ,
66
+ pageIcon : item . pageIcon || '' ,
67
+ lastEditedDate : item . lastEditedDate
68
+ }
69
+ if ( latestPosts . some ( post => post . id === item . id ) && ! postRead . includes ( item . id ) ) {
70
+ return { ...res , isLatest : true } ;
71
+ } else {
72
+ return res ;
73
+ }
74
+ } )
75
+ }
76
+
45
77
/**
46
78
* 基础布局
47
79
* 采用左右两侧布局,移动端使用顶部导航栏
48
80
* @returns {JSX.Element }
49
81
* @constructor
50
82
*/
51
83
const LayoutBase = ( props ) => {
52
- const { children, post, allNavPages, slotLeft, slotRight, slotTop } = props
84
+ const { children, post, allNavPages, latestPosts , slotLeft, slotRight, slotTop } = props
53
85
const { onLoading, fullWidth } = useGlobal ( )
54
86
const router = useRouter ( )
55
87
const [ tocVisible , changeTocVisible ] = useState ( false )
@@ -60,8 +92,8 @@ const LayoutBase = (props) => {
60
92
const searchModal = useRef ( null )
61
93
62
94
useEffect ( ( ) => {
63
- setFilteredNavPages ( allNavPages )
64
- } , [ post ] )
95
+ setFilteredNavPages ( getNavPagesWithLatest ( allNavPages , latestPosts , post ) )
96
+ } , [ router ] )
65
97
66
98
return (
67
99
< ThemeGlobalGitbook . Provider value = { { searchModal, tocVisible, changeTocVisible, filteredNavPages, setFilteredNavPages, allNavPages, pageNavVisible, changePageNavVisible } } >
@@ -78,7 +110,7 @@ const LayoutBase = (props) => {
78
110
{ /* 左侧推拉抽屉 */ }
79
111
{ fullWidth
80
112
? null
81
- : ( < div className = { 'hidden md:block border-r dark:border-transparent relative z-10 ' } >
113
+ : ( < div className = { 'hidden md:block border-r dark:border-transparent relative z-10 dark:bg-hexo-black-gray ' } >
82
114
< div className = 'w-72 py-14 px-6 sticky top-0 overflow-y-scroll h-screen scroll-hidden' >
83
115
{ slotLeft }
84
116
< SearchInput className = 'my-3 rounded-md' />
@@ -94,7 +126,7 @@ const LayoutBase = (props) => {
94
126
</ div >
95
127
</ div > ) }
96
128
97
- < div id = 'center-wrapper' className = 'flex flex-col justify-between w-full relative z-10 pt-14 min-h-screen' >
129
+ < div id = 'center-wrapper' className = 'flex flex-col justify-between w-full relative z-10 pt-14 min-h-screen dark:bg-black ' >
98
130
99
131
< div id = 'container-inner' className = { `w-full px-7 ${ fullWidth ? 'px-10' : 'max-w-3xl' } justify-center mx-auto` } >
100
132
{ slotTop }
0 commit comments