video-size

This commit is contained in:
tangly1024.com
2024-04-15 14:47:36 +08:00
parent dd9e30a177
commit 6fea7d3aba
3 changed files with 65 additions and 20 deletions

View File

@@ -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 = {}
@@ -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,
@@ -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]]
})
}
@@ -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') {
@@ -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
}
@@ -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)