diff --git a/README.md b/README.md index 76fef972..169e221a 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ yarn run start # 本地启动NextJS服务 ## 致谢 感谢Craig Hart发起的Nobelium项目 - +
Craig Hart
Craig Hart
Craig Hart
Craig Hart
## 贡献者 diff --git a/blog.config.js b/blog.config.js index 90df2948..19720ff9 100644 --- a/blog.config.js +++ b/blog.config.js @@ -10,9 +10,13 @@ const BLOG = { NOTION_ACCESS_TOKEN: process.env.NOTION_ACCESS_TOKEN || '', // Useful if you prefer not to make your database public DEBUG: process.env.NEXT_PUBLIC_DEBUG || false, // 是否显示调试按钮 + // 一个小插件展示你的facebook fan page~ @see https://tw.andys.pro/article/add-facebook-fanpage-notionnext + FACEBOOK_PAGE_TITLE: + process.env.NEXT_PUBLIC_FACEBOOK_PAGE_TITLE || null, // 邊欄 Facebook Page widget 的標題欄,填''則無標題欄 e.g FACEBOOK 粉絲團' + FACEBOOK_PAGE: + process.env.NEXT_PUBLIC_FACEBOOK_PAGE || null, // Facebook Page 的連結 e.g https://www.facebook.com/tw.andys.pro FACEBOOK_PAGE_ID: process.env.NEXT_PUBLIC_FACEBOOK_PAGE_ID || '', // Facebook Page ID 來啟用 messenger 聊天功能 - FACEBOOK_APP_ID: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID || '', // Facebook App ID 來啟用 messenger 聊天功能 - FACEBOOK_PAGE: process.env.NEXT_PUBLIC_FACEBOOK_PAGE || 'https://www.facebook.com/tw.andys.pro', // Facebook Page 的連結 + FACEBOOK_APP_ID: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID || '', // Facebook App ID 來啟用 messenger 聊天功能 获取: https://developers.facebook.com/ THEME: process.env.NEXT_PUBLIC_THEME || 'next', // 主题, 支持 ['next','hexo',"fukasawa','medium'] THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮 @@ -120,7 +124,7 @@ const BLOG = { process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖 isProd: process.env.VERCEL_ENV === 'production', // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) - VERSION: '3.1.0' // 版本号 + VERSION: '3.2.1' // 版本号 } module.exports = BLOG diff --git a/components/FacebookPage.js b/components/FacebookPage.js new file mode 100644 index 00000000..e4e52c93 --- /dev/null +++ b/components/FacebookPage.js @@ -0,0 +1,30 @@ +import BLOG from '@/blog.config' +import { FacebookProvider, Page } from 'react-facebook' +import { FacebookIcon } from 'react-share' + +const FacebookPage = () => { + if (!BLOG.FACEBOOK_APP_ID && !BLOG.FACEBOOK_PAGE) { + return <> + } + return
+ {BLOG.FACEBOOK_PAGE && ( +
+ + + + + {BLOG.FACEBOOK_PAGE_TITLE} + +
+ )} + {BLOG.FACEBOOK_APP_ID && + + } +
+} +export default FacebookPage diff --git a/components/NotionPage.js b/components/NotionPage.js index 4295f224..03b1f1eb 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -59,7 +59,7 @@ const NotionPage = ({ post }) => { (zoomRef.current).attach(imgList[i]) } } - }, [router.events]) + }, [router?.events]) return
{
} +/** + * 将id映射成博文内部链接。 + * @param {*} id + * @returns + */ const mapPageUrl = id => { - return 'https://www.notion.so/' + id.replace(/-/g, '') + // return 'https://www.notion.so/' + id.replace(/-/g, '') + return '/article/' + id.replace(/-/g, '') } function getMediumZoomMargin() { diff --git a/lib/notion/getAllCategories.js b/lib/notion/getAllCategories.js index 61aab49c..b9a543d8 100644 --- a/lib/notion/getAllCategories.js +++ b/lib/notion/getAllCategories.js @@ -1,9 +1,11 @@ +import { isIterable } from '../utils' + /** * 获取所有文章的分类 * @param allPosts * @returns {Promise<{}|*[]>} */ -export async function getAllCategories ({ allPosts, categoryOptions, sliceCount = 0 }) { +export async function getAllCategories({ allPosts, categoryOptions, sliceCount = 0 }) { if (!allPosts || !categoryOptions) { return [] } @@ -19,12 +21,14 @@ export async function getAllCategories ({ allPosts, categoryOptions, sliceCount } }) const list = [] - categoryOptions.forEach(c => { - const count = categoryObj[c.value] - if (count) { - list.push({ id: c.id, name: c.value, color: c.color, count }) + if (isIterable(categoryOptions)) { + for (const c of categoryOptions) { + const count = categoryObj[c.value] + if (count) { + list.push({ id: c.id, name: c.value, color: c.color, count }) + } } - }) + } // 按照数量排序 // list.sort((a, b) => b.count - a.count) diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js index 3ac01f54..174055d1 100644 --- a/lib/notion/getAllTags.js +++ b/lib/notion/getAllTags.js @@ -1,3 +1,4 @@ +import { isIterable } from '../utils' /** * 获取所有文章的标签 @@ -6,7 +7,7 @@ * @param tagOptions tags的下拉选项 * @returns {Promise<{}|*[]>} */ -export async function getAllTags ({ allPosts, sliceCount = 0, tagOptions }) { +export async function getAllTags({ allPosts, sliceCount = 0, tagOptions }) { if (!allPosts || !tagOptions) { return [] } @@ -22,12 +23,14 @@ export async function getAllTags ({ allPosts, sliceCount = 0, tagOptions }) { } }) const list = [] - tagOptions.forEach(c => { - const count = tagObj[c.value] - if (count) { - list.push({ id: c.id, name: c.value, color: c.color, count }) - } - }) + if (isIterable(tagOptions)) { + tagOptions.forEach(c => { + const count = tagObj[c.value] + if (count) { + list.push({ id: c.id, name: c.value, color: c.color, count }) + } + }) + } // 按照数量排序 // list.sort((a, b) => b.count - a.count) diff --git a/lib/rss.js b/lib/rss.js index 840045ad..9c394c2c 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -11,12 +11,12 @@ const createFeedContent = async post => { } 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, '') } - return post.summary } export async function generateRss(posts) { diff --git a/lib/utils.js b/lib/utils.js index be47e17f..be9db197 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -64,10 +64,19 @@ export function mergeDeep(target, ...sources) { } /** - * 对象检查 + * 是否对象 * @param item * @returns {boolean} */ export function isObject(item) { return (item && typeof item === 'object' && !Array.isArray(item)) } + +/** + * 是否可迭代 + * @param {*} obj + * @returns + */ +export function isIterable(obj) { + return obj != null && typeof obj[Symbol.iterator] === 'function' +} diff --git a/package.json b/package.json index d47bdc78..9b48294c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.1.0", + "version": "3.2.1", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": { @@ -40,8 +40,10 @@ "react-cookies": "^0.1.1", "react-cusdis": "^2.1.3", "react-dom": "17.0.2", + "react-facebook": "^8.1.4", "react-messenger-customer-chat": "^0.8.0", "react-notion-x": "6.6.2", + "react-share": "^4.4.0", "smoothscroll-polyfill": "^0.4.4", "typed.js": "^2.0.12", "use-ackee": "^3.0.0" diff --git a/pages/article/[slug].js b/pages/article/[slug].js index b190738d..538cbc90 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -5,6 +5,7 @@ import { useGlobal } from '@/lib/global' import * as ThemeMap from '@/themes' import { useEffect, useState } from 'react' import { useRouter } from 'next/router' +import { idToUuid } from 'notion-utils' /** * 根据notion的slug访问页面 @@ -30,7 +31,7 @@ const Slug = props => { } }, 3000) }) - const meta = { title: `${props?.siteInfo?.title} | loading` } + const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading` } return } @@ -92,7 +93,9 @@ export async function getStaticProps({ params: { slug } }) { const from = `slug-props-${slug}` const props = await getGlobalNotionData({ from, pageType: ['Post'] }) const allPosts = props.allPosts - props.post = props.allPosts.find(p => p.slug === slug) + props.post = props.allPosts.find((p) => { + return p.slug === slug || p.id === idToUuid(slug) + }) if (!props.post) { return { props, revalidate: 1 } } diff --git a/styles/notion.css b/styles/notion.css index d42d3b11..b176aed2 100644 --- a/styles/notion.css +++ b/styles/notion.css @@ -1601,7 +1601,7 @@ svg.notion-page-icon { } svg.notion-page-icon { - @apply hidden; + /* @apply hidden;*/ } svg + .notion-page-title-text { diff --git a/themes/example/LayoutSearch.js b/themes/example/LayoutSearch.js index d24024a5..110c11a6 100644 --- a/themes/example/LayoutSearch.js +++ b/themes/example/LayoutSearch.js @@ -38,7 +38,7 @@ export const LayoutSearch = props => {

Search - {keyword}

- {postsToShow.map(p => ( + {postsToShow?.map(p => (
{p.title} diff --git a/themes/fukasawa/LayoutIndex.js b/themes/fukasawa/LayoutIndex.js index 0158a856..7559d65b 100644 --- a/themes/fukasawa/LayoutIndex.js +++ b/themes/fukasawa/LayoutIndex.js @@ -3,6 +3,6 @@ import LayoutBase from './LayoutBase' export const LayoutIndex = (props) => { return - + } diff --git a/themes/fukasawa/LayoutSearch.js b/themes/fukasawa/LayoutSearch.js index 727e9595..46d01031 100644 --- a/themes/fukasawa/LayoutSearch.js +++ b/themes/fukasawa/LayoutSearch.js @@ -14,10 +14,9 @@ export const LayoutSearch = (props) => { const re = new RegExp(`${currentSearch}`, 'gim') container.innerHTML = container.innerHTML.replace(re, `${currentSearch}`) } - }, - 100) + }, 100) }) return - + } diff --git a/themes/fukasawa/components/BlogCard.js b/themes/fukasawa/components/BlogCard.js index 507bac40..f7235c71 100644 --- a/themes/fukasawa/components/BlogCard.js +++ b/themes/fukasawa/components/BlogCard.js @@ -7,7 +7,7 @@ import Card from './Card' const BlogCard = ({ post, showSummary }) => { const showPreview = CONFIG_FUKA.POST_LIST_PREVIEW && post.blockMap return ( - +
{
{post.title} diff --git a/themes/fukasawa/components/BlogListPage.js b/themes/fukasawa/components/BlogListPage.js index 51c1c6c1..a418ff47 100644 --- a/themes/fukasawa/components/BlogListPage.js +++ b/themes/fukasawa/components/BlogListPage.js @@ -17,7 +17,7 @@ const BlogListPage = ({ page = 1, posts = [], postCount }) => { const showNext = page < totalPage && posts.length === BLOG.POSTS_PER_PAGE && posts.length < postCount const [colCount, changeCol] = useState(1) - function updateCol () { + function updateCol() { if (window.outerWidth > 1200) { changeCol(3) } else { @@ -40,7 +40,7 @@ const BlogListPage = ({ page = 1, posts = [], postCount }) => {
{/* 文章列表 */}
- {posts.map(post => ( + {posts?.map(post => (
diff --git a/themes/fukasawa/components/Catalog.js b/themes/fukasawa/components/Catalog.js index 2e67c392..cad8ce68 100644 --- a/themes/fukasawa/components/Catalog.js +++ b/themes/fukasawa/components/Catalog.js @@ -58,7 +58,7 @@ const Catalog = ({ toc }) => { return
目录
-
+