From 771819985aee595157182fc6dceb5293f27ffdfd Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 14 Dec 2022 13:47:14 +0800 Subject: [PATCH] encrypt-password --- lib/notion/getNotionData.js | 5 ++--- lib/notion/getPageProperties.js | 2 ++ package.json | 1 + pages/[...slug].js | 3 ++- themes/medium/LayoutCategory.js | 2 +- themes/medium/LayoutTag.js | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 11913b2d..80444cdb 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -212,17 +212,16 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { collectionData.push(properties) } } - // 读取映射 配置 - let postCount = 0 // 获取page作为自定义菜单 const customNav = getCustomNav({ allPages: collectionData.filter(post => post.type === 'Page' && post.status === 'Published') }) + // 文章计数 + let postCount = 0 const allPages = collectionData.filter(post => { if (post.type === 'Post' && post.status === 'Published') { postCount++ } - return post && post.type && (post.type === 'Post' || post.type === 'Page') && diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index f4ee3282..ef93f84b 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -3,6 +3,7 @@ import { NotionAPI } from 'notion-client' import BLOG from '@/blog.config' import formatDate from '../formatDate' import { defaultMapImageUrl } from 'react-notion-x' +import md5 from 'js-md5' export default async function getPageProperties(id, block, schema, authToken, tagOptions, siteInfo) { const rawProperties = Object.entries(block?.[id]?.value?.properties || []) @@ -89,6 +90,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta properties.pageIcon = getImageUrl(block[id].value?.format?.page_icon, block[id].value) ?? '' properties.page_cover = getImageUrl(block[id].value?.format?.page_cover, block[id].value) ?? siteInfo?.pageCover properties.content = value.content ?? [] + properties.password = properties.password ? md5(properties.slug + properties.password) : '' properties.tagItems = properties?.tags?.map(tag => { return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' } }) || [] diff --git a/package.json b/package.json index c9e3b948..f022f9d0 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "feed": "^4.2.2", "gitalk": "^1.7.2", + "js-md5": "^0.7.3", "localStorage": "^1.0.4", "lodash.throttle": "^4.1.1", "mark.js": "^8.11.1", diff --git a/pages/[...slug].js b/pages/[...slug].js index cae6d4b1..9d521d8f 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -8,6 +8,7 @@ import { idToUuid, getPageTableOfContents } from 'notion-utils' import Router from 'next/router' import { isBrowser } from '@/lib/utils' import { getNotion } from '@/lib/notion/getNotion' +import md5 from 'js-md5' /** * 根据notion的slug访问页面 @@ -57,7 +58,7 @@ const Slug = props => { * @param {*} result */ const validPassword = passInput => { - if (passInput && passInput === post.password) { + if (passInput && md5(post.slug + passInput) === post.password) { setLock(false) return true } diff --git a/themes/medium/LayoutCategory.js b/themes/medium/LayoutCategory.js index a3018144..7522e264 100644 --- a/themes/medium/LayoutCategory.js +++ b/themes/medium/LayoutCategory.js @@ -5,7 +5,7 @@ import BLOG from '@/blog.config' export const LayoutCategory = props => { const { category } = props - const slotTop =
分类:
{category}
+ const slotTop =
分类:
{category}
return {BLOG.POST_LIST_STYLE === 'page' ? : } diff --git a/themes/medium/LayoutTag.js b/themes/medium/LayoutTag.js index 6f072aa9..41164ce3 100644 --- a/themes/medium/LayoutTag.js +++ b/themes/medium/LayoutTag.js @@ -5,7 +5,7 @@ import BlogPostListPage from './components/BlogPostListPage' export const LayoutTag = (props) => { const { tag } = props - const slotTop =
标签:
{tag}
+ const slotTop =
标签:
{tag}
return {BLOG.POST_LIST_STYLE === 'page' ? : }