Skip to content

Commit 18500ec

Browse files
committed
2 parents 832e145 + 3d67867 commit 18500ec

20 files changed

+445
-246
lines changed

lib/notion/getPageProperties.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ export default async function getPageProperties(
105105
properties.pageIcon = mapImgUrl(value?.format?.page_icon, value) ?? ''
106106
properties.pageCover = mapImgUrl(value?.format?.page_cover, value) ?? ''
107107
properties.pageCoverThumbnail =
108-
mapImgUrl(
109-
value?.format?.page_cover,
110-
value,
111-
'block',
112-
'pageCoverThumbnail'
113-
) ?? ''
108+
mapImgUrl(value?.format?.page_cover, value, 'block') ?? ''
114109
properties.ext = converToJSON(properties?.ext)
115110
properties.content = value.content ?? []
116111
properties.tagItems =

lib/notion/mapImage.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import { siteConfig } from '../config'
33

44
/**
55
* 图片映射
6-
* 1. 如果是 /xx.xx 相对路径格式,则转化为 完整notion域名图片
7-
* 2. 如果是 bookmark类型的block 图片封面无需处理
8-
* @param {*} img
9-
* @param {*} value
6+
*
7+
* @param {*} img 图片地址,可能是相对路径,可能是外链
8+
* @param {*} block 数据块,可能是单个内容块,可能是Page
9+
* @param {*} type block 单个内容块 ; collection 集合列表
10+
* @param {*} from 来自
1011
* @returns
1112
*/
12-
const mapImgUrl = (img, block, type = 'block', from = 'post') => {
13+
const mapImgUrl = (img, block, type = 'block', needCompress = true) => {
1314
if (!img) {
1415
return null
1516
}
17+
1618
let ret = null
1719
// 相对目录,则视为notion的自带图片
1820
if (img.startsWith('/')) {
@@ -22,12 +24,16 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
2224
}
2325

2426
// Notion 图床转换为永久地址
25-
const isNotionSignImg =
26-
ret.indexOf('https://www.notion.so/image') !== 0 &&
27+
const hasConverted = ret.indexOf('https://www.notion.so/image') === 0
28+
// 需要转化的URL ; 识别aws图床地址,或者bookmark类型的外链图片
29+
const needConvert =
30+
!hasConverted &&
2731
(ret.indexOf('secure.notion-static.com') > 0 ||
28-
ret.indexOf('prod-files-secure') > 0)
29-
const isImgBlock = BLOG.IMG_URL_TYPE === 'Notion' || type !== 'block'
30-
if (isNotionSignImg && isImgBlock) {
32+
ret.indexOf('prod-files-secure') > 0 ||
33+
block.type === 'bookmark')
34+
35+
// 使用Notion图传
36+
if (needConvert) {
3137
ret =
3238
BLOG.NOTION_HOST +
3339
'/image/' +
@@ -60,19 +66,19 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
6066
}
6167

6268
// 图片url优化,确保每一篇文章的图片url唯一
63-
if (ret && ret.length > 4) {
69+
if (
70+
ret &&
71+
ret.length > 4 &&
72+
!ret.includes('https://www.notion.so/images/')
73+
) {
6474
// 图片接口拼接唯一识别参数,防止请求的图片被缓,而导致随机结果相同
6575
const separator = ret.includes('?') ? '&' : '?'
6676
ret = `${ret.trim()}${separator}t=${block.id}`
6777
}
6878
}
6979

7080
// 统一压缩图片
71-
if (
72-
from === 'pageCoverThumbnail' ||
73-
block?.type === 'image' ||
74-
block?.type === 'page'
75-
) {
81+
if (needCompress) {
7682
const width = block?.format?.block_width
7783
ret = compressImage(ret, width)
7884
}

next.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const nextConfig = {
6969
'ko-fi.com'
7070
]
7171
},
72+
7273
// 默认将feed重定向至 /public/rss/feed.xml
7374
async redirects() {
7475
return [

themes/hexo/components/Hero.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const Hero = props => {
6666
<div className='text-white absolute bottom-0 flex flex-col h-full items-center justify-center w-full '>
6767
{/* 站点标题 */}
6868
<div className='font-black text-4xl md:text-5xl shadow-text'>
69-
{siteConfig('TITLE')}
69+
{siteInfo?.title || siteConfig('TITLE')}
7070
</div>
7171
{/* 站点欢迎语 */}
7272
<div className='mt-2 h-12 items-center text-center font-medium shadow-text text-lg'>

themes/hexo/components/Logo.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { siteConfig } from '@/lib/config'
22
import Link from 'next/link'
3-
3+
/**
4+
* Logo
5+
* 实际值支持文字
6+
* @param {*} props
7+
* @returns
8+
*/
49
const Logo = props => {
10+
const { siteInfo } = props
511
return (
612
<Link href='/' passHref legacyBehavior>
713
<div className='flex flex-col justify-center items-center cursor-pointer space-y-3'>
8-
<div className='font-medium text-lg p-1.5 rounded dark:border-white dark:text-white menu-link transform duration-200'> {siteConfig('TITLE') }</div>
14+
<div className='font-medium text-lg p-1.5 rounded dark:border-white dark:text-white menu-link transform duration-200'>
15+
{' '}
16+
{siteInfo?.title || siteConfig('TITLE')}
17+
</div>
918
</div>
1019
</Link>
1120
)

themes/hexo/components/MenuItemCollapse.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export const MenuItemCollapse = props => {
2929
return (
3030
<>
3131
<div
32-
className='w-full px-8 py-3 text-left dark:bg-hexo-black-gray'
32+
className='w-full px-8 py-3 dark:hover:bg-indigo-500 hover:bg-indigo-500 hover:text-white text-left dark:bg-hexo-black-gray'
3333
onClick={toggleShow}>
3434
{!hasSubMenu && (
3535
<Link
3636
href={link?.to}
3737
target={link?.target}
38-
className='font-extralight flex justify-between pl-2 pr-4 dark:text-gray-200 no-underline tracking-widest pb-1'>
38+
className=' font-extralight flex justify-between pl-2 pr-4 dark:text-gray-200 no-underline tracking-widest pb-1'>
3939
<span className=' transition-all items-center duration-200'>
4040
{link?.icon && <i className={link.icon + ' mr-4'} />}
4141
{link?.name}
@@ -63,7 +63,7 @@ export const MenuItemCollapse = props => {
6363
return (
6464
<div
6565
key={index}
66-
className='dark:bg-black dark:text-gray-200 text-left px-10 justify-start bg-gray-50 hover:bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200 py-3 pr-6'>
66+
className='dark:hover:bg-indigo-500 hover:bg-indigo-500 hover:text-white dark:bg-black dark:text-gray-200 text-left px-10 justify-start bg-gray-50 tracking-widest transition-all duration-200 py-3 pr-6'>
6767
<Link href={sLink.to} target={link?.target}>
6868
<span className='text-sm ml-4 whitespace-nowrap'>
6969
{link?.icon && <i className={sLink.icon + ' mr-2'} />}{' '}

themes/hexo/components/MenuItemDrop.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Link from 'next/link'
22
import { useState } from 'react'
3-
3+
/**
4+
* 支持二级展开的菜单
5+
* @param {*} param0
6+
* @returns
7+
*/
48
export const MenuItemDrop = ({ link }) => {
59
const [show, changeShow] = useState(false)
610
const hasSubMenu = link?.subMenus?.length > 0
@@ -25,7 +29,7 @@ export const MenuItemDrop = ({ link }) => {
2529

2630
{hasSubMenu && (
2731
<>
28-
<div className='cursor-pointer menu-link pl-2 pr-4 no-underline tracking-widest pb-1'>
32+
<div className='cursor-pointer menu-link pl-2 pr-4 no-underline tracking-widest pb-1'>
2933
{link?.icon && <i className={link?.icon} />} {link?.name}
3034
<i
3135
className={`px-2 fa fa-angle-down duration-300 ${show ? 'rotate-180' : 'rotate-0'}`}></i>
@@ -42,7 +46,7 @@ export const MenuItemDrop = ({ link }) => {
4246
return (
4347
<li
4448
key={index}
45-
className='cursor-pointer hover:bg-indigo-300 hover:text-black tracking-widest transition-all duration-200 dark:border-gray-800 py-1 pr-6 pl-3'>
49+
className='cursor-pointer hover:bg-indigo-500 hover:text-white tracking-widest transition-all duration-200 dark:border-gray-800 py-1 pr-6 pl-3'>
4650
<Link href={sLink.to} target={link?.target}>
4751
<span className='text-sm text-nowrap font-extralight'>
4852
{link?.icon && <i className={sLink?.icon}> &nbsp; </i>}

themes/hexo/components/MenuListSide.js

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
1-
import { useGlobal } from '@/lib/global'
21
import { siteConfig } from '@/lib/config'
3-
import { MenuItemCollapse } from './MenuItemCollapse'
2+
import { useGlobal } from '@/lib/global'
43
import CONFIG from '../config'
5-
6-
export const MenuListSide = (props) => {
4+
import { MenuItemCollapse } from './MenuItemCollapse'
5+
/**
6+
* 侧拉抽屉菜单
7+
* @param {*} props
8+
* @returns
9+
*/
10+
export const MenuListSide = props => {
711
const { customNav, customMenu } = props
812
const { locale } = useGlobal()
913

1014
let links = [
11-
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: siteConfig('HEXO_MENU_ARCHIVE', null, CONFIG) },
12-
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: siteConfig('HEXO_MENU_SEARCH', null, CONFIG) },
13-
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('HEXO_MENU_CATEGORY', null, CONFIG) },
14-
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('HEXO_MENU_TAG', null, CONFIG) }
15+
{
16+
icon: 'fas fa-archive',
17+
name: locale.NAV.ARCHIVE,
18+
to: '/archive',
19+
show: siteConfig('HEXO_MENU_ARCHIVE', null, CONFIG)
20+
},
21+
{
22+
icon: 'fas fa-search',
23+
name: locale.NAV.SEARCH,
24+
to: '/search',
25+
show: siteConfig('HEXO_MENU_SEARCH', null, CONFIG)
26+
},
27+
{
28+
icon: 'fas fa-folder',
29+
name: locale.COMMON.CATEGORY,
30+
to: '/category',
31+
show: siteConfig('HEXO_MENU_CATEGORY', null, CONFIG)
32+
},
33+
{
34+
icon: 'fas fa-tag',
35+
name: locale.COMMON.TAGS,
36+
to: '/tag',
37+
show: siteConfig('HEXO_MENU_TAG', null, CONFIG)
38+
}
1539
]
1640

1741
if (customNav) {
@@ -34,8 +58,10 @@ export const MenuListSide = (props) => {
3458
}
3559

3660
return (
37-
<nav>
38-
{links?.map((link, index) => <MenuItemCollapse key={index} link={link} />)}
39-
</nav>
61+
<nav>
62+
{links?.map((link, index) => (
63+
<MenuItemCollapse key={index} link={link} />
64+
))}
65+
</nav>
4066
)
4167
}

themes/hexo/components/SideBar.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { siteConfig } from '@/lib/config'
21
import LazyImage from '@/components/LazyImage'
2+
import { siteConfig } from '@/lib/config'
33
import { useRouter } from 'next/router'
44
import MenuGroupCard from './MenuGroupCard'
55
import { MenuListSide } from './MenuListSide'
@@ -11,22 +11,33 @@ import { MenuListSide } from './MenuListSide'
1111
* @returns {JSX.Element}
1212
* @constructor
1313
*/
14-
const SideBar = (props) => {
14+
const SideBar = props => {
1515
const { siteInfo } = props
1616
const router = useRouter()
1717
return (
18-
<div id='side-bar'>
19-
<div className="h-52 w-full flex justify-center">
20-
<div>
21-
<div onClick={() => { router.push('/') }}
22-
className='justify-center items-center flex hover:rotate-45 py-6 hover:scale-105 dark:text-gray-100 transform duration-200 cursor-pointer'>
23-
<LazyImage src={siteInfo?.icon} className='rounded-full' width={80} alt={siteConfig('AUTHOR')} />
24-
</div>
25-
<MenuGroupCard {...props} />
26-
</div>
27-
</div>
28-
<MenuListSide {...props} />
18+
<div id='side-bar'>
19+
<div className='h-52 w-full flex justify-center'>
20+
<div>
21+
<div
22+
onClick={() => {
23+
router.push('/')
24+
}}
25+
className='justify-center items-center flex hover:rotate-45 py-6 hover:scale-105 dark:text-gray-100 transform duration-200 cursor-pointer'>
26+
{/* 头像 */}
27+
<LazyImage
28+
src={siteInfo?.icon}
29+
className='rounded-full'
30+
width={80}
31+
alt={siteConfig('AUTHOR')}
32+
/>
33+
</div>
34+
{/* 总览 */}
35+
<MenuGroupCard {...props} />
2936
</div>
37+
</div>
38+
{/* 侧拉抽屉的菜单 */}
39+
<MenuListSide {...props} />
40+
</div>
3041
)
3142
}
3243

0 commit comments

Comments
 (0)