Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 30, 2024
2 parents 5612aa6 + 3d67867 commit 26a535c
Show file tree
Hide file tree
Showing 20 changed files with 445 additions and 246 deletions.
7 changes: 1 addition & 6 deletions lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ export default async function getPageProperties(
properties.pageIcon = mapImgUrl(value?.format?.page_icon, value) ?? ''
properties.pageCover = mapImgUrl(value?.format?.page_cover, value) ?? ''
properties.pageCoverThumbnail =
mapImgUrl(
value?.format?.page_cover,
value,
'block',
'pageCoverThumbnail'
) ?? ''
mapImgUrl(value?.format?.page_cover, value, 'block') ?? ''
properties.ext = converToJSON(properties?.ext)
properties.content = value.content ?? []
properties.tagItems =
Expand Down
38 changes: 22 additions & 16 deletions lib/notion/mapImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { siteConfig } from '../config'

/**
* 图片映射
* 1. 如果是 /xx.xx 相对路径格式,则转化为 完整notion域名图片
* 2. 如果是 bookmark类型的block 图片封面无需处理
* @param {*} img
* @param {*} value
*
* @param {*} img 图片地址,可能是相对路径,可能是外链
* @param {*} block 数据块,可能是单个内容块,可能是Page
* @param {*} type block 单个内容块 ; collection 集合列表
* @param {*} from 来自
* @returns
*/
const mapImgUrl = (img, block, type = 'block', from = 'post') => {
const mapImgUrl = (img, block, type = 'block', needCompress = true) => {
if (!img) {
return null
}

let ret = null
// 相对目录,则视为notion的自带图片
if (img.startsWith('/')) {
Expand All @@ -22,12 +24,16 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
}

// Notion 图床转换为永久地址
const isNotionSignImg =
ret.indexOf('https://www.notion.so/image') !== 0 &&
const hasConverted = ret.indexOf('https://www.notion.so/image') === 0
// 需要转化的URL ; 识别aws图床地址,或者bookmark类型的外链图片
const needConvert =
!hasConverted &&
(ret.indexOf('secure.notion-static.com') > 0 ||
ret.indexOf('prod-files-secure') > 0)
const isImgBlock = BLOG.IMG_URL_TYPE === 'Notion' || type !== 'block'
if (isNotionSignImg && isImgBlock) {
ret.indexOf('prod-files-secure') > 0 ||
block.type === 'bookmark')

// 使用Notion图传
if (needConvert) {
ret =
BLOG.NOTION_HOST +
'/image/' +
Expand Down Expand Up @@ -60,19 +66,19 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
}

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

// 统一压缩图片
if (
from === 'pageCoverThumbnail' ||
block?.type === 'image' ||
block?.type === 'page'
) {
if (needCompress) {
const width = block?.format?.block_width
ret = compressImage(ret, width)
}
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const nextConfig = {
'ko-fi.com'
]
},

// 默认将feed重定向至 /public/rss/feed.xml
async redirects() {
return [
Expand Down
2 changes: 1 addition & 1 deletion themes/hexo/components/Hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Hero = props => {
<div className='text-white absolute bottom-0 flex flex-col h-full items-center justify-center w-full '>
{/* 站点标题 */}
<div className='font-black text-4xl md:text-5xl shadow-text'>
{siteConfig('TITLE')}
{siteInfo?.title || siteConfig('TITLE')}
</div>
{/* 站点欢迎语 */}
<div className='mt-2 h-12 items-center text-center font-medium shadow-text text-lg'>
Expand Down
13 changes: 11 additions & 2 deletions themes/hexo/components/Logo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { siteConfig } from '@/lib/config'
import Link from 'next/link'

/**
* Logo
* 实际值支持文字
* @param {*} props
* @returns
*/
const Logo = props => {
const { siteInfo } = props
return (
<Link href='/' passHref legacyBehavior>
<div className='flex flex-col justify-center items-center cursor-pointer space-y-3'>
<div className='font-medium text-lg p-1.5 rounded dark:border-white dark:text-white menu-link transform duration-200'> {siteConfig('TITLE') }</div>
<div className='font-medium text-lg p-1.5 rounded dark:border-white dark:text-white menu-link transform duration-200'>
{' '}
{siteInfo?.title || siteConfig('TITLE')}
</div>
</div>
</Link>
)
Expand Down
6 changes: 3 additions & 3 deletions themes/hexo/components/MenuItemCollapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export const MenuItemCollapse = props => {
return (
<>
<div
className='w-full px-8 py-3 text-left dark:bg-hexo-black-gray'
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'
onClick={toggleShow}>
{!hasSubMenu && (
<Link
href={link?.to}
target={link?.target}
className='font-extralight flex justify-between pl-2 pr-4 dark:text-gray-200 no-underline tracking-widest pb-1'>
className=' font-extralight flex justify-between pl-2 pr-4 dark:text-gray-200 no-underline tracking-widest pb-1'>
<span className=' transition-all items-center duration-200'>
{link?.icon && <i className={link.icon + ' mr-4'} />}
{link?.name}
Expand Down Expand Up @@ -63,7 +63,7 @@ export const MenuItemCollapse = props => {
return (
<div
key={index}
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'>
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'>
<Link href={sLink.to} target={link?.target}>
<span className='text-sm ml-4 whitespace-nowrap'>
{link?.icon && <i className={sLink.icon + ' mr-2'} />}{' '}
Expand Down
10 changes: 7 additions & 3 deletions themes/hexo/components/MenuItemDrop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Link from 'next/link'
import { useState } from 'react'

/**
* 支持二级展开的菜单
* @param {*} param0
* @returns
*/
export const MenuItemDrop = ({ link }) => {
const [show, changeShow] = useState(false)
const hasSubMenu = link?.subMenus?.length > 0
Expand All @@ -25,7 +29,7 @@ export const MenuItemDrop = ({ link }) => {

{hasSubMenu && (
<>
<div className='cursor-pointer menu-link pl-2 pr-4 no-underline tracking-widest pb-1'>
<div className='cursor-pointer menu-link pl-2 pr-4 no-underline tracking-widest pb-1'>
{link?.icon && <i className={link?.icon} />} {link?.name}
<i
className={`px-2 fa fa-angle-down duration-300 ${show ? 'rotate-180' : 'rotate-0'}`}></i>
Expand All @@ -42,7 +46,7 @@ export const MenuItemDrop = ({ link }) => {
return (
<li
key={index}
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'>
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'>
<Link href={sLink.to} target={link?.target}>
<span className='text-sm text-nowrap font-extralight'>
{link?.icon && <i className={sLink?.icon}> &nbsp; </i>}
Expand Down
48 changes: 37 additions & 11 deletions themes/hexo/components/MenuListSide.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
import { useGlobal } from '@/lib/global'
import { siteConfig } from '@/lib/config'
import { MenuItemCollapse } from './MenuItemCollapse'
import { useGlobal } from '@/lib/global'
import CONFIG from '../config'

export const MenuListSide = (props) => {
import { MenuItemCollapse } from './MenuItemCollapse'
/**
* 侧拉抽屉菜单
* @param {*} props
* @returns
*/
export const MenuListSide = props => {
const { customNav, customMenu } = props
const { locale } = useGlobal()

let links = [
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: siteConfig('HEXO_MENU_ARCHIVE', null, CONFIG) },
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: siteConfig('HEXO_MENU_SEARCH', null, CONFIG) },
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('HEXO_MENU_CATEGORY', null, CONFIG) },
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('HEXO_MENU_TAG', null, CONFIG) }
{
icon: 'fas fa-archive',
name: locale.NAV.ARCHIVE,
to: '/archive',
show: siteConfig('HEXO_MENU_ARCHIVE', null, CONFIG)
},
{
icon: 'fas fa-search',
name: locale.NAV.SEARCH,
to: '/search',
show: siteConfig('HEXO_MENU_SEARCH', null, CONFIG)
},
{
icon: 'fas fa-folder',
name: locale.COMMON.CATEGORY,
to: '/category',
show: siteConfig('HEXO_MENU_CATEGORY', null, CONFIG)
},
{
icon: 'fas fa-tag',
name: locale.COMMON.TAGS,
to: '/tag',
show: siteConfig('HEXO_MENU_TAG', null, CONFIG)
}
]

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

return (
<nav>
{links?.map((link, index) => <MenuItemCollapse key={index} link={link} />)}
</nav>
<nav>
{links?.map((link, index) => (
<MenuItemCollapse key={index} link={link} />
))}
</nav>
)
}
37 changes: 24 additions & 13 deletions themes/hexo/components/SideBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { siteConfig } from '@/lib/config'
import LazyImage from '@/components/LazyImage'
import { siteConfig } from '@/lib/config'
import { useRouter } from 'next/router'
import MenuGroupCard from './MenuGroupCard'
import { MenuListSide } from './MenuListSide'
Expand All @@ -11,22 +11,33 @@ import { MenuListSide } from './MenuListSide'
* @returns {JSX.Element}
* @constructor
*/
const SideBar = (props) => {
const SideBar = props => {
const { siteInfo } = props
const router = useRouter()
return (
<div id='side-bar'>
<div className="h-52 w-full flex justify-center">
<div>
<div onClick={() => { router.push('/') }}
className='justify-center items-center flex hover:rotate-45 py-6 hover:scale-105 dark:text-gray-100 transform duration-200 cursor-pointer'>
<LazyImage src={siteInfo?.icon} className='rounded-full' width={80} alt={siteConfig('AUTHOR')} />
</div>
<MenuGroupCard {...props} />
</div>
</div>
<MenuListSide {...props} />
<div id='side-bar'>
<div className='h-52 w-full flex justify-center'>
<div>
<div
onClick={() => {
router.push('/')
}}
className='justify-center items-center flex hover:rotate-45 py-6 hover:scale-105 dark:text-gray-100 transform duration-200 cursor-pointer'>
{/* 头像 */}
<LazyImage
src={siteInfo?.icon}
className='rounded-full'
width={80}
alt={siteConfig('AUTHOR')}
/>
</div>
{/* 总览 */}
<MenuGroupCard {...props} />
</div>
</div>
{/* 侧拉抽屉的菜单 */}
<MenuListSide {...props} />
</div>
)
}

Expand Down
Loading

0 comments on commit 26a535c

Please sign in to comment.