diff --git a/.env.local b/.env.local index f2327cf8..4d4824d5 100644 --- a/.env.local +++ b/.env.local @@ -1,5 +1,5 @@ # 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables -NEXT_PUBLIC_VERSION=4.6.2 +NEXT_PUBLIC_VERSION=4.7.0 # 可在此添加环境变量,去掉最左边的(# )注释即可 diff --git a/.gitignore b/.gitignore index 42744c4b..b400f485 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,7 @@ yarn-error.log* /public/robots.txt /public/sitemap.xml /public/rss/* - +/sitemap.xml # yarn package-lock.json diff --git a/components/OpenWrite.js b/components/OpenWrite.js new file mode 100644 index 00000000..c5fd4a7a --- /dev/null +++ b/components/OpenWrite.js @@ -0,0 +1,61 @@ +import { siteConfig } from '@/lib/config' +import { isBrowser, loadExternalResource } from '@/lib/utils' +import { useEffect } from 'react' +/** + * OpenWrite公众号导流插件 + * 使用介绍:https://openwrite.cn/guide/readmore/readmore.html#%E4%BA%8C%E3%80%81%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8 + * 登录后台配置你的博客:https://readmore.openwrite.cn/ + * @returns + */ +const OpenWrite = () => { + const qrcode = siteConfig('OPEN_WRITE_QRCODE', '请配置公众号二维码') + const blogId = siteConfig('OPEN_WRITE_BLOG_ID') + const name = siteConfig('OPEN_WRITE_NAME', '请配置公众号名') + const id = 'article-wrapper' + const keyword = siteConfig('OPEN_WRITE_KEYWORD', '请配置公众号关键词') + const btnText = siteConfig( + 'OPEN_WRITE_BTN_TEXT', + '原创不易,完成人机检测,阅读全文' + ) + + const loadOpenWrite = async () => { + try { + await loadExternalResource( + 'https://readmore.openwrite.cn/js/readmore-2.0.js', + 'js' + ) + const BTWPlugin = window?.BTWPlugin + + if (BTWPlugin) { + const btw = new BTWPlugin() + window.btw = btw + btw.init({ + qrcode, + id, + name, + btnText, + keyword, + blogId + }) + } + } catch (error) { + console.error('OpenWrite 加载异常', error) + } + } + + useEffect(() => { + if (isBrowser && blogId) { + // Check if the element with id 'read-more-wrap' already exists + const readMoreWrap = document.getElementById('read-more-wrap') + + // Only load the script if the element doesn't exist + if (!readMoreWrap) { + loadOpenWrite() + } + } + }) + + return <> +} + +export default OpenWrite diff --git a/lib/utils/index.js b/lib/utils/index.js index 27a6494f..7817ed74 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -146,7 +146,7 @@ export function getLastPartOfUrl(url) { * @param type js 或 css * @returns {Promise} */ -export function loadExternalResource(url, type) { +export function loadExternalResource(url, type = 'js') { // 检查是否已存在 const elements = type === 'js' diff --git a/package.json b/package.json index 8d1c195f..2e523fbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "4.6.2", + "version": "4.7.0", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": { diff --git a/pages/[prefix]/index.js b/pages/[prefix]/index.js index dc480fcc..2bb175b6 100644 --- a/pages/[prefix]/index.js +++ b/pages/[prefix]/index.js @@ -1,5 +1,6 @@ import BLOG from '@/blog.config' import useNotification from '@/components/Notification' +import OpenWrite from '@/components/OpenWrite' import { siteConfig } from '@/lib/config' import { getGlobalData, getPost, getPostBlocks } from '@/lib/db/getSiteData' import { useGlobal } from '@/lib/global' @@ -95,8 +96,12 @@ const Slug = props => { }) return ( <> + {/* 文章布局 */} + {/* 解锁密码提示框 */} {post?.password && post?.password !== '' && !lock && } + {/* 导流工具 */} + ) } @@ -129,7 +134,7 @@ export async function getStaticProps({ params: { prefix }, locale }) { fullSlug += '.html' } } - + // 在列表内查找文章 props.post = props?.allPages?.find(p => { return ( diff --git a/styles/globals.css b/styles/globals.css index bdc13fe9..c3a4818e 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -272,3 +272,7 @@ a.avatar-wrapper { margin-right: 20px; } } + +img { + display: unset; +} diff --git a/themes/example/index.js b/themes/example/index.js index 90580a24..60b896c1 100644 --- a/themes/example/index.js +++ b/themes/example/index.js @@ -179,10 +179,12 @@ const LayoutSlug = props => { {lock ? ( ) : ( -
+
- - +
+ + +
)} diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index ca82dd52..ceef6df4 100644 --- a/themes/gitbook/index.js +++ b/themes/gitbook/index.js @@ -341,8 +341,10 @@ const LayoutSlug = props => { {/* Notion文章主体 */} {post && ( -
- +
+
+ +
{/* 分享 */} diff --git a/themes/heo/index.js b/themes/heo/index.js index b496ef20..9bab5daf 100644 --- a/themes/heo/index.js +++ b/themes/heo/index.js @@ -288,14 +288,17 @@ const LayoutSlug = props => { return ( <>
+ className={`article h-full w-full ${fullWidth ? '' : 'xl:max-w-5xl'} ${hasCode ? 'xl:w-[73.15vw]' : ''} bg-white dark:bg-[#18171d] dark:border-gray-600 lg:hover:shadow lg:border rounded-2xl lg:px-2 lg:py-4 `}> {/* 文章锁 */} {lock && } {!lock && ( -
+
{/* 文章主体 */} -
+
{/* Notion文章主体 */}
{ {lock && } {!lock && ( -
+
diff --git a/themes/landing/index.js b/themes/landing/index.js index d7301d4c..62d8f9db 100644 --- a/themes/landing/index.js +++ b/themes/landing/index.js @@ -1,4 +1,3 @@ - 'use client' /** @@ -7,21 +6,21 @@ * 2. 内容大部分是在此文件中写死,notion数据从props参数中传进来 * 3. 您可在此网站找到更多喜欢的组件 https://www.tailwind-kit.com/ */ +import Loading from '@/components/Loading' import NotionPage from '@/components/NotionPage' -import Header from './components/Header' -import Footer from './components/Footer' -import Hero from './components/Hero' +import { siteConfig } from '@/lib/config' +import { isBrowser } from '@/lib/utils' +import { useRouter } from 'next/router' +import { useEffect } from 'react' import Features from './components/Features' import FeaturesBlocks from './components/FeaturesBlocks' -import Testimonials from './components/Testimonials' +import Footer from './components/Footer' +import Header from './components/Header' +import Hero from './components/Hero' import Newsletter from './components/Newsletter' -import { useRouter } from 'next/router' -import CONFIG from './config' -import Loading from '@/components/Loading' -import { isBrowser } from '@/lib/utils' -import { siteConfig } from '@/lib/config' import { Pricing } from './components/Pricing' -import { useEffect } from 'react' +import Testimonials from './components/Testimonials' +import CONFIG from './config' /** * 布局框架 @@ -30,22 +29,23 @@ import { useEffect } from 'react' * @param {*} props * @returns */ -const LayoutBase = (props) => { +const LayoutBase = props => { const { children } = props - return
+ return ( +
+ {/* 顶部导航栏 */} +
- {/* 顶部导航栏 */} -
+ {/* 内容 */} +
{children}
- {/* 内容 */} -
- {children} -
- - {/* 底部页脚 */} -
+ {/* 底部页脚 */} +
+ ) } /** @@ -53,16 +53,16 @@ const LayoutBase = (props) => { * @param {*} props * @returns */ -const LayoutIndex = (props) => { +const LayoutIndex = props => { return ( - <> - - - - - - - + <> + + + + + + + ) } @@ -71,7 +71,7 @@ const LayoutIndex = (props) => { * @param {*} props * @returns */ -const LayoutSlug = (props) => { +const LayoutSlug = props => { const { post } = props // 如果 是 /article/[slug] 的文章路径则进行重定向到另一个域名 @@ -79,49 +79,90 @@ const LayoutSlug = (props) => { useEffect(() => { // 404 if (!post) { - setTimeout(() => { - if (isBrowser) { - const article = document.getElementById('notion-article') - if (!article) { - router.push('/404').then(() => { - console.warn('找不到页面', router.asPath) - }) + setTimeout( + () => { + if (isBrowser) { + const article = document.getElementById('notion-article') + if (!article) { + router.push('/404').then(() => { + console.warn('找不到页面', router.asPath) + }) + } } - } - }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000) + }, + siteConfig('POST_WAITING_TIME_FOR_404') * 1000 + ) } }, [post]) - if (JSON.parse(siteConfig('LANDING_POST_REDIRECT_ENABLE', null, CONFIG)) && isBrowser && router.route === '/[prefix]/[slug]') { - const redirectUrl = siteConfig('LANDING_POST_REDIRECT_URL', null, CONFIG) + router.asPath.replace('?theme=landing', '') + if ( + JSON.parse(siteConfig('LANDING_POST_REDIRECT_ENABLE', null, CONFIG)) && + isBrowser && + router.route === '/[prefix]/[slug]' + ) { + const redirectUrl = + siteConfig('LANDING_POST_REDIRECT_URL', null, CONFIG) + + router.asPath.replace('?theme=landing', '') router.push(redirectUrl) - return
+ return ( +
+ +
+ ) } - return <> -
- + return ( + <> +
+
+
+
+ ) } // 其他布局暂时留空 -const LayoutSearch = (props) => <> -const LayoutArchive = (props) => <> -const Layout404 = (props) => <> -const LayoutCategoryIndex = (props) => <> -const LayoutPostList = (props) => <> -const LayoutTagIndex = (props) => <> +const LayoutSearch = props => ( + <> + + +) +const LayoutArchive = props => ( + <> + + +) +const Layout404 = props => ( + <> + + +) +const LayoutCategoryIndex = props => ( + <> + + +) +const LayoutPostList = props => ( + <> + + +) +const LayoutTagIndex = props => ( + <> + + +) export { - CONFIG as THEME_CONFIG, - LayoutBase, - LayoutIndex, - LayoutSearch, - LayoutArchive, - LayoutSlug, Layout404, - LayoutPostList, + LayoutArchive, + LayoutBase, LayoutCategoryIndex, - LayoutTagIndex + LayoutIndex, + LayoutPostList, + LayoutSearch, + LayoutSlug, + LayoutTagIndex, + CONFIG as THEME_CONFIG } diff --git a/themes/matery/index.js b/themes/matery/index.js index 9f642cab..7cbcad19 100644 --- a/themes/matery/index.js +++ b/themes/matery/index.js @@ -254,9 +254,7 @@ const LayoutSlug = props => { {lock && } {!lock && ( -
+
{/* 文章信息 */} {post?.type && post?.type === 'Post' && ( <> @@ -268,7 +266,7 @@ const LayoutSlug = props => { )}
-
+
{/* Notion文章主体 */}
{ const router = useRouter() const [tocVisible, changeTocVisible] = useState(false) const { onLoading, fullWidth } = useGlobal() - const [slotRight, setSlotRight] = useState(null); + const [slotRight, setSlotRight] = useState(null) - useEffect(()=> { + useEffect(() => { if (post?.toc?.length > 0) { setSlotRight(
- ); + ) } else { - setSlotRight(null); + setSlotRight(null) } - },[post]) + }, [post]) const slotTop = return ( - - {/* CSS样式 */} -