Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 16, 2024
2 parents 69617e8 + 6411a78 commit 536478d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/db/getSiteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function getCustomMenu({ collectionData, NOTION_CONFIG }) {
e.to = e.slug
} else {
e.target = '_self'
if (e?.slug?.indexOf('/') !== 0) {
if (e?.slug?.indexOf('http') !== 0 && e?.slug?.indexOf('/') !== 0) {
e.to = '/' + e.slug
}
}
Expand Down
26 changes: 19 additions & 7 deletions lib/notion/getNotionPost.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BLOG from '@/blog.config'
import { idToUuid } from 'notion-utils'
import { defaultMapImageUrl } from 'react-notion-x'
import formatDate from '../utils/formatDate'
import { getPostBlocks } from './getPostBlocks'
import { defaultMapImageUrl } from 'react-notion-x'

/**
* 根据页面ID获取内容
Expand All @@ -23,11 +23,22 @@ export async function getPost(pageId) {
tags: [],
title: postInfo?.properties?.title?.[0],
status: 'Published',
createdTime: formatDate(new Date(postInfo.created_time).toString(), BLOG.LANG),
lastEditedDay: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG),
fullWidth: postInfo?.fullWidth,
page_cover: getPageCover(postInfo),
date: { start_date: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG) },
createdTime: formatDate(
new Date(postInfo.created_time).toString(),
BLOG.LANG
),
lastEditedDay: formatDate(
new Date(postInfo?.last_edited_time).toString(),
BLOG.LANG
),
fullWidth: postInfo?.fullWidth || false,
page_cover: getPageCover(postInfo) || BLOG.HOME_BANNER_IMAGE,
date: {
start_date: formatDate(
new Date(postInfo?.last_edited_time).toString(),
BLOG.LANG
)
},
blockMap
}
}
Expand All @@ -36,6 +47,7 @@ function getPageCover(postInfo) {
const pageCover = postInfo.format?.page_cover
if (pageCover) {
if (pageCover.startsWith('/')) return BLOG.NOTION_HOST + pageCover
if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, postInfo)
if (pageCover.startsWith('http'))
return defaultMapImageUrl(pageCover, postInfo)
}
}
56 changes: 44 additions & 12 deletions lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import { mapImgUrl } from './mapImage'
* @param {*} tagOptions
* @returns
*/
export default async function getPageProperties(id, value, schema, authToken, tagOptions) {
export default async function getPageProperties(
id,
value,
schema,
authToken,
tagOptions
) {
const rawProperties = Object.entries(value?.properties || [])
const excludeProperties = ['date', 'select', 'multi_select', 'person']
const properties = {}
Expand Down Expand Up @@ -49,7 +55,8 @@ export default async function getPageProperties(id, value, schema, authToken, ta
if (rawUsers[i][0][1]) {
const userId = rawUsers[i][0]
const res = await api.getUsers(userId)
const resValue = res?.recordMapWithRoles?.notion_user?.[userId[1]]?.value
const resValue =
res?.recordMapWithRoles?.notion_user?.[userId[1]]?.value
const user = {
id: resValue?.id,
first_name: resValue?.given_name,
Expand All @@ -72,7 +79,8 @@ export default async function getPageProperties(id, value, schema, authToken, ta
const fieldNames = BLOG.NOTION_PROPERTY_NAME
if (fieldNames) {
Object.keys(fieldNames).forEach(key => {
if (fieldNames[key] && properties[fieldNames[key]]) properties[key] = properties[fieldNames[key]]
if (fieldNames[key] && properties[fieldNames[key]])
properties[key] = properties[fieldNames[key]]
})
}

Expand All @@ -84,25 +92,41 @@ export default async function getPageProperties(id, value, schema, authToken, ta
// 映射值:用户个性化type和status字段的下拉框选项,在此映射回代码的英文标识
mapProperties(properties)

properties.publishDate = new Date(properties?.date?.start_date || value.created_time).getTime()
properties.publishDate = new Date(
properties?.date?.start_date || value.created_time
).getTime()
properties.publishDay = formatDate(properties.publishDate, BLOG.LANG)
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.lastEditedDay = formatDate(
new Date(value?.last_edited_time),
BLOG.LANG
)
properties.fullWidth = value?.format?.page_full_width ?? false
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.pageCoverThumbnail =
mapImgUrl(
value?.format?.page_cover,
value,
'block',
'pageCoverThumbnail'
) ?? ''
properties.ext = converToJSON(properties?.ext)
properties.content = value.content ?? []
properties.tagItems =
properties?.tags?.map(tag => {
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
return {
name: tag,
color: tagOptions?.find(t => t.value === tag)?.color || 'gray'
}
}) || []
delete properties.content

// 处理URL
if (properties.type === 'Post') {
properties.slug = BLOG.POST_URL_PREFIX ? generateCustomizeUrl(properties) : properties.slug ?? properties.id
properties.slug = BLOG.POST_URL_PREFIX
? generateCustomizeUrl(properties)
: properties.slug ?? properties.id
} else if (properties.type === 'Page') {
properties.slug = properties.slug ?? properties.id
} else if (properties.type === 'Menu' || properties.type === 'SubMenu') {
Expand All @@ -113,12 +137,17 @@ export default async function getPageProperties(id, value, schema, authToken, ta

// 开启伪静态路径
if (JSON.parse(BLOG.PSEUDO_STATIC)) {
if (!properties?.slug?.endsWith('.html') && !properties?.slug?.startsWith('http')) {
if (
!properties?.slug?.endsWith('.html') &&
!properties?.slug?.startsWith('http')
) {
properties.slug += '.html'
}
}
// 密码字段md5
properties.password = properties.password ? md5(properties.slug + properties.password) : ''
properties.password = properties.password
? md5(properties.slug + properties.password)
: ''
return properties
}

Expand Down Expand Up @@ -177,7 +206,10 @@ function generateCustomizeUrl(postProperties) {
fullPrefix += formatPostCreatedDate.getUTCFullYear()
} else if (pattern === '%month%' && postProperties?.publishDay) {
const formatPostCreatedDate = new Date(postProperties?.publishDay)
fullPrefix += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0)
fullPrefix += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(
2,
0
)
} else if (pattern === '%day%' && postProperties?.publishDay) {
const formatPostCreatedDate = new Date(postProperties?.publishDay)
fullPrefix += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
Expand Down
5 changes: 3 additions & 2 deletions styles/notion.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
line-height: 1.5;
color: var(--fg-color);
caret-color: var(--fg-color);
font-family: inherit;
font-family: inherit !important;
}

.notion > * {
Expand Down Expand Up @@ -2064,7 +2064,8 @@ code.language-mermaid {
border: 1px solid var(#eee) !important;
}

/* 竖屏视频高度bug */
/* 视频尺寸bug */
figure.notion-asset-wrapper.notion-asset-wrapper-video > div {
height: 100% !important;
width: 100% !important;
}
2 changes: 1 addition & 1 deletion themes/game/components/GameListIndexCombine.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const GameItem = ({ item, isLargeCard }) => {
<Link
title={title}
href={`${url}`}
className={`card-single ${isLargeCard ? 'h-80 ' : 'h-full text-xs'} w-full transition-all duration-200 hover:scale-105 shadow-md hover:shadow-lg relative rounded-lg overflow-hidden flex justify-center items-center
className={`card-single ${isLargeCard ? 'h-80 ' : 'h-full text-xs'} w-full transition-all duration-200 shadow-md md:hover:scale-105 md:hover:shadow-lg relative rounded-lg overflow-hidden flex justify-center items-center
group hover:border-purple-400`}
onMouseOver={() => {
setShowType('video')
Expand Down

0 comments on commit 536478d

Please sign in to comment.