Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import BLOG from '@/blog.config'
import { getDateValue, getTextContent } from 'notion-utils'
import formatDate from '../utils/formatDate'
// import { createHash } from 'crypto'
import md5 from 'js-md5'
import { siteConfig } from '../config'
import {
checkStartWithHttp,
convertUrlStartWithOneSlash,
getLastSegmentFromUrl
} from '../utils'
import { checkStartWithHttp, convertUrlStartWithOneSlash, getLastSegmentFromUrl } from '../utils'
import { extractLangPrefix } from '../utils/pageId'
import { mapImgUrl } from './mapImage'
import notionAPI from '@/lib/notion/getNotionAPI'
import { isSHA256Digest, sha256Digest } from '@/lib/password'

/**
* 获取页面元素成员属性
Expand Down Expand Up @@ -223,10 +219,14 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
}
}

// 密码字段md5
properties.password = properties.password
? md5(properties.slug + properties.password)
: ''
// 密码字段 hash
if (properties.password) {
if (!isSHA256Digest(properties.password)) {
properties.password = sha256Digest(properties.password)
}
} else {
properties.password = ''
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions lib/password.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isBrowser } from './utils'
import sha256 from 'crypto-js/sha256'

/**
* 获取默认密码
Expand Down Expand Up @@ -35,3 +36,11 @@ export const getPasswordQuery = path => {

return passwords
}

export const sha256Digest = str => {
return sha256(str).toString()
}

export const isSHA256Digest = str => {
return /^[a-fA-F0-9]{64}$/.test(str)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"@vercel/analytics": "^1.0.0",
"algoliasearch": "^4.18.0",
"axios": "^1.7.2",
"crypto-js": "^4.2.0",
"feed": "^4.2.2",
"ioredis": "^5.4.2",
"js-md5": "^0.7.3",
"lodash.throttle": "^4.1.1",
"memory-cache": "^0.2.0",
"next": "14.2.4",
Expand Down
10 changes: 6 additions & 4 deletions pages/[prefix]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { siteConfig } from '@/lib/config'
import { getGlobalData, getPost } from '@/lib/db/getSiteData'
import { useGlobal } from '@/lib/global'
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
import { getPasswordQuery } from '@/lib/password'
import { getPasswordQuery, sha256Digest } from '@/lib/password'
import { checkSlugHasNoSlash, processPostData } from '@/lib/utils/post'
import { DynamicLayout } from '@/themes/theme'
import md5 from 'js-md5'
import { useRouter } from 'next/router'
import { idToUuid } from 'notion-utils'
import { useEffect, useState } from 'react'
Expand Down Expand Up @@ -36,11 +35,14 @@ const Slug = props => {
if (!post) {
return false
}
const encrypt = md5(post?.slug + passInput)
const encrypt = sha256Digest(passInput)
if (passInput && encrypt === post?.password) {
setLock(false)
// 输入密码存入localStorage,下次自动提交
localStorage.setItem('password_' + router.asPath, passInput)
localStorage.setItem(
'password_' + router.asPath.split(/[?#]/)[0],
passInput
)
showNotification(locale.COMMON.ARTICLE_UNLOCK_TIPS) // 设置解锁成功提示显示
return true
}
Expand Down
95 changes: 48 additions & 47 deletions themes/nobelium/components/ArticleInfo.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@

import Image from 'next/image'
import TagItem from './TagItem'
import md5 from 'js-md5'
import { siteConfig } from '@/lib/config'
import NotionIcon from '@/components/NotionIcon'
import { sha256Digest } from '@/lib/password'

export const ArticleInfo = (props) => {
export const ArticleInfo = props => {
const { post } = props

const emailHash = md5(siteConfig('CONTACT_EMAIL', '#'))

return <section className="flex-wrap flex mt-2 text-gray--600 dark:text-gray-400 font-light leading-8">
<div>

<h1 className="font-bold text-3xl text-black dark:text-white">
{siteConfig('POST_TITLE_ICON') && <NotionIcon icon={post?.pageIcon} />}{post?.title}
</h1>

{post?.type !== 'Page' && <>
<nav className="flex mt-7 items-start text-gray-500 dark:text-gray-400">
<div className="flex mb-4">
<a href={siteConfig('CONTACT_GITHUB', '#')} className="flex">
<Image
alt={siteConfig('AUTHOR')}
width={24}
height={24}
src={`https://gravatar.com/avatar/${emailHash}`}
className="rounded-full"
/>
<p className="ml-2 md:block">{siteConfig('AUTHOR')}</p>
</a>
<span className="block">&nbsp;/&nbsp;</span>
</div>
<div className="mr-2 mb-4 md:ml-0">
{post?.publishDay}
</div>
{post?.tags && (
<div className="flex flex-nowrap max-w-full overflow-x-auto article-tags">
{post?.tags.map(tag => (
<TagItem key={tag} tag={tag} />
))}
</div>
)}
<span className="hidden busuanzi_container_page_pv mr-2">
<i className='mr-1 fas fa-eye' />
&nbsp;
<span className="mr-2 busuanzi_value_page_pv" />
</span>
</nav>
</>}

</div>

const emailHash = sha256Digest(siteConfig('CONTACT_EMAIL', '#'))

return (
<section className='flex-wrap flex mt-2 text-gray--600 dark:text-gray-400 font-light leading-8'>
<div>
<h1 className='font-bold text-3xl text-black dark:text-white'>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post?.pageIcon} />
)}
{post?.title}
</h1>

{post?.type !== 'Page' && (
<>
<nav className='flex mt-7 items-start text-gray-500 dark:text-gray-400'>
<div className='flex mb-4'>
<a href={siteConfig('CONTACT_GITHUB', '#')} className='flex'>
<Image
alt={siteConfig('AUTHOR')}
width={24}
height={24}
src={`https://gravatar.com/avatar/${emailHash}`}
className='rounded-full'
/>
<p className='ml-2 md:block'>{siteConfig('AUTHOR')}</p>
</a>
<span className='block'>&nbsp;/&nbsp;</span>
</div>
<div className='mr-2 mb-4 md:ml-0'>{post?.publishDay}</div>
{post?.tags && (
<div className='flex flex-nowrap max-w-full overflow-x-auto article-tags'>
{post?.tags.map(tag => (
<TagItem key={tag} tag={tag} />
))}
</div>
)}
<span className='hidden busuanzi_container_page_pv mr-2'>
<i className='mr-1 fas fa-eye' />
&nbsp;
<span className='mr-2 busuanzi_value_page_pv' />
</span>
</nav>
</>
)}
</div>
</section>
)
}
93 changes: 47 additions & 46 deletions themes/plog/components/ArticleInfo.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@

import Image from 'next/image'
import TagItem from './TagItem'
import md5 from 'js-md5'
import { siteConfig } from '@/lib/config'
import NotionIcon from '@/components/NotionIcon'
import { sha256Digest } from '@/lib/password'

export const ArticleInfo = (props) => {
export const ArticleInfo = props => {
const { post } = props

const emailHash = md5(siteConfig('CONTACT_EMAIL', '#'))

return <section className="flex-wrap flex mt-2 text-gray--600 dark:text-gray-400 font-light leading-8">
<div>

<h1 className="font-bold text-3xl text-black dark:text-white">
{siteConfig('POST_TITLE_ICON') && <NotionIcon icon={post?.pageIcon} />}{post?.title}
</h1>

{post?.type !== 'Page' && <>
<nav className="flex mt-7 items-start text-gray-500 dark:text-gray-400">
<div className="flex mb-4">
<a href={siteConfig('CONTACT_GITHUB') || '#'} className="flex">
<Image
alt={siteConfig('AUTHOR')}
width={24}
height={24}
src={`https://gravatar.com/avatar/${emailHash}`}
className="rounded-full"
/>
<p className="ml-2 md:block">{siteConfig('AUTHOR')}</p>
</a>
<span className="block">&nbsp;/&nbsp;</span>
</div>
<div className="mr-2 mb-4 md:ml-0">
{post?.publishDay}
</div>
{post?.tags && (
<div className="flex flex-nowrap max-w-full overflow-x-auto article-tags">
{post?.tags.map(tag => (
<TagItem key={tag} tag={tag} />
))}
const emailHash = sha256Digest(siteConfig('CONTACT_EMAIL', '#'))

return (
<section className='flex-wrap flex mt-2 text-gray--600 dark:text-gray-400 font-light leading-8'>
<div>
<h1 className='font-bold text-3xl text-black dark:text-white'>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post?.pageIcon} />
)}
{post?.title}
</h1>

{post?.type !== 'Page' && (
<>
<nav className='flex mt-7 items-start text-gray-500 dark:text-gray-400'>
<div className='flex mb-4'>
<a href={siteConfig('CONTACT_GITHUB') || '#'} className='flex'>
<Image
alt={siteConfig('AUTHOR')}
width={24}
height={24}
src={`https://gravatar.com/avatar/${emailHash}`}
className='rounded-full'
/>
<p className='ml-2 md:block'>{siteConfig('AUTHOR')}</p>
</a>
<span className='block'>&nbsp;/&nbsp;</span>
</div>
)}
<span className="hidden busuanzi_container_page_pv mr-2">
<i className='mr-1 fas fa-eye' />
&nbsp;
<span className="mr-2 busuanzi_value_page_pv" />
</span>
</nav>
</>}

</div>

<div className='mr-2 mb-4 md:ml-0'>{post?.publishDay}</div>
{post?.tags && (
<div className='flex flex-nowrap max-w-full overflow-x-auto article-tags'>
{post?.tags.map(tag => (
<TagItem key={tag} tag={tag} />
))}
</div>
)}
<span className='hidden busuanzi_container_page_pv mr-2'>
<i className='mr-1 fas fa-eye' />
&nbsp;
<span className='mr-2 busuanzi_value_page_pv' />
</span>
</nav>
</>
)}
</div>
</section>
)
}
Loading