From c2dc5ba47c5f0b3392fa87267c1a2008b0d1cb9e Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 5 Sep 2024 11:28:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?OPEN=5FWRITE=E5=AF=BC=E6=B5=81=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- components/OpenWrite.js | 60 +++++++++++++++++++++++++++++++++++++++++ lib/utils/index.js | 2 +- pages/[prefix]/index.js | 7 ++++- styles/globals.css | 4 +++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 components/OpenWrite.js diff --git a/.gitignore b/.gitignore index 42744c4b2cf..b400f485732 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 00000000000..f199e50eb59 --- /dev/null +++ b/components/OpenWrite.js @@ -0,0 +1,60 @@ +import { siteConfig } from '@/lib/config' +import { isBrowser, loadExternalResource } from '@/lib/utils' +import { useRouter } from 'next/router' +import { useEffect, useRef } 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 router = useRouter() + 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 hasLoaded = useRef(false) + + 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 && !hasLoaded.current) { + loadOpenWrite() + hasLoaded.current = true + } + }, [router]) + + return <> +} + +export default OpenWrite diff --git a/lib/utils/index.js b/lib/utils/index.js index 27a6494f4b9..7817ed74972 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/pages/[prefix]/index.js b/pages/[prefix]/index.js index dc480fcc531..2bb175b6dc7 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 bdc13fe97df..c3a4818e2cb 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -272,3 +272,7 @@ a.avatar-wrapper { margin-right: 20px; } } + +img { + display: unset; +} From 218d1fa37e421bdab08f1dd131f13dcc819d3b3b Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 5 Sep 2024 11:35:02 +0800 Subject: [PATCH 2/4] 4.7.0 --- .env.local | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.local b/.env.local index f2327cf8624..4d4824d5bb6 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/package.json b/package.json index 8d1c195f392..2e523fbcd40 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": { From c351b76c139955bb26436c2bcd1ddee76a15a1a3 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 5 Sep 2024 12:13:07 +0800 Subject: [PATCH 3/4] =?UTF-8?q?OpenWrite=E9=80=82=E9=85=8D=E6=89=80?= =?UTF-8?q?=E6=9C=89=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/OpenWrite.js | 9 +- themes/example/index.js | 8 +- themes/gitbook/index.js | 6 +- themes/heo/index.js | 9 +- themes/hexo/index.js | 5 +- themes/landing/index.js | 159 +++++--- themes/matery/index.js | 6 +- themes/medium/index.js | 466 +++++++++++++----------- themes/nav/index.js | 6 +- themes/next/components/ArticleDetail.js | 6 +- themes/next/index.js | 424 +++++++++++---------- themes/nobelium/index.js | 327 +++++++++-------- themes/plog/index.js | 281 +++++++------- themes/simple/index.js | 10 +- themes/starter/index.js | 4 +- 15 files changed, 961 insertions(+), 765 deletions(-) diff --git a/components/OpenWrite.js b/components/OpenWrite.js index f199e50eb59..00d001a966f 100644 --- a/components/OpenWrite.js +++ b/components/OpenWrite.js @@ -1,7 +1,7 @@ import { siteConfig } from '@/lib/config' import { isBrowser, loadExternalResource } from '@/lib/utils' import { useRouter } from 'next/router' -import { useEffect, useRef } from 'react' +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 @@ -20,8 +20,6 @@ const OpenWrite = () => { '原创不易,完成人机检测,阅读全文' ) - const hasLoaded = useRef(false) - const loadOpenWrite = async () => { try { await loadExternalResource( @@ -48,11 +46,10 @@ const OpenWrite = () => { } useEffect(() => { - if (isBrowser && blogId && !hasLoaded.current) { + if (isBrowser && blogId) { loadOpenWrite() - hasLoaded.current = true } - }, [router]) + }) return <> } diff --git a/themes/example/index.js b/themes/example/index.js index 90580a24f93..60b896c1f4f 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 ca82dd5265e..ceef6df4b98 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 b496ef20bfd..9bab5daffc8 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 d7301d4caaa..62d8f9db844 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, + Layout404, + LayoutArchive, LayoutBase, + LayoutCategoryIndex, LayoutIndex, + LayoutPostList, LayoutSearch, - LayoutArchive, LayoutSlug, - Layout404, - LayoutPostList, - LayoutCategoryIndex, - LayoutTagIndex + LayoutTagIndex, + CONFIG as THEME_CONFIG } diff --git a/themes/matery/index.js b/themes/matery/index.js index 9f642cabb5d..7cbcad19ddb 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样式 */} -