mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-05 23:16:52 +00:00
Merge pull request #2352 from tangly1024/feat/next-images-domains
Feat/next images domains
This commit is contained in:
@@ -105,12 +105,7 @@ export default async function getPageProperties(
|
|||||||
properties.pageIcon = mapImgUrl(value?.format?.page_icon, value) ?? ''
|
properties.pageIcon = mapImgUrl(value?.format?.page_icon, value) ?? ''
|
||||||
properties.pageCover = mapImgUrl(value?.format?.page_cover, value) ?? ''
|
properties.pageCover = mapImgUrl(value?.format?.page_cover, value) ?? ''
|
||||||
properties.pageCoverThumbnail =
|
properties.pageCoverThumbnail =
|
||||||
mapImgUrl(
|
mapImgUrl(value?.format?.page_cover, value, 'block') ?? ''
|
||||||
value?.format?.page_cover,
|
|
||||||
value,
|
|
||||||
'block',
|
|
||||||
'pageCoverThumbnail'
|
|
||||||
) ?? ''
|
|
||||||
properties.ext = converToJSON(properties?.ext)
|
properties.ext = converToJSON(properties?.ext)
|
||||||
properties.content = value.content ?? []
|
properties.content = value.content ?? []
|
||||||
properties.tagItems =
|
properties.tagItems =
|
||||||
|
|||||||
@@ -3,16 +3,18 @@ import { siteConfig } from '../config'
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片映射
|
* 图片映射
|
||||||
* 1. 如果是 /xx.xx 相对路径格式,则转化为 完整notion域名图片
|
*
|
||||||
* 2. 如果是 bookmark类型的block 图片封面无需处理
|
* @param {*} img 图片地址,可能是相对路径,可能是外链
|
||||||
* @param {*} img
|
* @param {*} block 数据块,可能是单个内容块,可能是Page
|
||||||
* @param {*} value
|
* @param {*} type block 单个内容块 ; collection 集合列表
|
||||||
|
* @param {*} from 来自
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const mapImgUrl = (img, block, type = 'block', from = 'post') => {
|
const mapImgUrl = (img, block, type = 'block', needCompress = true) => {
|
||||||
if (!img) {
|
if (!img) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = null
|
let ret = null
|
||||||
// 相对目录,则视为notion的自带图片
|
// 相对目录,则视为notion的自带图片
|
||||||
if (img.startsWith('/')) {
|
if (img.startsWith('/')) {
|
||||||
@@ -22,17 +24,21 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notion 图床转换为永久地址
|
// Notion 图床转换为永久地址
|
||||||
const isNotionSignImg =
|
const hasConverted = ret.indexOf('https://www.notion.so/image') === 0
|
||||||
ret.indexOf('https://www.notion.so/image') !== 0 &&
|
// 需要转化的URL ; 识别aws图床地址,或者bookmark类型的外链图片
|
||||||
|
const needConvert =
|
||||||
|
!hasConverted &&
|
||||||
(ret.indexOf('secure.notion-static.com') > 0 ||
|
(ret.indexOf('secure.notion-static.com') > 0 ||
|
||||||
ret.indexOf('prod-files-secure') > 0)
|
ret.indexOf('prod-files-secure') > 0 ||
|
||||||
const isImgBlock = BLOG.IMG_URL_TYPE === 'Notion' || type !== 'block'
|
block.type === 'bookmark')
|
||||||
if (isNotionSignImg && isImgBlock) {
|
|
||||||
|
// 使用Notion图传
|
||||||
|
if (needConvert) {
|
||||||
ret =
|
ret =
|
||||||
BLOG.NOTION_HOST +
|
BLOG.NOTION_HOST +
|
||||||
'/image/' +
|
'/image/' +
|
||||||
encodeURIComponent(ret) +
|
encodeURIComponent(ret) +
|
||||||
'?table=' +
|
'?table=block' +
|
||||||
type +
|
type +
|
||||||
'&id=' +
|
'&id=' +
|
||||||
block.id
|
block.id
|
||||||
@@ -60,7 +66,11 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 图片url优化,确保每一篇文章的图片url唯一
|
// 图片url优化,确保每一篇文章的图片url唯一
|
||||||
if (ret && ret.length > 4) {
|
if (
|
||||||
|
ret &&
|
||||||
|
ret.length > 4 &&
|
||||||
|
!ret.includes('https://www.notion.so/images/')
|
||||||
|
) {
|
||||||
// 图片接口拼接唯一识别参数,防止请求的图片被缓,而导致随机结果相同
|
// 图片接口拼接唯一识别参数,防止请求的图片被缓,而导致随机结果相同
|
||||||
const separator = ret.includes('?') ? '&' : '?'
|
const separator = ret.includes('?') ? '&' : '?'
|
||||||
ret = `${ret.trim()}${separator}t=${block.id}`
|
ret = `${ret.trim()}${separator}t=${block.id}`
|
||||||
@@ -68,11 +78,7 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 统一压缩图片
|
// 统一压缩图片
|
||||||
if (
|
if (needCompress) {
|
||||||
from === 'pageCoverThumbnail' ||
|
|
||||||
block?.type === 'image' ||
|
|
||||||
block?.type === 'page'
|
|
||||||
) {
|
|
||||||
const width = block?.format?.block_width
|
const width = block?.format?.block_width
|
||||||
ret = compressImage(ret, width)
|
ret = compressImage(ret, width)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,21 +54,6 @@ function scanSubdirectories(directory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
images: {
|
|
||||||
// 图片压缩
|
|
||||||
formats: ['image/avif', 'image/webp'],
|
|
||||||
// 允许next/image加载的图片 域名
|
|
||||||
domains: [
|
|
||||||
'gravatar.com',
|
|
||||||
'www.notion.so',
|
|
||||||
'avatars.githubusercontent.com',
|
|
||||||
'images.unsplash.com',
|
|
||||||
'source.unsplash.com',
|
|
||||||
'p1.qhimg.com',
|
|
||||||
'webmention.io',
|
|
||||||
'ko-fi.com'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// 默认将feed重定向至 /public/rss/feed.xml
|
// 默认将feed重定向至 /public/rss/feed.xml
|
||||||
async redirects() {
|
async redirects() {
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user