diff --git a/.env.local b/.env.local index bcee941c..76272843 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.2 +NEXT_PUBLIC_VERSION=3.12.3 diff --git a/README.md b/README.md index a985ae42..44220cd3 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,9 @@ Pylogmon
派了个萌

🔧 🐛 - SkysCrystal
Simon Shi -

🔧 🐛 + SkysCrystal
Simon Shi

🔧 🐛 + + S.Y. Lee
S.Y. Lee

🔧 🐛 diff --git a/blog.config.js b/blog.config.js index 2449cc31..14dcc2da 100644 --- a/blog.config.js +++ b/blog.config.js @@ -214,6 +214,9 @@ const BLOG = { icon: process.env.NEXT_PUBLIC_NOTION_PROPERTY_ICON || 'icon' }, + // RSS + ENABLE_RSS: process.env.NEXT_PUBLIC_ENABLE_RSS || true, // 是否开启RSS订阅功能 + // 作废配置 AVATAR: process.env.NEXT_PUBLIC_AVATAR || '/avatar.png', // 作者头像,被notion中的ICON覆盖。若无ICON则取public目录下的avatar.png TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖 diff --git a/components/ExternalScript.js b/components/ExternalScript.js index a168caab..f1672b16 100644 --- a/components/ExternalScript.js +++ b/components/ExternalScript.js @@ -1,12 +1,13 @@ import BLOG from '@/blog.config' -import { isBrowser, loadExternalResource } from '@/lib/utils' +import { loadExternalResource } from '@/lib/utils' +import { useEffect } from 'react' /** * 自定义引入外部JS 和 CSS * @returns */ const ExternalScript = () => { - if (isBrowser()) { + useEffect(() => { // 静态导入本地自定义样式 loadExternalResource(BLOG.FONT_AWESOME, 'css') loadExternalResource('/css/custom.css', 'css') @@ -25,7 +26,7 @@ const ExternalScript = () => { BLOG.FONT_URL?.forEach(e => { loadExternalResource(e, 'css') }) - } + }, []) return null } diff --git a/lib/robots.txt.js b/lib/robots.txt.js new file mode 100644 index 00000000..917796d7 --- /dev/null +++ b/lib/robots.txt.js @@ -0,0 +1,19 @@ + +import fs from 'fs' +import BLOG from '@/blog.config' + +export async function generateRobotsTxt() { + fs.mkdirSync('./public/rss', { recursive: true }) + fs.writeFileSync('./public/robots.txt', ` + # * + User-agent: * + Allow: / + + # Host + Host: ${BLOG.LINK} + + # Sitemaps + Sitemap: ${BLOG.LINK}/sitemap.xml + + `) +} diff --git a/lib/rss.js b/lib/rss.js index 68214659..66723f93 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -5,21 +5,6 @@ import ReactDOMServer from 'react-dom/server' import { getPostBlocks } from './notion' import NotionPage from '@/components/NotionPage' -const createFeedContent = async post => { - // 加密的文章内容只返回摘要 - if (post.password && post.password !== '') { - return post.summary - } - const blockMap = await getPostBlocks(post.id, 'rss-content') - if (blockMap) { - post.blockMap = blockMap - const content = ReactDOMServer.renderToString() - const regexExp = - /
.*?<\/svg>
.*?<\/div><\/div>
.*?<\/div><\/div><\/div><\/div>/g - return content.replace(regexExp, '') - } -} - export async function generateRss(posts) { const year = new Date().getFullYear() const feed = new Feed({ @@ -38,7 +23,6 @@ export async function generateRss(posts) { for (const post of posts) { feed.addItem({ title: post.title, - guid: `${post.id}`, link: `${BLOG.LINK}/${post.slug}`, description: post.summary, content: await createFeedContent(post), @@ -51,3 +35,23 @@ export async function generateRss(posts) { fs.writeFileSync('./public/rss/atom.xml', feed.atom1()) fs.writeFileSync('./public/rss/feed.json', feed.json1()) } + +/** + * 生成RSS内容 + * @param {*} post + * @returns + */ +const createFeedContent = async post => { + // 加密的文章内容只返回摘要 + if (post.password && post.password !== '') { + return post.summary + } + const blockMap = await getPostBlocks(post.id, 'rss-content') + if (blockMap) { + post.blockMap = blockMap + const content = ReactDOMServer.renderToString() + const regexExp = + /
.*?<\/svg>
.*?<\/div><\/div>
.*?<\/div><\/div><\/div><\/div>/g + return content.replace(regexExp, '') + } +} diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js new file mode 100644 index 00000000..0e057610 --- /dev/null +++ b/lib/sitemap.xml.js @@ -0,0 +1,57 @@ + +import fs from 'fs' +import BLOG from '@/blog.config' + +export async function generateSitemapXml({ allPages }) { + fs.mkdirSync('./public', { recursive: true }) + + const urls = [{ + loc: `${BLOG.LINK}`, + lastmod: new Date().toISOString().split('T')[0], + changefreq: 'daily' + }, { + loc: `${BLOG.LINK}/archive`, + lastmod: new Date().toISOString().split('T')[0], + changefreq: 'daily' + }, { + loc: `${BLOG.LINK}/category`, + lastmod: new Date().toISOString().split('T')[0], + changefreq: 'daily' + }, { + loc: `${BLOG.LINK}/tag`, + lastmod: new Date().toISOString().split('T')[0], + changefreq: 'daily' + }] + + allPages?.forEach(post => { + urls.push({ + loc: `${BLOG.LINK}/${post.slug}`, + lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0], + changefreq: 'daily' + }) + }) + const xml = createSitemapXml(urls) + fs.writeFileSync('./public/sitemap.xml', xml) +} + +function createSitemapXml(urls) { + let urlsXml = '' + urls.forEach(u => { + urlsXml += ` + ${u.loc} + ${u.lastmod} + ${u.changefreq} + + ` + }) + + return ` + + ${urlsXml} + + ` +} diff --git a/next.config.js b/next.config.js index 33b66908..65fde6e7 100644 --- a/next.config.js +++ b/next.config.js @@ -11,7 +11,9 @@ module.exports = withBundleAnalyzer({ 'gravatar.com', 'www.notion.so', 'avatars.githubusercontent.com', - 'images.unsplash.com' + 'images.unsplash.com', + 'source.unsplash.com', + 'p1.qhimg.com' ] }, // 默认将feed重定向至 /public/rss/feed.xml diff --git a/package.json b/package.json index 09316777..9a539f00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.12.2", + "version": "3.12.3", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": { diff --git a/pages/_app.js b/pages/_app.js index ce4cfd54..41feba71 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -58,12 +58,12 @@ const MyApp = ({ Component, pageProps }) => { useEffect(() => { AOS.init() smoothscroll.polyfill() - }) + }, []) return ( - {externalPlugins} + {externalPlugins} ) } diff --git a/pages/index.js b/pages/index.js index a26d57bd..663462fd 100644 --- a/pages/index.js +++ b/pages/index.js @@ -4,6 +4,8 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import * as ThemeMap from '@/themes' import { useGlobal } from '@/lib/global' import { generateRss } from '@/lib/rss' +import { generateRobotsTxt } from '@/lib/robots.txt' +import { generateSitemapXml } from '@/lib/sitemap.xml' const Index = props => { const { theme } = useGlobal() const ThemeComponents = ThemeMap[theme] @@ -17,7 +19,6 @@ export async function getStaticProps() { const { siteInfo } = props props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published') - delete props.allPages const meta = { title: `${siteInfo?.title} | ${siteInfo?.description}`, description: siteInfo?.description, @@ -43,8 +44,16 @@ export async function getStaticProps() { } } - // 异步生成Feed订阅 - generateRss(props?.latestPosts || []) + // 生成Feed订阅 + if (JSON.parse(BLOG.ENABLE_RSS)) { + generateRss(props?.latestPosts || []) + } + // 生成robotTxt + generateRobotsTxt() + // 生成sitemap.xml + generateSitemapXml({ allPages: props.allPages }) + + delete props.allPages return { props: { diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js deleted file mode 100644 index 17980067..00000000 --- a/pages/sitemap.xml.js +++ /dev/null @@ -1,60 +0,0 @@ -// pages/sitemap.xml.js -import { getServerSideSitemap } from 'next-sitemap' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import BLOG from '@/blog.config' - -export const getServerSideProps = async (ctx) => { - const { allPages } = await getGlobalNotionData({ from: 'rss' }) - const defaultFields = [ - { - loc: `${BLOG.LINK}`, - lastmod: new Date().toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - }, { - loc: `${BLOG.LINK}/archive`, - lastmod: new Date().toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - }, { - loc: `${BLOG.LINK}/category`, - lastmod: new Date().toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - }, { - loc: `${BLOG.LINK}/feed`, - lastmod: new Date().toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - }, { - loc: `${BLOG.LINK}/search`, - lastmod: new Date().toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - }, { - loc: `${BLOG.LINK}/tag`, - lastmod: new Date().toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - } - ] - const postFields = allPages?.map(post => { - return { - loc: `${BLOG.LINK}/${post.slug}`, - lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0], - changefreq: 'daily', - priority: '0.7' - } - }) - const fields = defaultFields.concat(postFields) - - // 缓存 - // ctx.res.setHeader( - // 'Cache-Control', - // 'public, s-maxage=10, stale-while-revalidate=59' - // ) - - return getServerSideSitemap(ctx, fields) -} - -export default () => { } diff --git a/public/bg_image.jpg b/public/bg_image.jpg old mode 100644 new mode 100755 index d602ff36..191b9554 Binary files a/public/bg_image.jpg and b/public/bg_image.jpg differ diff --git a/styles/globals.css b/styles/globals.css index 69097839..569fbfc6 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -167,6 +167,13 @@ nav { -webkit-box-orient: vertical; } +.waline-recent-content .wl-emoji { + height: 1.1rem !important; + display: inline-block !important; + line-height: 1.25rem !important; + vertical-align: text-bottom !important; +} + .vcontent .wl-emoji { display: inline-block; vertical-align: baseline; diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index a9ec3442..701daa71 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -14,7 +14,13 @@ import dynamic from 'next/dynamic' const FacebookPage = dynamic( () => { - return import('@/components/FacebookPage') + let facebook = <> + try { + facebook = import('@/components/FacebookPage') + } catch (err) { + console.error(err) + } + return facebook }, { ssr: false } ) @@ -59,14 +65,14 @@ const LayoutBase = props => { }, []) return ( -
+
{headerSlot} -
+
{ const headerSlot = CONFIG_HEXO.HOME_BANNER_ENABLE &&
return - {BLOG.POST_LIST_STYLE === 'page' ? : } } diff --git a/themes/hexo/components/Announcement.js b/themes/hexo/components/Announcement.js index 18cb3f8a..391fd3a8 100644 --- a/themes/hexo/components/Announcement.js +++ b/themes/hexo/components/Announcement.js @@ -6,12 +6,7 @@ const NotionPage = dynamic(() => import('@/components/NotionPage')) const Announcement = ({ post, className }) => { const { locale } = useGlobal() if (post?.blockMap) { - return
+ return
{locale.COMMON.ANNOUNCEMENT}
{post && (
diff --git a/themes/hexo/components/BlogPostCard.js b/themes/hexo/components/BlogPostCard.js index 895a77ec..02940295 100644 --- a/themes/hexo/components/BlogPostCard.js +++ b/themes/hexo/components/BlogPostCard.js @@ -4,6 +4,7 @@ import React from 'react' import TagItemMini from './TagItemMini' import CONFIG_HEXO from '../config_hexo' import NotionPage from '@/components/NotionPage' +import Image from 'next/image' const BlogPostCard = ({ post, showSummary, siteInfo }) => { const showPreview = CONFIG_HEXO.POST_LIST_PREVIEW && post.blockMap @@ -15,6 +16,7 @@ const BlogPostCard = ({ post, showSummary, siteInfo }) => {
{
{showPageCover && !showPreview && post?.page_cover && ( -
+
{/* eslint-disable-next-line @next/next/no-img-element */} - {post.title} - {/* {post.title} */} + className="w-full cursor-pointer object-cover duration-200 hover:scale-125 " + /> */} +
+ {post.title} +
)} diff --git a/themes/hexo/components/Header.js b/themes/hexo/components/Header.js index 7f38552e..d6fff722 100644 --- a/themes/hexo/components/Header.js +++ b/themes/hexo/components/Header.js @@ -1,3 +1,4 @@ +import Image from 'next/image' import { useEffect, useState } from 'react' import Typed from 'typed.js' import CONFIG_HEXO from '../config_hexo' @@ -45,7 +46,7 @@ const Header = props => { } }) - function updateHeaderHeight () { + function updateHeaderHeight() { requestAnimationFrame(() => { const wrapperElement = document.getElementById('wrapper') wrapperTop = wrapperElement?.offsetTop @@ -53,32 +54,36 @@ const Header = props => { } return ( - ) } @@ -104,12 +109,12 @@ const scrollTrigger = () => { ) { autoScroll = true window.scrollTo({ top: wrapperTop, behavior: 'smooth' }) - requestAnimationFrame(autoScrollEnd) + autoScrollEnd() } if ((scrollS < windowTop) && (scrollS < window.innerHeight) && !autoScroll) { autoScroll = true window.scrollTo({ top: 0, behavior: 'smooth' }) - requestAnimationFrame(autoScrollEnd) + autoScrollEnd() } windowTop = scrollS }) diff --git a/themes/hexo/components/LatestPostsGroup.js b/themes/hexo/components/LatestPostsGroup.js index 9e799aa9..009e91cb 100644 --- a/themes/hexo/components/LatestPostsGroup.js +++ b/themes/hexo/components/LatestPostsGroup.js @@ -1,5 +1,6 @@ import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' +import Image from 'next/image' import Link from 'next/link' import { useRouter } from 'next/router' @@ -19,46 +20,51 @@ const LatestPostsGroup = ({ latestPosts, siteInfo }) => { } return <> -
-
- - {locale.COMMON.LATEST_POSTS} -
-
- {latestPosts.map(post => { - const selected = currentPath === `${BLOG.SUB_PATH}/${post.slug}` - const headerImage = post?.page_cover - ? `url("${post.page_cover}")` - : `url("${siteInfo?.pageCover}")` - - return ( - ( - -
-
+
-
{post.title}
-
{post.lastEditedTime}
+ + {locale.COMMON.LATEST_POSTS}
-
+
+ {latestPosts.map(post => { + const selected = currentPath === `${BLOG.SUB_PATH}/${post.slug}` - ) - ) - })} - + const headerImage = post?.page_cover ? post.page_cover : siteInfo?.pageCover + + return ( + ( + +
+ {post.title} +
+
+
+
{post.title}
+
{post.lastEditedTime}
+
+
+ + ) + ) + })} + } export default LatestPostsGroup diff --git a/themes/hexo/components/TopNav.js b/themes/hexo/components/TopNav.js index 374f59ce..d3fe3f1b 100644 --- a/themes/hexo/components/TopNav.js +++ b/themes/hexo/components/TopNav.js @@ -61,7 +61,7 @@ const TopNav = props => { nav && nav.classList.replace('transparent', 'dark:bg-hexo-black-gray') } - const showNav = scrollS <= windowTop || scrollS < 5 || (header && scrollS <= header.clientHeight)// 非首页无大图时影藏顶部 滚动条置顶时隐藏 + const showNav = scrollS <= windowTop || scrollS < 5 || (header && scrollS <= header.clientHeight * 2)// 非首页无大图时影藏顶部 滚动条置顶时隐藏 if (!showNav) { nav && nav.classList.replace('top-0', '-top-20') windowTop = scrollS diff --git a/themes/matery/LayoutBase.js b/themes/matery/LayoutBase.js index 4a1bbc51..9fcd9849 100644 --- a/themes/matery/LayoutBase.js +++ b/themes/matery/LayoutBase.js @@ -23,18 +23,11 @@ const LayoutBase = props => { const scrollListener = () => { requestAnimationFrame(() => { - // const targetRef = document.getElementById('wrapper') - // const clientHeight = targetRef?.clientHeight const scrollY = window.pageYOffset - // const fullHeight = clientHeight - window.outerHeight - // let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0)) - // if (per > 100) per = 100 const shouldShow = scrollY > 300 - console.log(scrollY) if (shouldShow !== show) { switchShow(shouldShow) } - // changePercent(per) }) } useEffect(() => { diff --git a/themes/matery/components/BlogPostCard.js b/themes/matery/components/BlogPostCard.js index b809c723..e7da2f17 100644 --- a/themes/matery/components/BlogPostCard.js +++ b/themes/matery/components/BlogPostCard.js @@ -3,6 +3,7 @@ import Link from 'next/link' import React from 'react' import TagItemMini from './TagItemMini' import CONFIG_MATERY from '../config_matery' +import Image from 'next/image' const BlogPostCard = ({ post, showSummary, siteInfo }) => { const showPreview = CONFIG_MATERY.POST_LIST_PREVIEW && post.blockMap @@ -14,7 +15,7 @@ const BlogPostCard = ({ post, showSummary, siteInfo }) => { return (
@@ -27,11 +28,22 @@ const BlogPostCard = ({ post, showSummary, siteInfo }) => {
{/* eslint-disable-next-line @next/next/no-img-element */} - {post.title} + /> */} +
+ {post.title} +
{post.title}
diff --git a/themes/matery/components/Header.js b/themes/matery/components/Header.js index 5ad30675..b24ff85d 100644 --- a/themes/matery/components/Header.js +++ b/themes/matery/components/Header.js @@ -1,3 +1,4 @@ +import Image from 'next/image' import { useEffect, useState } from 'react' import Typed from 'typed.js' import CONFIG_MATERY from '../config_matery' @@ -49,9 +50,9 @@ const Header = props => { } /** - * 吸附滚动,移动端关闭 - * @returns - */ + * 吸附滚动,移动端关闭 + * @returns + */ const scrollTrigger = () => { requestAnimationFrame(() => { if (screen.width <= 768) { @@ -76,7 +77,7 @@ const Header = props => { }) } - function updateHeaderHeight () { + function updateHeaderHeight() { requestAnimationFrame(() => { const wrapperElement = document.getElementById('wrapper') wrapperTop = wrapperElement?.offsetTop @@ -84,26 +85,30 @@ const Header = props => { } return ( - ) } diff --git a/themes/matery/components/HeaderArticle.js b/themes/matery/components/HeaderArticle.js index 6d8229c3..62317d06 100644 --- a/themes/matery/components/HeaderArticle.js +++ b/themes/matery/components/HeaderArticle.js @@ -1,3 +1,5 @@ +import Image from 'next/image' + export default function HeaderArticle({ post, siteInfo }) { const headerImage = post?.page_cover ? post?.page_cover : siteInfo?.pageCover const title = post?.title @@ -9,11 +11,16 @@ export default function HeaderArticle({ post, siteInfo }) { data-aos-anchor-placement="top-center" id='header' className="flex h-96 justify-center align-middle items-center w-full relative duration-200 bg-black"> {/* eslint-disable-next-line @next/next/no-img-element */} - {title} + /> */} + {title} {title}
) diff --git a/themes/matery/components/TopNav.js b/themes/matery/components/TopNav.js index 47b485a8..73086b76 100644 --- a/themes/matery/components/TopNav.js +++ b/themes/matery/components/TopNav.js @@ -27,7 +27,7 @@ const TopNav = props => { const scrollS = window.scrollY const nav = document.querySelector('#sticky-nav') const header = document.querySelector('#header') - const showNav = scrollS <= windowTop || scrollS < 5 // 非首页无大图时影藏顶部 滚动条置顶时隐藏 + const showNav = scrollS <= windowTop || scrollS < 5 || (header && scrollS <= header.clientHeight * 2)// 非首页无大图时影藏顶部 滚动条置顶时隐藏// 非首页无大图时影藏顶部 滚动条置顶时隐藏 // 是否将导航栏透明 const navTransparent = header && scrollS < 300 // 透明导航条的条件 diff --git a/themes/next/components/ShareBar.js b/themes/next/components/ShareBar.js index 2f174b13..c595da13 100644 --- a/themes/next/components/ShareBar.js +++ b/themes/next/components/ShareBar.js @@ -8,17 +8,17 @@ import { useGlobal } from '@/lib/global' import CONFIG_NEXT from '../config_next' const ShareBar = ({ post }) => { + const router = useRouter() + const [qrCodeShow, setQrCodeShow] = React.useState(false) + const { locale } = useGlobal() if (!CONFIG_NEXT.ARTICLE_SHARE) { return <> } - const router = useRouter() const shareUrl = BLOG.LINK + router.asPath // 二维码悬浮 - const [qrCodeShow, setQrCodeShow] = React.useState(false) const btnRef = React.createRef() const popoverRef = React.createRef() - const { locale } = useGlobal() const openPopover = () => { createPopper(btnRef.current, popoverRef.current, { @@ -57,7 +57,7 @@ const ShareBar = ({ post }) => {
-
+
diff --git a/themes/next/config_next.js b/themes/next/config_next.js index db098307..5504b8df 100644 --- a/themes/next/config_next.js +++ b/themes/next/config_next.js @@ -30,7 +30,7 @@ const CONFIG_NEXT = { WIDGET_DARK_MODE: false, // 显示日间/夜间模式切换 WIDGET_TOC: true, // 移动端显示悬浮目录 - ARTICLE_SHARE: false, // 文章分享功能 + ARTICLE_SHARE: process.env.NEXT_PUBLIC_ARTICLE_SHARE || false, // 文章分享功能 ARTICLE_RELATE_POSTS: true, // 相关文章推荐 ARTICLE_COPYRIGHT: true // 文章版权声明 diff --git a/themes/nobelium/components/Nav.js b/themes/nobelium/components/Nav.js index 6c6951ea..a0594ebf 100644 --- a/themes/nobelium/components/Nav.js +++ b/themes/nobelium/components/Nav.js @@ -75,7 +75,7 @@ const NavBar = props => { const { locale } = useGlobal() let links = [ - { id: 2, name: locale.NAV.RSS, to: '/feed', show: CONFIG_NOBELIUM.MENU_RSS, target: '_blank' }, + { id: 2, name: locale.NAV.RSS, to: '/feed', show: BLOG.ENABLE_RSS && CONFIG_NOBELIUM.MENU_RSS, target: '_blank' }, { icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_NOBELIUM.MENU_SEARCH }, { icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_NOBELIUM.MENU_ARCHIVE }, { icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_NOBELIUM.MENU_CATEGORY },