mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
Next主题可隐藏头图,并显示icon
This commit is contained in:
20
components/NotionIcon.js
Normal file
20
components/NotionIcon.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* notion的图标icon
|
||||
* 可能是emoji 可能是 svg 也可能是 图片
|
||||
* @returns
|
||||
*/
|
||||
const NotionIcon = ({ icon }) => {
|
||||
if (!icon) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
if (icon.startsWith('http')) {
|
||||
// return <Image src={icon} width={30} height={30}/>
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
return <img src={icon} className='w-8 float-left mr-1'/>
|
||||
}
|
||||
|
||||
return <span className='mr-1'>{icon}</span>
|
||||
}
|
||||
|
||||
export default NotionIcon
|
||||
@@ -79,6 +79,7 @@ async function getPageProperties(id, block, schema, authToken, tagOptions, siteI
|
||||
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
||||
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)
|
||||
properties.fullWidth = value.format?.page_full_width ?? false
|
||||
properties.pageIcon = getPageIcon(id, block) ?? ''
|
||||
properties.page_cover = getPostCover(id, block) ?? siteInfo?.pageCover
|
||||
properties.content = value.content ?? []
|
||||
properties.tagItems = properties?.tags?.map(tag => {
|
||||
@@ -97,4 +98,13 @@ async function getPageProperties(id, block, schema, authToken, tagOptions, siteI
|
||||
}
|
||||
}
|
||||
|
||||
function getPageIcon(id, block) {
|
||||
const pageIcon = block[id].value?.format?.page_icon
|
||||
if (pageIcon) {
|
||||
if (pageIcon.startsWith('/')) return 'https://www.notion.so' + pageIcon
|
||||
if (pageIcon.startsWith('http')) return defaultMapImageUrl(pageIcon, block[id].value)
|
||||
return pageIcon
|
||||
}
|
||||
}
|
||||
|
||||
export { getPageProperties as default }
|
||||
|
||||
@@ -11,6 +11,8 @@ import { useRouter } from 'next/router'
|
||||
import ArticleCopyright from './ArticleCopyright'
|
||||
import WordCount from './WordCount'
|
||||
import NotionPage from '@/components/NotionPage'
|
||||
import CONFIG_NEXT from '../config_next'
|
||||
import NotionIcon from '@/components/NotionIcon'
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -29,7 +31,7 @@ export default function ArticleDetail(props) {
|
||||
>
|
||||
|
||||
{showArticleInfo && <header className='animate__slideInDown animate__animated'>
|
||||
{post?.type && !post?.type.includes('Page') && post?.page_cover && (
|
||||
{CONFIG_NEXT.POST_HEADER_IMAGE_VISIBLE && post?.type && !post?.type !== 'Page' && post?.page_cover && (
|
||||
<div className="w-full relative md:flex-shrink-0 overflow-hidden">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img alt={post.title} src={post?.page_cover} className='object-center w-full' />
|
||||
@@ -38,7 +40,7 @@ export default function ArticleDetail(props) {
|
||||
|
||||
{/* 文章Title */}
|
||||
<div className="font-bold text-3xl text-black dark:text-white font-serif pt-10">
|
||||
{post.title}
|
||||
<NotionIcon icon={post.pageIcon}/>{post.title}
|
||||
</div>
|
||||
|
||||
<section className="flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8">
|
||||
|
||||
@@ -7,6 +7,7 @@ import Card from './Card'
|
||||
import TagItemMini from './TagItemMini'
|
||||
import CONFIG_NEXT from '../config_next'
|
||||
import NotionPage from '@/components/NotionPage'
|
||||
import NotionIcon from '@/components/NotionIcon'
|
||||
|
||||
const BlogPostCard = ({ post, showSummary }) => {
|
||||
const { locale } = useGlobal()
|
||||
@@ -23,7 +24,7 @@ const BlogPostCard = ({ post, showSummary }) => {
|
||||
className={`cursor-pointer hover:underline text-3xl ${showPreview ? 'text-center' : ''
|
||||
} leading-tight text-gray-700 dark:text-gray-100 hover:text-blue-500 dark:hover:text-blue-400`}
|
||||
>
|
||||
{post.title}
|
||||
<NotionIcon icon={post.pageIcon} /> {post.title}
|
||||
</a>
|
||||
</Link>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ const CONFIG_NEXT = {
|
||||
POST_LIST_PREVIEW: true, // 显示文章预览
|
||||
POST_LIST_SUMMARY: false, // 显示用户自定义摘要,有预览时优先只展示预览
|
||||
|
||||
POST_HEADER_IMAGE_VISIBLE: false, // 文章详情页是否显示封面图
|
||||
|
||||
// 右侧组件
|
||||
RIGHT_BAR: true, // 是否显示右侧栏
|
||||
RIGHT_LATEST_POSTS: true, // 右侧栏最新文章
|
||||
|
||||
Reference in New Issue
Block a user