Skip to content

Commit

Permalink
Merge pull request #1834 from tangly1024/fix/heo-cover-post
Browse files Browse the repository at this point in the history
Fix/heo cover post
  • Loading branch information
tangly1024 committed Jan 30, 2024
2 parents 9e48df7 + ad24ea1 commit 6ed1000
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 71 deletions.
8 changes: 7 additions & 1 deletion lib/notion/getNotionData.js
Expand Up @@ -273,10 +273,15 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {

const viewIds = rawMetadata?.view_ids
const collectionData = []

const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
if (pageIds?.length === 0) {
console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, collectionView, viewIds, pageRecordMap)
} else {
console.log('有效Page数量', pageIds?.length)
}

// 获取每篇文章基础数据
for (let i = 0; i < pageIds.length; i++) {
const id = pageIds[i]
const value = block[id]?.value
Expand All @@ -291,7 +296,8 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
}
continue
}
const properties = (await getPageProperties(id, block[id].value, schema, null, getTagOptions(schema))) || null

const properties = (await getPageProperties(id, value, schema, null, getTagOptions(schema))) || null
if (properties) {
collectionData.push(properties)
}
Expand Down
7 changes: 4 additions & 3 deletions lib/notion/getPageProperties.js
Expand Up @@ -90,9 +90,10 @@ export default async function getPageProperties(id, value, schema, authToken, ta
properties.lastEditedDate = new Date(value?.last_edited_time)
properties.lastEditedDay = formatDate(new Date(value?.last_edited_time), BLOG.LANG)
properties.fullWidth = value.format?.page_full_width ?? false
properties.pageIcon = mapImgUrl(value.value?.format?.page_icon, value.value) ?? ''
properties.pageCover = mapImgUrl(value.value?.format?.page_cover, value.value) ?? ''
properties.pageCoverThumbnail = mapImgUrl(value.value?.format?.page_cover, value.value, 'block', 'pageCoverThumbnail') ?? ''
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') ?? ''

properties.content = value.content ?? []
properties.tagItems = properties?.tags?.map(tag => {
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
Expand Down
1 change: 1 addition & 0 deletions lib/notion/getPostBlocks.js
Expand Up @@ -61,6 +61,7 @@ export async function getPageWithRetry(id, from, retryAttempts = 3) {
const authToken = BLOG.NOTION_ACCESS_TOKEN || null
const api = new NotionAPI({ authToken, userTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone })
const pageData = await api.getPage(id)
// console.log('stringfy', JSON.stringify(pageData))
console.info('[响应成功]:', `from:${from}`)
return pageData
} catch (e) {
Expand Down
7 changes: 3 additions & 4 deletions themes/example/index.js
Expand Up @@ -49,9 +49,9 @@ const LayoutBase = props => {
slotTop = <div className='pb-12'>#{tag}</div>
} else if (props.slotTop) {
slotTop = props.slotTop
} else if (router.route==='/search'){
// 嵌入一个搜索框在顶部
slotTop = <div className='pb-12'><SearchInput {...props} /></div>
} else if (router.route === '/search') {
// 嵌入一个搜索框在顶部
slotTop = <div className='pb-12'><SearchInput {...props} /></div>
}

// 增加一个状态以触发 Transition 组件的动画
Expand Down Expand Up @@ -136,7 +136,6 @@ const LayoutIndex = props => {
* @returns
*/
const LayoutPostList = props => {

return (
<>
{siteConfig('POST_LIST_STYLE') === 'page' ? <BlogListPage {...props} /> : <BlogListScroll {...props} />}
Expand Down
1 change: 0 additions & 1 deletion themes/gitbook/index.js
Expand Up @@ -31,7 +31,6 @@ import { Transition } from '@headlessui/react'
import { Style } from './style'
import CommonHead from '@/components/CommonHead'
import BlogArchiveItem from './components/BlogArchiveItem'
import BlogPostListPage from './components/BlogPostListPage'
import Link from 'next/link'
import dynamic from 'next/dynamic'
import { siteConfig } from '@/lib/config'
Expand Down
12 changes: 5 additions & 7 deletions themes/heo/index.js
Expand Up @@ -59,19 +59,20 @@ const LayoutBase = props => {
const { fullWidth } = useGlobal()
const router = useRouter()
console.log(router)

const headerSlot = (
<header>
{/* 顶部导航 */}
<div id="nav-bar-wrapper" className="h-16">
<NavBar {...props} />
</div>
{/* 通知横幅 */}
{router.route==='/' ? <>
{router.route === '/'
? <>
<NoticeBar />
<Hero {...props} />
</>
: null}
: null}
<div className="max-w-[86rem] mx-auto px-3">
<WWAds className="w-full" orientation="horizontal" />
</div>
Expand Down Expand Up @@ -159,7 +160,6 @@ const LayoutIndex = props => {
* @returns
*/
const LayoutPostList = props => {

return (
<div id="post-outer-wrapper" className="px-5 md:px-0">
{/* 文章分类条 */}
Expand All @@ -184,7 +184,7 @@ const LayoutSearch = props => {
const { keyword } = props
const router = useRouter()
const currentSearch = keyword || router?.query?.s

useEffect(() => {
// 高亮搜索结果
if (currentSearch) {
Expand Down Expand Up @@ -270,7 +270,6 @@ const LayoutSlug = props => {
setHasCode(hasCode)
}, [])


const commentEnable = siteConfig('COMMENT_TWIKOO_ENV_ID') || siteConfig('COMMENT_WALINE_SERVER_URL') || siteConfig('COMMENT_VALINE_APP_ID') ||
siteConfig('COMMENT_GISCUS_REPO') || siteConfig('COMMENT_CUSDIS_APP_ID') || siteConfig('COMMENT_UTTERRANCES_REPO') ||
siteConfig('COMMENT_GITALK_CLIENT_ID') || siteConfig('COMMENT_WEBMENTION_ENABLE')
Expand Down Expand Up @@ -428,7 +427,6 @@ const LayoutCategoryIndex = props => {
const { categoryOptions } = props
const { locale } = useGlobal()


return (
<div id="category-outer-wrapper" className="mt-8 px-5 md:px-0">
<div className="text-4xl font-extrabold dark:text-gray-200 mb-5">
Expand Down
2 changes: 1 addition & 1 deletion themes/hexo/components/TocDrawer.js
Expand Up @@ -21,7 +21,7 @@ const TocDrawer = ({ post, cRef }) => {
}
return <>
<div className='fixed top-0 right-0 z-40 '>
{/* 侧边菜单 */}
{/* 悬浮目录 */}
<div
className={(showDrawer ? 'animate__slideInRight ' : ' -mr-72 animate__slideOutRight') +
' shadow-card animate__animated animate__faster' +
Expand Down
26 changes: 14 additions & 12 deletions themes/hexo/index.js
Expand Up @@ -34,7 +34,6 @@ import replaceSearchResult from '@/components/Mark'
import { siteConfig } from '@/lib/config'
import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'


// 主题全局状态
const ThemeGlobalHexo = createContext()
export const useHexoGlobal = () => useContext(ThemeGlobalHexo)
Expand All @@ -46,14 +45,19 @@ export const useHexoGlobal = () => useContext(ThemeGlobalHexo)
* @constructor
*/
const LayoutBase = props => {
const { post , children, slotTop, meta, className } = props
const { post, children, slotTop, meta, className } = props
const { onLoading, fullWidth } = useGlobal()

const router = useRouter()
const headerSlot = post
? <PostHeader {...props} /> : (router.route==='/' && siteConfig('HEXO_HOME_BANNER_ENABLE', null, CONFIG)
? <Hero {...props} /> : null)

? <PostHeader {...props} />
: (router.route === '/' && siteConfig('HEXO_HOME_BANNER_ENABLE', null, CONFIG)
? <Hero {...props} />
: null)

const drawerRight = useRef(null)
const tocRef = isBrowser ? document.getElementById('article-wrapper') : null

const floatSlot = <>
{post?.toc?.length > 1 && <div className="block lg:hidden">
<TocDrawerButton
Expand Down Expand Up @@ -121,6 +125,10 @@ const LayoutBase = props => {
</div>
</main>

<div className='block lg:hidden'>
<TocDrawer post={post} cRef={drawerRight} targetRef={tocRef} />
</div>

{/* 悬浮菜单 */}
<RightFloatArea floatSlot={floatSlot} />

Expand All @@ -141,7 +149,7 @@ const LayoutBase = props => {
* @returns
*/
const LayoutIndex = (props) => {
return <LayoutPostList {...props} className='pt-8' />
return <LayoutPostList {...props} className='pt-8' />
}

/**
Expand Down Expand Up @@ -217,8 +225,6 @@ const LayoutArchive = (props) => {
*/
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const drawerRight = useRef(null)
const tocRef = isBrowser ? document.getElementById('article-wrapper') : null

return (
<>
Expand Down Expand Up @@ -252,10 +258,6 @@ const LayoutSlug = props => {
</div>}
</div>

<div className='block lg:hidden'>
<TocDrawer post={post} cRef={drawerRight} targetRef={tocRef} />
</div>

</>
)
}
Expand Down
9 changes: 5 additions & 4 deletions themes/matery/index.js
Expand Up @@ -43,9 +43,10 @@ const LayoutBase = props => {
const { children, meta, siteInfo, post } = props
const { onLoading, fullWidth } = useGlobal()
const router = useRouter()
const containerSlot= router.route==='/' ? <Announcement {...props} /> : <BlogListBar {...props} />
const headerSlot= siteConfig('MATERY_HOME_BANNER_ENABLE', null, CONFIG) && router.route==='/'
? <Hero {...props} /> : (post && !fullWidth ? <PostHeader {...props} /> : null)
const containerSlot = router.route === '/' ? <Announcement {...props} /> : <BlogListBar {...props} />
const headerSlot = siteConfig('MATERY_HOME_BANNER_ENABLE', null, CONFIG) && router.route === '/'
? <Hero {...props} />
: (post && !fullWidth ? <PostHeader {...props} /> : null)

const floatRightBottom = post ? <JumpToCommentButton /> : null

Expand Down Expand Up @@ -198,7 +199,7 @@ const LayoutArchive = (props) => {
const LayoutSlug = props => {
const { post, lock, validPassword } = props
const { fullWidth } = useGlobal()

return (<>

<div id='inner-wrapper' className={`w-full ${fullWidth ? '' : 'lg:max-w-3xl 2xl:max-w-4xl'}`} >
Expand Down
32 changes: 2 additions & 30 deletions themes/nav/index.js
Expand Up @@ -25,7 +25,6 @@ import { ArticleLock } from './components/ArticleLock'
import { Transition } from '@headlessui/react'
import { Style } from './style'
import CommonHead from '@/components/CommonHead'
import BlogArchiveItem from './components/BlogArchiveItem'
import BlogPostListAll from './components/BlogPostListAll'
import BlogPostCard from './components/BlogPostCard'
import Link from 'next/link'
Expand Down Expand Up @@ -271,14 +270,7 @@ const LayoutSearch = (props) => {
* @returns
*/
const LayoutArchive = (props) => {
return <div {...props}></div>
// const { archivePosts } = props

return <>
<div className="mb-10 pb-20 md:py-12 py-3 min-h-full">
{Object.keys(archivePosts)?.map(archiveTitle => <BlogArchiveItem key={archiveTitle} archiveTitle={archiveTitle} archivePosts={archivePosts} />)}
</div>
</>
return <></>
}

/**
Expand Down Expand Up @@ -325,27 +317,7 @@ const LayoutCategoryIndex = (props) => {
* 标签列表
*/
const LayoutTagIndex = (props) => {
return <div {...props}></div>
// const { tagOptions } = props
// const { locale } = useGlobal()

return <>
<div className="bg-white dark:bg-gray-700 py-10">
<div className="dark:text-gray-200 mb-5">
<i className="mr-4 fas fa-tag" />
{locale.COMMON.TAGS}:
</div>
<div id="tags-list" className="duration-200 flex flex-wrap">
{tagOptions?.map(tag => {
return (
<div key={tag.name} className="p-2">
<TagItemMini key={tag.name} tag={tag} />
</div>
)
})}
</div>
</div>
</>
return <></>
}

export {
Expand Down
6 changes: 3 additions & 3 deletions themes/next/index.js
Expand Up @@ -71,7 +71,7 @@ const LayoutBase = (props) => {
const drawerRight = useRef(null)
const floatSlot = <div className='block lg:hidden'>
<TocDrawerButton onClick={() => {
drawerRight?.current?.handleSwitchVisible()
drawerRight?.current?.handleSwitchVisible()
}} />
</div>
const tocRef = isBrowser ? document.getElementById('article-wrapper') : null
Expand Down Expand Up @@ -114,7 +114,7 @@ const LayoutBase = (props) => {

{/* 右侧栏样式 */}
{siteConfig('NEXT_RIGHT_BAR', null, CONFIG) && <SideAreaRight targetRef={targetRef} slot={rightAreaSlot} {...props} />}

</main>

{/* 悬浮目录按钮 */}
Expand Down Expand Up @@ -342,5 +342,5 @@ export {
Layout404,
LayoutCategoryIndex,
LayoutPostList,
LayoutTagIndex,
LayoutTagIndex
}
8 changes: 4 additions & 4 deletions themes/nobelium/index.js
Expand Up @@ -37,13 +37,13 @@ export const useNobeliumGlobal = () => useContext(ThemeGlobalNobelium)
* @constructor
*/
const LayoutBase = props => {
const { children, post, meta } = props
const { children, post, meta } = props
const fullWidth = post?.fullWidth ?? false
const { onLoading } = useGlobal()
const searchModal = useRef(null)
// 在列表中进行实时过滤
const [filterKey, setFilterKey] = useState('')
const topSlot= <BlogListBar {...props}/>
const topSlot = <BlogListBar {...props}/>

return (
<ThemeGlobalNobelium.Provider value={{ searchModal, filterKey, setFilterKey }}>
Expand Down Expand Up @@ -116,7 +116,7 @@ const LayoutIndex = props => {
* @returns
*/
const LayoutPostList = props => {
const { posts, topSlot,tag } = props
const { posts, topSlot, tag } = props
const { filterKey } = useNobeliumGlobal()
let filteredBlogPosts = []
if (filterKey && posts) {
Expand Down Expand Up @@ -160,7 +160,7 @@ const LayoutSearch = props => {
}, [])

// 在列表中进行实时过滤
const {filterKey} = useNobeliumGlobal()
const { filterKey } = useNobeliumGlobal()
let filteredBlogPosts = []
if (filterKey && posts) {
filteredBlogPosts = posts.filter(post => {
Expand Down
2 changes: 1 addition & 1 deletion themes/simple/index.js
Expand Up @@ -290,5 +290,5 @@ export {
Layout404,
LayoutCategoryIndex,
LayoutPostList,
LayoutTagIndex,
LayoutTagIndex
}

0 comments on commit 6ed1000

Please sign in to comment.