From c8c1e71480d3fbace2502f8a490a64a2e55ffdc1 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 16 Mar 2022 13:12:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?hexo=20=E5=9B=9E=E9=A1=B6=20=E6=8C=89?= =?UTF-8?q?=E9=92=AE=20=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/LayoutBase.js | 10 +++++----- themes/hexo/components/FloatDarkModeButton.js | 2 +- themes/hexo/components/JumpToCommentButton.js | 2 +- themes/hexo/components/JumpToTopButton.js | 2 +- themes/hexo/components/PaginationNumber.js | 4 ++-- themes/hexo/components/TocDrawerButton.js | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index dd186e06..93e5b129 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -17,7 +17,7 @@ import FloatDarkModeButton from './components/FloatDarkModeButton' const LayoutBase = (props) => { const { children, headerSlot, floatSlot, meta } = props const [show, switchShow] = useState(false) - const [percent, changePercent] = useState(0) // 页面阅读百分比 + // const [percent, changePercent] = useState(0) // 页面阅读百分比 const scrollListener = () => { const targetRef = document.getElementById('wrapper') @@ -31,7 +31,7 @@ const LayoutBase = (props) => { if (shouldShow !== show) { switchShow(shouldShow) } - changePercent(per) + // changePercent(per) } useEffect(() => { smoothscroll.polyfill() @@ -55,11 +55,11 @@ const LayoutBase = (props) => { {/* 右下角悬浮 */} -
-
+
+
{floatSlot} - +
diff --git a/themes/hexo/components/FloatDarkModeButton.js b/themes/hexo/components/FloatDarkModeButton.js index 196a7875..b6122ba9 100644 --- a/themes/hexo/components/FloatDarkModeButton.js +++ b/themes/hexo/components/FloatDarkModeButton.js @@ -21,7 +21,7 @@ export default function FloatDarkModeButton () { return (
diff --git a/themes/hexo/components/JumpToCommentButton.js b/themes/hexo/components/JumpToCommentButton.js index 736468d4..cc96497c 100644 --- a/themes/hexo/components/JumpToCommentButton.js +++ b/themes/hexo/components/JumpToCommentButton.js @@ -17,7 +17,7 @@ const JumpToCommentButton = () => { } } - return (
+ return (
) } diff --git a/themes/hexo/components/JumpToTopButton.js b/themes/hexo/components/JumpToTopButton.js index de1bce3d..427ef500 100644 --- a/themes/hexo/components/JumpToTopButton.js +++ b/themes/hexo/components/JumpToTopButton.js @@ -15,7 +15,7 @@ const JumpToTopButton = ({ showPercent = true, percent }) => { return <> } const { locale } = useGlobal() - return (
window.scrollTo({ top: 0, behavior: 'smooth' })} > + return (
window.scrollTo({ top: 0, behavior: 'smooth' })} >
{showPercent && (
{percent}
)}
) diff --git a/themes/hexo/components/PaginationNumber.js b/themes/hexo/components/PaginationNumber.js index 56942531..45d9282b 100644 --- a/themes/hexo/components/PaginationNumber.js +++ b/themes/hexo/components/PaginationNumber.js @@ -37,7 +37,7 @@ const PaginationNumber = ({ page, totalPage }) => { @@ -48,7 +48,7 @@ const PaginationNumber = ({ page, totalPage }) => { function getPageElement (page, currentPage) { return - {page} diff --git a/themes/hexo/components/TocDrawerButton.js b/themes/hexo/components/TocDrawerButton.js index a4bba1a4..144af536 100644 --- a/themes/hexo/components/TocDrawerButton.js +++ b/themes/hexo/components/TocDrawerButton.js @@ -14,7 +14,7 @@ const TocDrawerButton = (props) => { return <> } const { locale } = useGlobal() - return (
+ return (
) } From 72f45e58663575e387e5b652d87fe78c0ad4ce82 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 17 Mar 2022 09:41:37 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/LayoutSearch.js | 85 +++++++++++++++++++++----- themes/hexo/LayoutTagIndex.js | 2 +- themes/hexo/components/SearchInput.js | 73 +++++++++++++--------- themes/next/components/SearchDrawer.js | 2 +- 4 files changed, 117 insertions(+), 45 deletions(-) diff --git a/themes/hexo/LayoutSearch.js b/themes/hexo/LayoutSearch.js index 22abf034..b4dab8a2 100644 --- a/themes/hexo/LayoutSearch.js +++ b/themes/hexo/LayoutSearch.js @@ -1,34 +1,89 @@ - import { useRouter } from 'next/router' -import { useEffect } from 'react' +import { useEffect, useRef } from 'react' import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' import SearchInput from './components/SearchInput' -export const LayoutSearch = (props) => { - const { keyword } = props +import { useGlobal } from '@/lib/global' +import TagItemMini from './components/TagItemMini' +import Card from './components/Card' +import Link from 'next/link' + +export const LayoutSearch = props => { + const { keyword, tags, categories } = props + const { locale } = useGlobal() const router = useRouter() const currentSearch = keyword || router?.query?.s let handleTextColor = false + const cRef = useRef(null) useEffect(() => { setTimeout(() => { + // 自动聚焦到搜索框 + cRef.current.focus() if (currentSearch && !handleTextColor) { const container = document.getElementById('container') if (container && container.innerHTML) { const re = new RegExp(`${currentSearch}`, 'gim') - container.innerHTML = container.innerHTML.replace(re, `${currentSearch}`) + container.innerHTML = container.innerHTML.replace( + re, + `${currentSearch}` + ) handleTextColor = true } } - }, - 100) + }, 100) }) - return -
- -
-
- -
-
+ return ( + +
+ + {/* 分类 */} + +
+ + {locale.COMMON.CATEGORY}: +
+
+ {categories.map(category => { + return ( + +
+ + {category.name}({category.count}) +
+ + ) + })} +
+
+ {/* 标签 */} + +
+ + {locale.COMMON.TAGS}: +
+
+ {tags.map(tag => { + return ( +
+ +
+ ) + })} +
+
+
+
+ +
+
+ ) } diff --git a/themes/hexo/LayoutTagIndex.js b/themes/hexo/LayoutTagIndex.js index 662bbe48..89cfcbad 100644 --- a/themes/hexo/LayoutTagIndex.js +++ b/themes/hexo/LayoutTagIndex.js @@ -22,7 +22,7 @@ export const LayoutTagIndex = props => {
{tags.map(tag => { return ( -
+
) diff --git a/themes/hexo/components/SearchInput.js b/themes/hexo/components/SearchInput.js index 438920f7..0f29a3a7 100644 --- a/themes/hexo/components/SearchInput.js +++ b/themes/hexo/components/SearchInput.js @@ -1,12 +1,14 @@ import { useRouter } from 'next/router' import { useImperativeHandle, useRef, useState } from 'react' +import { useGlobal } from '@/lib/global' let lock = false -const SearchInput = (props) => { +const SearchInput = props => { const { currentSearch, cRef, className } = props const [onLoading, setLoadingState] = useState(false) const router = useRouter() const searchInputRef = useRef() + const { locale } = useGlobal() useImperativeHandle(cRef, () => { return { focus: () => { @@ -21,14 +23,15 @@ const SearchInput = (props) => { setLoadingState(true) location.href = '/search/' + key } else { - router.push({ pathname: '/' }).then(r => { - }) + router.push({ pathname: '/' }).then(r => {}) } } - const handleKeyUp = (e) => { - if (e.keyCode === 13) { // 回车 + const handleKeyUp = e => { + if (e.keyCode === 13) { + // 回车 handleSearch(searchInputRef.current.value) - } else if (e.keyCode === 27) { // ESC + } else if (e.keyCode === 27) { + // ESC cleanSearch() } } @@ -37,7 +40,7 @@ const SearchInput = (props) => { } const [showClean, setShowClean] = useState(false) - const updateSearchKey = (val) => { + const updateSearchKey = val => { if (lock) { return } @@ -57,30 +60,44 @@ const SearchInput = (props) => { lock = false } - return
- updateSearchKey(e.target.value)} - defaultValue={currentSearch} - /> + return ( +
+ updateSearchKey(e.target.value)} + defaultValue={currentSearch || ''} + /> -
- -
- - {(showClean && -
- +
+
+ + {showClean && ( +
+ +
)} -
+
+ ) } export default SearchInput diff --git a/themes/next/components/SearchDrawer.js b/themes/next/components/SearchDrawer.js index c7ec88a7..6c1f46b9 100644 --- a/themes/next/components/SearchDrawer.js +++ b/themes/next/components/SearchDrawer.js @@ -28,7 +28,7 @@ const SearchDrawer = ({ cRef, slot }) => {
{/* 背景蒙版 */} -
+
) } From 005fb33a8f4d008d1814ad35f88f8839bcf3e6c9 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 17 Mar 2022 09:54:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?rss=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/rss.js | 33 +++++++++++++++++++++++++++++---- pages/feed.js | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/rss.js b/lib/rss.js index 9c3f3fc7..d6cbaf4a 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -1,7 +1,31 @@ import { Feed } from 'feed' import BLOG from '@/blog.config' +import ReactDOMServer from 'react-dom/server' +import { NotionRenderer, Equation, Code, Collection, CollectionRow } from 'react-notion-x' +import { getPostBlocks } from './notion' -export function generateRss (posts) { +const mapPageUrl = id => 'https://www.notion.so/' + id.replace(/-/g, '') + +const createFeedContent = async post => { + const blockMap = await getPostBlocks(post.id, 'rss-content') + if (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) { const year = new Date().getFullYear() const feed = new Feed({ title: BLOG.TITLE, @@ -17,14 +41,15 @@ export function generateRss (posts) { link: BLOG.LINK } }) - posts.forEach(post => { + for (const post of posts) { feed.addItem({ title: post.title, id: `${BLOG.LINK}/article/${post.slug}`, link: `${BLOG.LINK}/article/${post.slug}`, description: post.summary, + content: await createFeedContent(post), date: new Date(post?.date?.start_date || post.createdTime) }) - }) - return feed.rss2() + } + return feed.atom1() } diff --git a/pages/feed.js b/pages/feed.js index 3e3ebffa..e7499181 100644 --- a/pages/feed.js +++ b/pages/feed.js @@ -4,7 +4,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' export async function getServerSideProps ({ res }) { res.setHeader('Content-Type', 'text/xml') const globalNotionData = await getGlobalNotionData({ from: 'rss' }) - const xmlFeed = generateRss(globalNotionData?.allPosts?.slice(0, 10) || []) + const xmlFeed = await generateRss(globalNotionData?.allPosts?.slice(0, 10) || []) res.write(xmlFeed) res.end() return {