From 4020cd5d483f8a506bc61043006d2574dc1cef30 Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 13 Mar 2023 01:30:31 +0800 Subject: [PATCH 1/7] feat(post): support customize post's permalink format --- blog.config.js | 4 +++- lib/notion/getPageProperties.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/blog.config.js b/blog.config.js index 14dcc2da..03632139 100644 --- a/blog.config.js +++ b/blog.config.js @@ -67,8 +67,10 @@ const BLOG = { BACKGROUND_DARK: '#000000', // use hex value, don't forget '#' SUB_PATH: '', // leave this empty unless you want to deploy in a folder - POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article', // POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug] + POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article/%year%/%month%/%day%', + // POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug] // 如果此项配置为 '' 空, 则文章将没有前缀路径,使用场景: 希望文章前缀路径为 /post 的情况 支持多级 + // 支援類似 WP 可自訂文章連結格式的功能:https://wordpress.org/documentation/article/customize-permalinks/,目前只先實作 %year%/%month%/%day% POST_LIST_STYLE: process.env.NEXT_PUBLIC_PPOST_LIST_STYLE || 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载 POST_LIST_PREVIEW: process.env.NEXT_PUBLIC_POST_PREVIEW || 'false', // 是否在列表加载文章预览 diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 0a328868..ea3171c3 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -77,7 +77,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta mapProperties(properties) if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_post) { - properties.slug = BLOG.POST_URL_PREFIX ? (BLOG.POST_URL_PREFIX + '/' + (properties.slug ?? properties.id)) : (properties.slug ?? properties.id) + properties.slug = (BLOG.POST_URL_PREFIX) ? generateCustomizeUrl(properties) : (properties.slug ?? properties.id) } else if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_page) { properties.slug = properties.slug ?? properties.id } else if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_menu || properties.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) { @@ -147,3 +147,30 @@ function mapProperties(properties) { properties.status = 'Invisible' } } + +function generateCustomizeUrl(postProperties) { + let fullSlug = '' + const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/') + allSlugPatterns.forEach((pattern, idx) => { + if (pattern === '%year%' && postProperties?.date?.start_date) { + const formatPostCreatedDate = new Date(postProperties?.date?.start_date) + fullSlug += formatPostCreatedDate.getUTCFullYear() + } else if (pattern === '%month%' && postProperties?.date?.start_date) { + const formatPostCreatedDate = new Date(postProperties?.date?.start_date) + fullSlug += (formatPostCreatedDate.getUTCMonth() + 1) + } else if (pattern === '%day%' && postProperties?.date?.start_date) { + const formatPostCreatedDate = new Date(postProperties?.date?.start_date) + fullSlug += formatPostCreatedDate.getUTCDate() + } else if (pattern === '%slug%') { + fullSlug += (postProperties.slug ?? postProperties.id) + } else if (!pattern.includes('%')) { + fullSlug += pattern + } else { + return + } + if (idx !== allSlugPatterns.length - 1) { + fullSlug += '/' + } + }) + return `${fullSlug}/${(postProperties.slug ?? postProperties.id)}` +} From 35a388d996d4b56c366381d7f98b3f2277498503 Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 13 Mar 2023 17:03:00 +0800 Subject: [PATCH 2/7] deps: fixed #791, upgrade react-notion-x to the latest 6.16.0 version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a539f00..55ad0eaf 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "react-dom": "^18.2.0", "react-facebook": "^8.1.4", "react-messenger-customer-chat": "^0.8.0", - "react-notion-x": "6.15.8", + "react-notion-x": "6.16.0", "react-share": "^4.4.0", "react-tweet-embed": "~2.0.0", "smoothscroll-polyfill": "^0.4.4", From b49686bb03cf36f68405ab15df4e97cd812523d4 Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 13 Mar 2023 20:24:34 +0800 Subject: [PATCH 3/7] chore: use padStart on month/date to keep a better output format --- lib/notion/getPageProperties.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index ea3171c3..0ba6a3bd 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -157,10 +157,10 @@ function generateCustomizeUrl(postProperties) { fullSlug += formatPostCreatedDate.getUTCFullYear() } else if (pattern === '%month%' && postProperties?.date?.start_date) { const formatPostCreatedDate = new Date(postProperties?.date?.start_date) - fullSlug += (formatPostCreatedDate.getUTCMonth() + 1) + fullSlug += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0) } else if (pattern === '%day%' && postProperties?.date?.start_date) { const formatPostCreatedDate = new Date(postProperties?.date?.start_date) - fullSlug += formatPostCreatedDate.getUTCDate() + fullSlug += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0) } else if (pattern === '%slug%') { fullSlug += (postProperties.slug ?? postProperties.id) } else if (!pattern.includes('%')) { From 6d67b56a82e71896de5992204b1adbc819b302b8 Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 13 Mar 2023 20:25:20 +0800 Subject: [PATCH 4/7] chore: rollback NEXT_PUBLIC_POST_URL_PREFIX value to keep the same behavior --- blog.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blog.config.js b/blog.config.js index 03632139..e2db2fb0 100644 --- a/blog.config.js +++ b/blog.config.js @@ -67,10 +67,11 @@ const BLOG = { BACKGROUND_DARK: '#000000', // use hex value, don't forget '#' SUB_PATH: '', // leave this empty unless you want to deploy in a folder - POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article/%year%/%month%/%day%', + POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article', // POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug] // 如果此项配置为 '' 空, 则文章将没有前缀路径,使用场景: 希望文章前缀路径为 /post 的情况 支持多级 // 支援類似 WP 可自訂文章連結格式的功能:https://wordpress.org/documentation/article/customize-permalinks/,目前只先實作 %year%/%month%/%day% + // 例:如想連結改成前綴 article + 時間戳記,可變更為: 'article/%year%/%month%/%day%' POST_LIST_STYLE: process.env.NEXT_PUBLIC_PPOST_LIST_STYLE || 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载 POST_LIST_PREVIEW: process.env.NEXT_PUBLIC_POST_PREVIEW || 'false', // 是否在列表加载文章预览 From 6772b8777c25af85c7333f6e326d3c811363a657 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Wed, 15 Mar 2023 09:42:00 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=9C=86=E8=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/css/img-shadow.css | 1 + 1 file changed, 1 insertion(+) diff --git a/public/css/img-shadow.css b/public/css/img-shadow.css index ab674c1e..ea7bfdff 100644 --- a/public/css/img-shadow.css +++ b/public/css/img-shadow.css @@ -1,4 +1,5 @@ /* 图片阴影 */ #notion-article img{ box-shadow: rgba(50, 50, 93, 0.25) 0px 13px 27px -5px, rgba(0, 0, 0, 0.3) 0px 8px 16px -8px; + border-radius: 0.5rem; } From fc2276812106ba9a13b31482f6e0af0356e77dac Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Wed, 15 Mar 2023 09:52:57 +0800 Subject: [PATCH 6/7] hexo animate --- themes/hexo/components/BlogPostCard.js | 6 ++++++ themes/hexo/components/BlogPostCardInfo.js | 12 ++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/themes/hexo/components/BlogPostCard.js b/themes/hexo/components/BlogPostCard.js index 1f02e323..52cfa885 100644 --- a/themes/hexo/components/BlogPostCard.js +++ b/themes/hexo/components/BlogPostCard.js @@ -11,9 +11,15 @@ const BlogPostCard = ({ index, post, showSummary, siteInfo }) => { post.page_cover = siteInfo?.pageCover } const showPageCover = CONFIG_HEXO.POST_LIST_COVER && post?.page_cover + const delay = (index % 2) * 200 return (
{ - const delay = (index % 2) * 200 +export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary }) => { + return
- return
- {/* 标题 */} Date: Wed, 15 Mar 2023 09:58:28 +0800 Subject: [PATCH 7/7] 3.12.4 --- .env.local | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.local b/.env.local index 76272843..5c68a5c9 100644 --- a/.env.local +++ b/.env.local @@ -1,2 +1,2 @@ # 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables -NEXT_PUBLIC_VERSION=3.12.3 +NEXT_PUBLIC_VERSION=3.12.4 diff --git a/package.json b/package.json index 55ad0eaf..2412a5c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.12.3", + "version": "3.12.4", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": {