Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 9, 2024
2 parents 88c931d + 914443a commit c19f1f4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=4.7.4
NEXT_PUBLIC_VERSION=4.7.5


# 可在此添加环境变量,去掉最左边的(# )注释即可
Expand Down
45 changes: 41 additions & 4 deletions lib/db/getSiteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,47 @@ function handleDataBeforeReturn(db) {
db.allNavPages = shortenIds(db?.allNavPages)
// db.allPages = cleanBlocks(db?.allPages)

db.allNavPages = cleanPages(db?.allNavPages, db.tagOptions)
db.allPages = cleanPages(db.allPages, db.tagOptions)
db.latestPosts = cleanPages(db.latestPosts, db.tagOptions)
return db
}

/**
* 处理文章列表中的异常数据
* @param {Array} allPages - 所有页面数据
* @param {Array} tagOptions - 标签选项
* @returns {Array} 处理后的 allPages
*/
function cleanPages(allPages, tagOptions) {
// 校验参数是否为数组
if (!Array.isArray(allPages) || !Array.isArray(tagOptions)) {
console.warn('Invalid input: allPages and tagOptions should be arrays.')
return allPages || [] // 返回空数组或原始值
}

// 提取 tagOptions 中所有合法的标签名
const validTags = new Set(
tagOptions
.map(tag => (typeof tag.name === 'string' ? tag.name : null))
.filter(Boolean) // 只保留合法的字符串
)

// 遍历所有的 pages
allPages.forEach(page => {
// 确保 tagItems 是数组
if (Array.isArray(page.tagItems)) {
// 对每个 page 的 tagItems 进行过滤
page.tagItems = page.tagItems.filter(
tagItem =>
validTags.has(tagItem?.name) && typeof tagItem.name === 'string' // 校验 tagItem.name 是否是字符串
)
}
})

return allPages
}

/**
* 清理一组数据的id
* @param {*} items
Expand Down Expand Up @@ -237,16 +275,15 @@ function getCustomMenu({ collectionData, NOTION_CONFIG }) {
const menuPages = collectionData.filter(
post =>
post.status === 'Published' &&
(post?.type === BLOG.NOTION_PROPERTY_NAME.type_menu ||
post?.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu)
(post?.type === 'Menu' || post?.type === 'SubMenu')
)
const menus = []
if (menuPages && menuPages.length > 0) {
menuPages.forEach(e => {
e.show = true
if (e.type === BLOG.NOTION_PROPERTY_NAME.type_menu) {
if (e.type === 'Menu') {
menus.push(e)
} else if (e.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) {
} else if (e.type === 'SubMenu') {
const parentMenu = menus[menus.length - 1]
if (parentMenu) {
if (parentMenu.subMenus) {
Expand Down
27 changes: 16 additions & 11 deletions lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,25 @@ function convertToJSON(str) {
* 映射用户自定义表头
*/
function mapProperties(properties) {
if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_post) {
properties.type = 'Post'
const typeMap = {
[BLOG.NOTION_PROPERTY_NAME.type_post]: 'Post',
[BLOG.NOTION_PROPERTY_NAME.type_page]: 'Page',
[BLOG.NOTION_PROPERTY_NAME.type_notice]: 'Notice',
[BLOG.NOTION_PROPERTY_NAME.type_menu]: 'Menu',
[BLOG.NOTION_PROPERTY_NAME.type_sub_menu]: 'SubMenu'
}
if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_page) {
properties.type = 'Page'
}
if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_notice) {
properties.type = 'Notice'

const statusMap = {
[BLOG.NOTION_PROPERTY_NAME.status_publish]: 'Published',
[BLOG.NOTION_PROPERTY_NAME.status_invisible]: 'Invisible'
}
if (properties?.status === BLOG.NOTION_PROPERTY_NAME.status_publish) {
properties.status = 'Published'

if (properties?.type && typeMap[properties.type]) {
properties.type = typeMap[properties.type]
}
if (properties?.status === BLOG.NOTION_PROPERTY_NAME.status_invisible) {
properties.status = 'Invisible'

if (properties?.status && statusMap[properties.status]) {
properties.status = statusMap[properties.status]
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notion-next",
"version": "4.7.4",
"version": "4.7.5",
"homepage": "https://github.com/tangly1024/NotionNext.git",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions pages/page/[page].js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export async function getStaticPaths({ locale }) {
}
}

export async function getStaticProps({ params: { page } }) {
export async function getStaticProps({ params: { page }, locale }) {
const from = `page-${page}`
const props = await getGlobalData({ from })
const props = await getGlobalData({ from, locale })
const { allPages } = props
const POST_PREVIEW_LINES = siteConfig(
'POST_PREVIEW_LINES',
Expand Down
12 changes: 7 additions & 5 deletions themes/heo/components/Hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ function Banner(props) {
id='banners'
onClick={handleClickBanner}
className='hidden xl:flex xl:flex-col group h-full bg-white dark:bg-[#1e1e1e] rounded-xl border dark:border-gray-700 mb-3 relative overflow-hidden'>
<div id='banner-title' className='flex flex-col absolute top-10 left-10'>
<div
id='banner-title'
className='z-10 flex flex-col absolute top-10 left-10'>
<div className='text-4xl font-bold mb-3 dark:text-white'>
{siteConfig('HEO_HERO_TITLE_1', null, CONFIG)}
<br />
Expand Down Expand Up @@ -115,10 +117,10 @@ function Banner(props) {
* 英雄区左上角banner条中斜向滚动的图标
*/
function TagsGroupBar() {
const groupIcons = siteConfig('HEO_GROUP_ICONS', null, CONFIG).concat(
siteConfig('HEO_GROUP_ICONS', null, CONFIG)
)

let groupIcons = siteConfig('HEO_GROUP_ICONS', null, CONFIG)
if (groupIcons) {
groupIcons = groupIcons.concat(groupIcons)
}
return (
<div className='tags-group-all flex -rotate-[30deg] h-full'>
<div className='tags-group-wrapper flex flex-nowrap absolute top-16'>
Expand Down

0 comments on commit c19f1f4

Please sign in to comment.