From 53a7ec36028f9dd012744949528da4d8c13c0bc8 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 7 Dec 2022 18:14:46 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B1=87=E7=BC=96?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E9=AB=98=E4=BA=AE=EF=BC=8Cprismjs=E9=87=87?= =?UTF-8?q?=E7=94=A8=E5=A4=96=E9=83=A8cdn=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 4 +++- components/NotionPage.js | 36 ------------------------------------ components/PrismMac.js | 7 +++++-- lib/notion/getPostBlocks.js | 5 ++++- 4 files changed, 12 insertions(+), 40 deletions(-) diff --git a/blog.config.js b/blog.config.js index 592a6a99..3b471dc5 100644 --- a/blog.config.js +++ b/blog.config.js @@ -37,7 +37,9 @@ const BLOG = { BEI_AN: process.env.NEXT_PUBLIC_BEI_AN || '', // 备案号 闽ICP备XXXXXXX // 图标库CDN(可以直接改版本号) - FONT_AWESOME_PATH: 'https://cdn.bootcdn.net/ajax/libs/font-awesome/6.2.0/css/all.min.css', + FONT_AWESOME_PATH: 'https://npm.elemecdn.com/font-awesome/6.2.0/css/all.min.css', + // PrismJs CDN + PRISM_JS_PATH: 'https://npm.elemecdn.com/prismjs@1.29.0/components/', BACKGROUND_LIGHT: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc BACKGROUND_DARK: '#000000', // use hex value, don't forget '#' diff --git a/components/NotionPage.js b/components/NotionPage.js index e195e24d..8739917f 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -1,47 +1,11 @@ import { NotionRenderer } from 'react-notion-x' import dynamic from 'next/dynamic' -// import mediumZoom from 'medium-zoom' import mediumZoom from '@fisch0920/medium-zoom' import React from 'react' import { isBrowser } from '@/lib/utils' import Image from 'next/image' import Link from 'next/link' import { Code } from 'react-notion-x/build/third-party/code' -// import { Pdf } from 'react-notion-x/build/third-party/pdf' -// import { Equation } from 'react-notion-x/build/third-party/equation' - -import 'prismjs/components/prism-bash.js' -import 'prismjs/components/prism-markup-templating.js' -import 'prismjs/components/prism-markup.js' -import 'prismjs/components/prism-c.js' -import 'prismjs/components/prism-cpp.js' -import 'prismjs/components/prism-csharp.js' -import 'prismjs/components/prism-docker.js' -import 'prismjs/components/prism-java.js' -import 'prismjs/components/prism-js-templates.js' -import 'prismjs/components/prism-coffeescript.js' -import 'prismjs/components/prism-diff.js' -import 'prismjs/components/prism-git.js' -import 'prismjs/components/prism-go.js' -import 'prismjs/components/prism-graphql.js' -import 'prismjs/components/prism-handlebars.js' -import 'prismjs/components/prism-less.js' -import 'prismjs/components/prism-makefile.js' -import 'prismjs/components/prism-markdown.js' -import 'prismjs/components/prism-objectivec.js' -import 'prismjs/components/prism-ocaml.js' -import 'prismjs/components/prism-python.js' -import 'prismjs/components/prism-reason.js' -import 'prismjs/components/prism-rust.js' -import 'prismjs/components/prism-sass.js' -import 'prismjs/components/prism-scss.js' -import 'prismjs/components/prism-solidity.js' -import 'prismjs/components/prism-sql.js' -import 'prismjs/components/prism-stylus.js' -import 'prismjs/components/prism-swift.js' -import 'prismjs/components/prism-wasm.js' -import 'prismjs/components/prism-yaml.js' -import 'prismjs/components/prism-r.js' const Equation = dynamic(() => import('react-notion-x/build/third-party/equation').then(async (m) => { diff --git a/components/PrismMac.js b/components/PrismMac.js index 0180069a..fbfd42cd 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -3,12 +3,13 @@ import Prism from 'prismjs' import 'prismjs/plugins/toolbar/prism-toolbar' import 'prismjs/plugins/show-language/prism-show-language' import 'prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard' -// import 'prismjs/plugins/autoloader/prism-autoloader' import 'prismjs/plugins/line-numbers/prism-line-numbers' import 'prismjs/plugins/line-numbers/prism-line-numbers.css' - +// 所有语言的prismjs 使用autoloader引入 +import 'prismjs/plugins/autoloader/prism-autoloader' // mermaid图 import mermaid from 'mermaid' +import BLOG from '@/blog.config' /** * @author https://github.com/txs/ @@ -67,6 +68,8 @@ function renderPrismMac() { // 重新渲染之前检查所有的多余text try { + // setup autoloader + Prism.plugins.autoloader.languages_path = BLOG.PRISM_JS_PATH Prism.highlightAll() } catch (err) { console.log('代码渲染', err) diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index 685e8d46..1f92fa41 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -72,7 +72,7 @@ function filterPostBlocks(id, pageBlock, slice) { continue } count++ - // 处理 c++ 和 c#两种语言 + // 处理 c++ 和 c#等语言名字映射 if (b?.value?.type === 'code') { if (b?.value?.properties?.language?.[0][0] === 'C++') { b.value.properties.language[0][0] = 'cpp' @@ -80,6 +80,9 @@ function filterPostBlocks(id, pageBlock, slice) { if (b?.value?.properties?.language?.[0][0] === 'C#') { b.value.properties.language[0][0] = 'csharp' } + if (b?.value?.properties?.language?.[0][0] === 'Assembly') { + b.value.properties.language[0][0] = 'asm6502' + } } delete b?.role From 900dc5fbd05fdba8e7d9fd1feaae8097dbd3187e Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 7 Dec 2022 18:18:08 +0800 Subject: [PATCH 2/5] fontawesome --- blog.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog.config.js b/blog.config.js index 3b471dc5..4497b3d3 100644 --- a/blog.config.js +++ b/blog.config.js @@ -37,7 +37,7 @@ const BLOG = { BEI_AN: process.env.NEXT_PUBLIC_BEI_AN || '', // 备案号 闽ICP备XXXXXXX // 图标库CDN(可以直接改版本号) - FONT_AWESOME_PATH: 'https://npm.elemecdn.com/font-awesome/6.2.0/css/all.min.css', + FONT_AWESOME_PATH: 'https://cdn.bootcdn.net/ajax/libs/font-awesome/6.2.0/css/all.min.css', // PrismJs CDN PRISM_JS_PATH: 'https://npm.elemecdn.com/prismjs@1.29.0/components/', From 47d2dcaa45b4e66d5d6859b4e3f91b85c3f5510a Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 7 Dec 2022 18:59:19 +0800 Subject: [PATCH 3/5] =?UTF-8?q?meta=E7=A7=BB=E5=8A=A8=E7=AB=AF=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/medium/LayoutSlug.js | 3 +- themes/medium/components/ArticleDetail.js | 99 ++++++----- themes/next/LayoutSlug.js | 18 +- themes/next/components/ArticleDetail.js | 205 +++++++++++----------- themes/next/components/WordCount.js | 4 +- 5 files changed, 163 insertions(+), 166 deletions(-) diff --git a/themes/medium/LayoutSlug.js b/themes/medium/LayoutSlug.js index f9242af0..e0c52b84 100644 --- a/themes/medium/LayoutSlug.js +++ b/themes/medium/LayoutSlug.js @@ -9,6 +9,8 @@ import { ArticleLock } from './components/ArticleLock' export const LayoutSlug = props => { const { post, lock, validPassword } = props + const { locale } = useGlobal() + if (!post) { return { post.content = Object.keys(post.blockMap.block) post.toc = getPageTableOfContents(post, post.blockMap) } - const { locale } = useGlobal() const slotRight = post?.toc && post?.toc?.length > 3 && (
diff --git a/themes/medium/components/ArticleDetail.js b/themes/medium/components/ArticleDetail.js index 48630d47..5e6c4da5 100644 --- a/themes/medium/components/ArticleDetail.js +++ b/themes/medium/components/ArticleDetail.js @@ -19,55 +19,58 @@ export const ArticleDetail = props => { locale.LOCALE ) return
-

{post?.title}

-
- - <> - {/* eslint-disable-next-line @next/next/no-img-element */} - + {/* title */} +

{post?.title}

-
- {BLOG.AUTHOR} -
- - -
{date}
-
- {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime} -
-
- -   - -
-
- {/* Notion文章主体 */} -
- {post && ()} -
+ {/* meta */} +
+
+ {date} + | + {post.lastEditedTime} +
+ + +
+
+ +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + -
- {/* 文章内嵌广告 */} - -
-
-
- {CONFIG_MEDIUM.POST_DETAIL_CATEGORY && post.category && } -
- {CONFIG_MEDIUM.POST_DETAIL_TAG && post?.tagItems?.map(tag => )} -
-
- {post.type === 'Post' && } - -
-
+
+ {BLOG.AUTHOR} +
+
+ + + {/* Notion文章主体 */} +
+ {post && ()} +
+ +
+ {/* 文章内嵌广告 */} + +
+
+
+ {CONFIG_MEDIUM.POST_DETAIL_CATEGORY && post.category && } +
+ {CONFIG_MEDIUM.POST_DETAIL_TAG && post?.tagItems?.map(tag => )} +
+
+ {post.type === 'Post' && } + +
+
} diff --git a/themes/next/LayoutSlug.js b/themes/next/LayoutSlug.js index 9e1b0341..aa1cc4d2 100644 --- a/themes/next/LayoutSlug.js +++ b/themes/next/LayoutSlug.js @@ -12,15 +12,6 @@ import { isBrowser } from '@/lib/utils' export const LayoutSlug = (props) => { const { post, latestPosts, lock, validPassword } = props - if (!post) { - return - } - /> - } - if (!lock && post?.blockMap?.block) { post.content = Object.keys(post.blockMap.block) post.toc = getPageTableOfContents(post, post.blockMap) @@ -34,6 +25,15 @@ export const LayoutSlug = (props) => { }} /> : null + if (!post) { + return + } + /> + } + return ( -
+
- {showArticleInfo &&
- {CONFIG_NEXT.POST_HEADER_IMAGE_VISIBLE && post?.type && !post?.type !== 'Page' && post?.page_cover && ( -
- {/* eslint-disable-next-line @next/next/no-img-element */} - {post.title} -
- )} + {showArticleInfo &&
+ {/* 头图 */} + {CONFIG_NEXT.POST_HEADER_IMAGE_VISIBLE && post?.type && !post?.type !== 'Page' && post?.page_cover && ( +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {post.title} +
+ )} - {/* 文章Title */} -
- {post.title} + {/* title */} +
+ {post.title} +
+ + {/* meta */} +
+
+ {post?.type !== 'Page' && (<> + +
+ {date} +
+ + | {post.lastEditedTime} + +
+ + +
+ + )} +
+ + +
+ +
} + + {/* Notion内容主体 */} +
+ {post && ()} +
+ +
+ {/* 文章内嵌广告 */} + +
+ + {showArticleInfo && <> + {/* 版权声明 */} + {post.type === 'Post' && } + + {/* 推荐文章 */} + {post.type === 'Post' && } + +
+ {/* 分类 */} + {post.category && <> +
+ + <> {post.category} + +
+ + } + + {/* 标签列表 */} + {post.type === 'Post' && ( + <> + {post.tagItems && ( +
+
+ {locale.COMMON.TAGS}: +
+ {post.tagItems.map(tag => ( + + ))} +
+ )} + + + )} +
+ {post.type === 'Post' && } + } + + {/* 评论互动 */} +
+ +
-
-
- {post.category && <> - - - {post.category} - - - | - } - {post?.type !== 'Page' && (<> - - - {date} - - - | -
- -   - -
- - )} - -
- -
- {locale.COMMON.LAST_EDITED_TIME} {post.lastEditedTime} -
- -
- -
-
- - } - - {/* Notion内容主体 */} -
- {post && ()} -
- -
- {/* 文章内嵌广告 */} - -
- - {showArticleInfo && <> - {/* 版权声明 */} - {post.type === 'Post' && } - - {/* 推荐文章 */} - {post.type === 'Post' && } - - {/* 标签列表 */} - {post.type === 'Post' && ( -
- {post.tagItems && ( -
-
- {locale.COMMON.TAGS}: -
- {post.tagItems.map(tag => ( - - ))} -
- )} -
- -
-
- )} - - {post.type === 'Post' && } - } - - {/* 评论互动 */} -
- -
-
- - ) + ) } diff --git a/themes/next/components/WordCount.js b/themes/next/components/WordCount.js index bad2cf3a..2062e69a 100644 --- a/themes/next/components/WordCount.js +++ b/themes/next/components/WordCount.js @@ -9,8 +9,8 @@ export default function WordCount() { countWords() }) - return
- 本文字数 0  |  阅读时长 ≈ 0 分钟 + return
+ 本文字数 0  |  阅读时长 ≈ 0 分钟
} From a53ff415277969d800cc73474ca5e194b2fed821 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 7 Dec 2022 19:04:03 +0800 Subject: [PATCH 4/5] =?UTF-8?q?medium=E4=B8=BB=E9=A2=98nav-button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/medium/components/GroupMenu.js | 8 ++++---- themes/medium/components/TopNavBar.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/medium/components/GroupMenu.js b/themes/medium/components/GroupMenu.js index 534f2c78..6ec027ab 100644 --- a/themes/medium/components/GroupMenu.js +++ b/themes/medium/components/GroupMenu.js @@ -9,18 +9,18 @@ function GroupMenu ({ customNav }) { const router = useRouter() let links = [ - { name: locale.NAV.INDEX, to: '/' || '/', show: true }, + // { name: locale.NAV.INDEX, to: '/' || '/', show: true }, { name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_MEDIUM.MENU_CATEGORY }, { name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_MEDIUM.MENU_TAG }, - { name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_MEDIUM.MENU_ARCHIVE }, - { name: locale.NAV.SEARCH, to: '/search', show: CONFIG_MEDIUM.MENU_SEARCH } + { name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_MEDIUM.MENU_ARCHIVE } + // { name: locale.NAV.SEARCH, to: '/search', show: CONFIG_MEDIUM.MENU_SEARCH } ] if (customNav) { links = links.concat(customNav) } - return