Skip to content

Commit 825f9f0

Browse files
committed
2 parents 1e48acf + c24f9a0 commit 825f9f0

File tree

10 files changed

+216
-150
lines changed

10 files changed

+216
-150
lines changed

blog.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const BLOG = {
1313
APPEARANCE: process.env.NEXT_PUBLIC_APPEARANCE || 'light', // ['light', 'dark', 'auto'], // light 日间模式 , dark夜间模式, auto根据时间和主题自动夜间模式
1414
APPEARANCE_DARK_TIME: process.env.NEXT_PUBLIC_APPEARANCE_DARK_TIME || [18, 6], // 夜间模式起至时间,false时关闭根据时间自动切换夜间模式
1515

16+
TAG_SORT_BY_COUNT: true, // 标签是否按照文章数量倒序排列,文章多的标签排在前。
1617
IS_TAG_COLOR_DISTINGUISHED:
1718
process.env.NEXT_PUBLIC_IS_TAG_COLOR_DISTINGUISHED === 'true' || true, // 对于名称相同的tag是否区分tag的颜色
1819

components/CustomContextMenu.js

+30-7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export default function CustomContextMenu(props) {
5656
setShow(true)
5757
}
5858

59+
/**
60+
* 鼠标点击事件
61+
*/
5962
const handleClick = event => {
6063
if (menuRef.current && !menuRef.current.contains(event.target)) {
6164
setShow(false)
@@ -140,6 +143,26 @@ export default function CustomContextMenu(props) {
140143
htmlElement.classList?.add(newStatus ? 'dark' : 'light')
141144
}
142145

146+
// 一些配置变量
147+
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU_RANDOM_POST = siteConfig(
148+
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU_RANDOM_POST'
149+
)
150+
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU_CATEGORY = siteConfig(
151+
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU_CATEGORY'
152+
)
153+
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU_TAG = siteConfig(
154+
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU_TAG'
155+
)
156+
const CAN_COPY = siteConfig('CAN_COPY')
157+
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU_SHARE_LINK = siteConfig(
158+
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU_SHARE_LINK'
159+
)
160+
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU_DARK_MODE = siteConfig(
161+
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU_DARK_MODE'
162+
)
163+
const CUSTOM_RIGHT_CLICK_CONTEXT_MENU_THEME_SWITCH = siteConfig(
164+
'CUSTOM_RIGHT_CLICK_CONTEXT_MENU_THEME_SWITCH'
165+
)
143166
return (
144167
<div
145168
ref={menuRef}
@@ -167,7 +190,7 @@ export default function CustomContextMenu(props) {
167190

168191
{/* 跳转导航按钮 */}
169192
<div className='w-full px-2'>
170-
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_RANDOM_POST') && (
193+
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_RANDOM_POST && (
171194
<div
172195
onClick={handleJumpToRandomPost}
173196
title={locale.MENU.WALK_AROUND}
@@ -177,7 +200,7 @@ export default function CustomContextMenu(props) {
177200
</div>
178201
)}
179202

180-
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_CATEGORY') && (
203+
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_CATEGORY && (
181204
<Link
182205
href='/category'
183206
title={locale.MENU.CATEGORY}
@@ -187,7 +210,7 @@ export default function CustomContextMenu(props) {
187210
</Link>
188211
)}
189212

190-
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_TAG') && (
213+
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_TAG && (
191214
<Link
192215
href='/tag'
193216
title={locale.MENU.TAGS}
@@ -202,7 +225,7 @@ export default function CustomContextMenu(props) {
202225

203226
{/* 功能按钮 */}
204227
<div className='w-full px-2'>
205-
{siteConfig('CAN_COPY') && (
228+
{CAN_COPY && (
206229
<div
207230
onClick={handleCopy}
208231
title={locale.MENU.COPY}
@@ -212,7 +235,7 @@ export default function CustomContextMenu(props) {
212235
</div>
213236
)}
214237

215-
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_SHARE_LINK') && (
238+
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_SHARE_LINK && (
216239
<div
217240
onClick={handleCopyLink}
218241
title={locale.MENU.SHARE_URL}
@@ -222,7 +245,7 @@ export default function CustomContextMenu(props) {
222245
</div>
223246
)}
224247

225-
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_DARK_MODE') && (
248+
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_DARK_MODE && (
226249
<div
227250
onClick={handleChangeDarkMode}
228251
title={
@@ -241,7 +264,7 @@ export default function CustomContextMenu(props) {
241264
</div>
242265
)}
243266

244-
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_THEME_SWITCH') && (
267+
{CUSTOM_RIGHT_CLICK_CONTEXT_MENU_THEME_SWITCH && (
245268
<div
246269
onClick={handleChangeTheme}
247270
title={locale.MENU.THEME_SWITCH}

lib/db/getSiteData.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getAllPageIds from '@/lib/notion/getAllPageIds'
55
import { getAllTags } from '@/lib/notion/getAllTags'
66
import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig'
77
import getPageProperties, {
8-
adjustPageProperties
8+
adjustPageProperties
99
} from '@/lib/notion/getPageProperties'
1010
import { fetchInBatches, getPage } from '@/lib/notion/getPostBlocks'
1111
import { compressImage, mapImgUrl } from '@/lib/notion/mapImage'
@@ -77,15 +77,17 @@ export async function getNotionPageData({ pageId, from }) {
7777
}
7878

7979
// 返回给前端的数据做处理
80-
return compressData(deepClone(data))
80+
return handleDataBeforeReturn(deepClone(data))
8181
}
8282

8383
/**
84-
* 减少返回给前端的数据
85-
* 并脱敏
84+
* 返回给浏览器前端的数据处理
85+
* 适当脱敏
86+
* 减少体积
87+
* 其它处理
8688
* @param {*} db
8789
*/
88-
function compressData(db) {
90+
function handleDataBeforeReturn(db) {
8991
// 清理多余数据
9092
delete db.block
9193
delete db.schema
@@ -545,11 +547,17 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
545547
)
546548
})?.[0]
547549
)
550+
// 所有分类
548551
const categoryOptions = getAllCategories({
549552
allPages,
550553
categoryOptions: getCategoryOptions(schema)
551554
})
552-
const tagOptions = getAllTags({ allPages, tagOptions: getTagOptions(schema) })
555+
// 所有标签
556+
const tagOptions = getAllTags({
557+
allPages,
558+
tagOptions: getTagOptions(schema),
559+
NOTION_CONFIG
560+
})
553561
// 旧的菜单
554562
const customNav = getCustomNav({
555563
allPages: collectionData.filter(

lib/notion/getAllCategories.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isIterable } from '../utils'
44
* 获取所有文章的标签
55
* @param allPosts
66
* @param sliceCount 默认截取数量为12,若为0则返回全部
7-
* @param tagOptions tags的下拉选项
7+
* @param categoryOptions categories的下拉选项
88
* @returns {Promise<{}|*[]>}
99
*/
1010

@@ -13,8 +13,14 @@ import { isIterable } from '../utils'
1313
* @param allPosts
1414
* @returns {Promise<{}|*[]>}
1515
*/
16-
export function getAllCategories({ allPages, categoryOptions, sliceCount = 0 }) {
17-
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
16+
export function getAllCategories({
17+
allPages,
18+
categoryOptions,
19+
sliceCount = 0
20+
}) {
21+
const allPosts = allPages?.filter(
22+
page => page.type === 'Post' && page.status === 'Published'
23+
)
1824
if (!allPosts || !categoryOptions) {
1925
return []
2026
}

lib/notion/getAllTags.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { siteConfig } from '../config'
12
import { isIterable } from '../utils'
2-
import BLOG from '@/blog.config'
33

44
/**
55
* 获取所有文章的标签
@@ -8,8 +8,15 @@ import BLOG from '@/blog.config'
88
* @param tagOptions tags的下拉选项
99
* @returns {Promise<{}|*[]>}
1010
*/
11-
export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
12-
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
11+
export function getAllTags({
12+
allPages,
13+
sliceCount = 0,
14+
tagOptions,
15+
NOTION_CONFIG
16+
}) {
17+
const allPosts = allPages?.filter(
18+
page => page.type === 'Post' && page.status === 'Published'
19+
)
1320

1421
if (!allPosts || !tagOptions) {
1522
return []
@@ -27,7 +34,12 @@ export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
2734
})
2835

2936
const list = []
30-
const { IS_TAG_COLOR_DISTINGUISHED } = BLOG
37+
const IS_TAG_COLOR_DISTINGUISHED = siteConfig(
38+
'IS_TAG_COLOR_DISTINGUISHED',
39+
false,
40+
NOTION_CONFIG
41+
)
42+
const TAG_SORT_BY_COUNT = siteConfig('TAG_SORT_BY_COUNT', true, NOTION_CONFIG)
3143
if (isIterable(tagOptions)) {
3244
if (!IS_TAG_COLOR_DISTINGUISHED) {
3345
// 如果不区分颜色, 那么不同颜色相同名称的tag当做同一种tag
@@ -52,7 +64,10 @@ export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
5264
}
5365

5466
// 按照数量排序
55-
// list.sort((a, b) => b.count - a.count)
67+
if (TAG_SORT_BY_COUNT) {
68+
list.sort((a, b) => b.count - a.count)
69+
}
70+
5671
if (sliceCount && sliceCount > 0) {
5772
return list.slice(0, sliceCount)
5873
} else {

themes/heo/components/PaginationNumber.js

+24-31
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const PaginationNumber = ({ page, totalPage }) => {
4444
return (
4545
<>
4646
{/* pc端分页按钮 */}
47-
<div className="hidden lg:flex justify-between items-end mt-10 mb-5 font-medium text-black duration-500 dark:text-gray-300 py-3 space-x-2 overflow-x-auto">
47+
<div className='hidden lg:flex justify-between items-end mt-10 font-medium text-black duration-500 dark:text-gray-300 pt-3 space-x-2 overflow-x-auto'>
4848
{/* 上一页 */}
4949
<Link
5050
href={{
@@ -54,32 +54,29 @@ const PaginationNumber = ({ page, totalPage }) => {
5454
: `${pagePrefix}/page/${currentPage - 1}`,
5555
query: router.query.s ? { s: router.query.s } : {}
5656
}}
57-
rel="prev"
58-
className={`${currentPage === 1 ? 'invisible' : 'block'}`}
59-
>
60-
<div className="relative w-24 h-10 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-lg cursor-pointer group">
61-
<i className="fas fa-angle-left mr-2 transition-all duration-200 transform group-hover:-translate-x-4" />
62-
<div className="absolute translate-x-4 ml-2 opacity-0 transition-all duration-200 group-hover:opacity-100 group-hover:translate-x-0">
57+
rel='prev'
58+
className={`${currentPage === 1 ? 'invisible' : 'block'}`}>
59+
<div className='relative w-24 h-10 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-lg cursor-pointer group'>
60+
<i className='fas fa-angle-left mr-2 transition-all duration-200 transform group-hover:-translate-x-4' />
61+
<div className='absolute translate-x-4 ml-2 opacity-0 transition-all duration-200 group-hover:opacity-100 group-hover:translate-x-0'>
6362
{locale.PAGINATION.PREV}
6463
</div>
6564
</div>
6665
</Link>
6766

6867
{/* 分页 */}
69-
<div className="flex items-center space-x-2">
68+
<div className='flex items-center space-x-2'>
7069
{pages}
7170

7271
{/* 跳转页码 */}
73-
<div className="bg-white hover:bg-gray-100 dark:hover:bg-yellow-600 dark:bg-[#1e1e1e] h-10 border flex justify-center items-center rounded-lg group hover:border-indigo-600 transition-all duration-200">
72+
<div className='bg-white hover:bg-gray-100 dark:hover:bg-yellow-600 dark:bg-[#1e1e1e] h-10 border flex justify-center items-center rounded-lg group hover:border-indigo-600 transition-all duration-200'>
7473
<input
7574
value={value}
76-
className="w-0 group-hover:w-20 group-hover:px-3 transition-all duration-200 bg-gray-100 border-none outline-none h-full rounded-lg"
77-
onInput={handleInputChange}
78-
></input>
75+
className='w-0 group-hover:w-20 group-hover:px-3 transition-all duration-200 bg-gray-100 border-none outline-none h-full rounded-lg'
76+
onInput={handleInputChange}></input>
7977
<div
8078
onClick={jumpToPage}
81-
className="cursor-pointer hover:bg-indigo-600 dark:bg-[#1e1e1e] dark:hover:bg-yellow-600 hover:text-white px-4 py-2 group-hover:px-2 group-hover:mx-1 group-hover:rounded bg-white"
82-
>
79+
className='cursor-pointer hover:bg-indigo-600 dark:bg-[#1e1e1e] dark:hover:bg-yellow-600 hover:text-white px-4 py-2 group-hover:px-2 group-hover:mx-1 group-hover:rounded bg-white'>
8380
<ChevronDoubleRight className={'w-4 h-4'} />
8481
</div>
8582
</div>
@@ -91,12 +88,11 @@ const PaginationNumber = ({ page, totalPage }) => {
9188
pathname: `${pagePrefix}/page/${currentPage + 1}`,
9289
query: router.query.s ? { s: router.query.s } : {}
9390
}}
94-
rel="next"
95-
className={`${+showNext ? 'block' : 'invisible'} `}
96-
>
97-
<div className="relative w-24 h-10 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-lg cursor-pointer group">
98-
<i className="fas fa-angle-right mr-2 transition-all duration-200 transform group-hover:translate-x-6" />
99-
<div className="absolute -translate-x-10 ml-2 opacity-0 transition-all duration-200 group-hover:opacity-100 group-hover:-translate-x-2">
91+
rel='next'
92+
className={`${+showNext ? 'block' : 'invisible'} `}>
93+
<div className='relative w-24 h-10 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-lg cursor-pointer group'>
94+
<i className='fas fa-angle-right mr-2 transition-all duration-200 transform group-hover:translate-x-6' />
95+
<div className='absolute -translate-x-10 ml-2 opacity-0 transition-all duration-200 group-hover:opacity-100 group-hover:-translate-x-2'>
10096
{locale.PAGINATION.NEXT}
10197
</div>
10298
</div>
@@ -105,7 +101,7 @@ const PaginationNumber = ({ page, totalPage }) => {
105101

106102
{/* 移动端分页 */}
107103

108-
<div className="lg:hidden w-full flex flex-row">
104+
<div className='lg:hidden w-full flex flex-row'>
109105
{/* 上一页 */}
110106
<Link
111107
href={{
@@ -115,23 +111,21 @@ const PaginationNumber = ({ page, totalPage }) => {
115111
: `${pagePrefix}/page/${currentPage - 1}`,
116112
query: router.query.s ? { s: router.query.s } : {}
117113
}}
118-
rel="prev"
119-
className={`${showPrev ? 'block' : 'hidden'} dark:text-white relative w-full flex-1 h-14 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-xl cursor-pointer`}
120-
>
114+
rel='prev'
115+
className={`${showPrev ? 'block' : 'hidden'} dark:text-white relative w-full flex-1 h-14 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-xl cursor-pointer`}>
121116
{locale.PAGINATION.PREV}
122117
</Link>
123118

124-
{showPrev && showNext && <div className="w-12"></div>}
119+
{showPrev && showNext && <div className='w-12'></div>}
125120

126121
{/* 下一页 */}
127122
<Link
128123
href={{
129124
pathname: `${pagePrefix}/page/${currentPage + 1}`,
130125
query: router.query.s ? { s: router.query.s } : {}
131126
}}
132-
rel="next"
133-
className={`${+showNext ? 'block' : 'hidden'} dark:text-white relative w-full flex-1 h-14 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-xl cursor-pointer`}
134-
>
127+
rel='next'
128+
className={`${+showNext ? 'block' : 'hidden'} dark:text-white relative w-full flex-1 h-14 flex items-center transition-all duration-200 justify-center py-2 px-2 bg-white dark:bg-[#1e1e1e] border rounded-xl cursor-pointer`}>
135129
{locale.PAGINATION.NEXT}
136130
</Link>
137131
</div>
@@ -161,8 +155,7 @@ function getPageElement(page, currentPage, pagePrefix) {
161155
? 'bg-indigo-600 dark:bg-yellow-600 text-white '
162156
: 'dark:bg-[#1e1e1e] bg-white') +
163157
' hover:border-indigo-600 dark:hover:bg-yellow-600 dark:border-gray-600 px-4 border py-2 rounded-lg drop-shadow-sm duration-200 transition-colors'
164-
}
165-
>
158+
}>
166159
{page}
167160
</Link>
168161
)
@@ -195,7 +188,7 @@ function generatePages(pagePrefix, page, currentPage, totalPage) {
195188
}
196189
if (startPage > 2) {
197190
pages.push(
198-
<div key={-1} className="-mt-2 mx-1">
191+
<div key={-1} className='-mt-2 mx-1'>
199192
...{' '}
200193
</div>
201194
)

0 commit comments

Comments
 (0)