From 6c91e68ff92f0fcfa6c966c878766f7c3d6f87e9 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 28 Feb 2022 17:30:17 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/search.js | 34 ++++++++++++++++++- themes/Empty/LayoutSearch.js | 25 -------------- themes/Fukasawa/LayoutIndex.js | 4 +-- themes/Fukasawa/LayoutSearch.js | 26 ++------------- themes/Hexo/LayoutCategoryIndex.js | 2 +- themes/Hexo/LayoutSearch.js | 35 ++------------------ themes/Hexo/components/MenuButtonGroup.js | 14 ++++---- themes/Hexo/components/SearchInput.js | 4 +-- themes/Medium/LayoutSearch.js | 1 - themes/NEXT/LayoutSearch.js | 40 +++-------------------- themes/NEXT/components/SearchInput.js | 4 +-- themes/index.js | 4 +-- 12 files changed, 58 insertions(+), 135 deletions(-) diff --git a/pages/search.js b/pages/search.js index 57bc57fb..ef7cae89 100644 --- a/pages/search.js +++ b/pages/search.js @@ -1,5 +1,8 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import { LayoutSearch } from '@/themes' +import BLOG from '@/blog.config' +import { useGlobal } from '@/lib/global' +import { useRouter } from 'next/router' export async function getStaticProps () { const { @@ -24,7 +27,36 @@ export async function getStaticProps () { } const Search = (props) => { - return + const { posts } = props + let filteredPosts + const searchKey = getSearchKey() + // 静态过滤 + if (searchKey) { + filteredPosts = posts.filter(post => { + const tagContent = post.tags ? post.tags.join(' ') : '' + const categoryContent = post.category ? post.category.join(' ') : '' + const searchContent = post.title + post.summary + tagContent + categoryContent + return searchContent.toLowerCase().includes(searchKey.toLowerCase()) + }) + } else { + filteredPosts = posts + } + + const { locale } = useGlobal() + const meta = { + title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `, + description: BLOG.DESCRIPTION, + type: 'website' + } + return +} + +function getSearchKey () { + const router = useRouter() + if (router.query && router.query.s) { + return router.query.s + } + return null } export default Search diff --git a/themes/Empty/LayoutSearch.js b/themes/Empty/LayoutSearch.js index c7469a60..fb9244c3 100644 --- a/themes/Empty/LayoutSearch.js +++ b/themes/Empty/LayoutSearch.js @@ -1,31 +1,6 @@ -import { useRouter } from 'next/router' import LayoutBase from './LayoutBase' export const LayoutSearch = (props) => { - const { posts } = props - let filteredPosts - const searchKey = getSearchKey() - if (searchKey) { - filteredPosts = posts.filter(post => { - const tagContent = post.tags ? post.tags.join(' ') : '' - const searchContent = post.title + post.summary + tagContent - return searchContent.toLowerCase().includes(searchKey.toLowerCase()) - }) - } else { - filteredPosts = posts - } - - console.log(filteredPosts) - return - Search {searchKey} } - -function getSearchKey () { - const router = useRouter() - if (router.query && router.query.s) { - return router.query.s - } - return null -} diff --git a/themes/Fukasawa/LayoutIndex.js b/themes/Fukasawa/LayoutIndex.js index 5a1209c5..0158a856 100644 --- a/themes/Fukasawa/LayoutIndex.js +++ b/themes/Fukasawa/LayoutIndex.js @@ -3,8 +3,6 @@ import LayoutBase from './LayoutBase' export const LayoutIndex = (props) => { return - - - + } diff --git a/themes/Fukasawa/LayoutSearch.js b/themes/Fukasawa/LayoutSearch.js index 1d77bf69..8112f850 100644 --- a/themes/Fukasawa/LayoutSearch.js +++ b/themes/Fukasawa/LayoutSearch.js @@ -1,30 +1,8 @@ -import { useRouter } from 'next/router' import LayoutBase from './LayoutBase' +import BlogListPage from './components/BlogListPage' export const LayoutSearch = (props) => { - let filteredPosts - const searchKey = getSearchKey() - if (searchKey) { - filteredPosts = props.posts.filter(post => { - const tagContent = post.tags ? post.tags.join(' ') : '' - const searchContent = post.title + post.summary + tagContent - return searchContent.toLowerCase().includes(searchKey.toLowerCase()) - }) - } else { - filteredPosts = props.posts - } - - console.log(filteredPosts) - return - Search {searchKey} + } - -function getSearchKey () { - const router = useRouter() - if (router.query && router.query.s) { - return router.query.s - } - return null -} diff --git a/themes/Hexo/LayoutCategoryIndex.js b/themes/Hexo/LayoutCategoryIndex.js index 6585e290..5c6de632 100644 --- a/themes/Hexo/LayoutCategoryIndex.js +++ b/themes/Hexo/LayoutCategoryIndex.js @@ -25,7 +25,7 @@ export const LayoutCategoryIndex = props => {
diff --git a/themes/Hexo/LayoutSearch.js b/themes/Hexo/LayoutSearch.js index 77be5014..3b26ad57 100644 --- a/themes/Hexo/LayoutSearch.js +++ b/themes/Hexo/LayoutSearch.js @@ -1,38 +1,9 @@ -import BLOG from '@/blog.config' -import { useGlobal } from '@/lib/global' -import { useRouter } from 'next/router' + import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' export const LayoutSearch = (props) => { - const { posts } = props - let filteredPosts - const searchKey = getSearchKey() - if (searchKey) { - filteredPosts = posts.filter(post => { - const tagContent = post.tags ? post.tags.join(' ') : '' - const searchContent = post.title + post.summary + tagContent - return searchContent.toLowerCase().includes(searchKey.toLowerCase()) - }) - } else { - filteredPosts = posts - } - - const { locale } = useGlobal() - const meta = { - title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `, - description: BLOG.DESCRIPTION, - type: 'website' - } - return - + return + } - -function getSearchKey () { - const router = useRouter() - if (router.query && router.query.s) { - return router.query.s - } - return null -} diff --git a/themes/Hexo/components/MenuButtonGroup.js b/themes/Hexo/components/MenuButtonGroup.js index ee93f4a7..a968b800 100644 --- a/themes/Hexo/components/MenuButtonGroup.js +++ b/themes/Hexo/components/MenuButtonGroup.js @@ -11,11 +11,11 @@ const MenuButtonGroup = (props) => { const archiveSlot =
{postCount}
let links = [ - { id: 0, icon: 'fas fa-home', name: locale.NAV.INDEX, to: '/' || '/', show: true }, - { id: 1, icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY }, - { id: 2, icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG }, - { id: 3, icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: CONFIG_HEXO.MENU_ARCHIVE }, - { id: 4, icon: 'fas fa-user', name: locale.NAV.ABOUT, to: '/about', show: CONFIG_HEXO.MENU_ABOUT } + { icon: 'fas fa-home', name: locale.NAV.INDEX, to: '/' || '/', show: true }, + { icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY }, + { icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG }, + { icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: CONFIG_HEXO.MENU_ARCHIVE }, + { icon: 'fas fa-user', name: locale.NAV.ABOUT, to: '/about', show: CONFIG_HEXO.MENU_ABOUT } ] if (customNav) { links = links.concat(customNav) @@ -24,11 +24,11 @@ const MenuButtonGroup = (props) => { {links.map(link => { if (link.show) { const selected = (router.pathname === link.to) || (router.asPath === link.to) - return + return
- +
{link.name}
{link.slot} diff --git a/themes/Hexo/components/SearchInput.js b/themes/Hexo/components/SearchInput.js index 5ac91ad5..d6ba0884 100644 --- a/themes/Hexo/components/SearchInput.js +++ b/themes/Hexo/components/SearchInput.js @@ -44,10 +44,10 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => { updateSearchKey(e.target.value)} - defaultValue={searchKey} + defaultValue={currentSearch} />
{ - const { posts, tags } = props - let filteredPosts - const searchKey = getSearchKey() - if (searchKey) { - filteredPosts = posts.filter(post => { - const tagContent = post.tags ? post.tags.join(' ') : '' - const searchContent = post.title + post.summary + tagContent - return searchContent.toLowerCase().includes(searchKey.toLowerCase()) - }) - } else { - filteredPosts = posts - } - const { locale } = useGlobal() - const meta = { - title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `, - description: BLOG.DESCRIPTION, - type: 'website' - } + const { posts } = props + return ( - +
{' '} - {filteredPosts.length} {locale.COMMON.RESULT_OF_SEARCH} + {posts.length} {locale.COMMON.RESULT_OF_SEARCH}
- +
) } - -function getSearchKey () { - const router = useRouter() - if (router.query && router.query.s) { - return router.query.s - } - return null -} diff --git a/themes/NEXT/components/SearchInput.js b/themes/NEXT/components/SearchInput.js index 2c18732f..2f6f86c4 100644 --- a/themes/NEXT/components/SearchInput.js +++ b/themes/NEXT/components/SearchInput.js @@ -47,12 +47,12 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => { ref={searchInputRef} type='text' placeholder={currentTag ? `${locale.SEARCH.TAGS} #${currentTag}` : `${locale.SEARCH.ARTICLES}`} - className={'w-full text-sm pl-2 transition focus:shadow-lg font-light leading-10 border-gray-300 text-black bg-gray-100 dark:bg-gray-900 dark:text-white'} + className={'w-full text-sm pl-4 transition focus:shadow-lg font-light leading-10 border-gray-300 text-black bg-gray-100 dark:bg-gray-900 dark:text-white'} onKeyUp={handleKeyUp} onChange={e => updateSearchKey(e.target.value)} defaultValue={searchKey} /> - {(searchKey && searchKey.length && )} + {(searchKey && searchKey.length && )}
{ handleSearch(searchKey) }}> diff --git a/themes/index.js b/themes/index.js index 29af6e2a..79876b36 100644 --- a/themes/index.js +++ b/themes/index.js @@ -4,6 +4,6 @@ // export * from './Empty' // 空主题 // export * from './NEXT' -// export * from './Fukasawa' +export * from './Fukasawa' +// export * from './Hexo' // export * from './Hexo' -export * from './Hexo' From 9e3bcb75e58a29d05621976f1b9c7b8706b1e952 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 28 Feb 2022 17:46:31 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=8D=A1=E7=89=8Carticle-cover=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/Medium/components/BlogPostCard.js | 5 ++--- themes/NEXT/components/BlogPostCard.js | 4 ++-- themes/index.js | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/themes/Medium/components/BlogPostCard.js b/themes/Medium/components/BlogPostCard.js index c71b1345..c3e2a1df 100644 --- a/themes/Medium/components/BlogPostCard.js +++ b/themes/Medium/components/BlogPostCard.js @@ -45,10 +45,10 @@ const BlogPostCard = ({ post, showSummary }) => { collection: Collection }} /> -
+
- + {locale.COMMON.ARTICLE_DETAIL} @@ -58,7 +58,6 @@ const BlogPostCard = ({ post, showSummary }) => {
}

-
) diff --git a/themes/NEXT/components/BlogPostCard.js b/themes/NEXT/components/BlogPostCard.js index 8fb3ce7e..d2f2c9be 100644 --- a/themes/NEXT/components/BlogPostCard.js +++ b/themes/NEXT/components/BlogPostCard.js @@ -59,9 +59,9 @@ const BlogPostCard = ({ post, showSummary }) => { />
} -
+
- + {locale.COMMON.ARTICLE_DETAIL} diff --git a/themes/index.js b/themes/index.js index 79876b36..e9b63872 100644 --- a/themes/index.js +++ b/themes/index.js @@ -3,7 +3,7 @@ */ // export * from './Empty' // 空主题 -// export * from './NEXT' -export * from './Fukasawa' -// export * from './Hexo' +export * from './NEXT' +// export * from './Fukasawa' // export * from './Hexo' +// export * from './Medium' From 1bdd079b64cf31af54482fb12e0a56aba4682ce8 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 1 Mar 2022 11:19:33 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/NEXT/LayoutSearch.js | 2 +- themes/NEXT/components/SearchInput.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/NEXT/LayoutSearch.js b/themes/NEXT/LayoutSearch.js index 01b13d72..34a48e47 100644 --- a/themes/NEXT/LayoutSearch.js +++ b/themes/NEXT/LayoutSearch.js @@ -12,7 +12,7 @@ export const LayoutSearch = (props) => {
{' '} - {posts.length} {locale.COMMON.RESULT_OF_SEARCH} + {posts?.length} {locale.COMMON.RESULT_OF_SEARCH}
diff --git a/themes/NEXT/components/SearchInput.js b/themes/NEXT/components/SearchInput.js index 2f6f86c4..48399f85 100644 --- a/themes/NEXT/components/SearchInput.js +++ b/themes/NEXT/components/SearchInput.js @@ -52,7 +52,7 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => { onChange={e => updateSearchKey(e.target.value)} defaultValue={searchKey} /> - {(searchKey && searchKey.length && )} + {(searchKey && searchKey.length && )}
{ handleSearch(searchKey) }}> From 0b2046b658d3ac680b492d082d3a5af406b2c4a4 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 1 Mar 2022 12:40:17 +0800 Subject: [PATCH 4/9] FontAwesomeCDN --- blog.config.js | 1 + pages/_app.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/blog.config.js b/blog.config.js index 6c22adf3..b1e5a876 100644 --- a/blog.config.js +++ b/blog.config.js @@ -14,6 +14,7 @@ const BLOG = { BEI_AN: process.env.NEXT_PUBLIC_BEI_AN || '', // 备案号 闽ICP备XXXXXXX APPEARANCE: 'auto', // ['light', 'dark', 'auto'], FONT: 'font-serif tracking-wider subpixel-antialiased', // 文章字体 ['font-sans', 'font-serif', 'font-mono'] @see https://www.tailwindcss.cn/docs/font-family + FONT_AWESOME_PATH: 'https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css', // 图标库CDN ,国内推荐BootCDN,国外推荐 CloudFlare https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css BACKGROUND_LIGHT: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc BACKGROUND_DARK: '#111827', // use hex value, don't forget '#' PATH: '', // leave this empty unless you want to deploy in a folder diff --git a/pages/_app.js b/pages/_app.js index 98c5abc1..e5b63150 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -27,7 +27,8 @@ const MyApp = ({ Component, pageProps }) => { {BLOG.ANALYTICS_GOOGLE_ID && } {JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && } {BLOG.ADSENSE_GOOGLE_ID && } - + {/* FontawesomeCDN */} + ) From b89177644fd0a90aba5fbd90a80fd14ed30ec095 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 1 Mar 2022 12:49:38 +0800 Subject: [PATCH 5/9] =?UTF-8?q?NEXT=E4=B8=BB=E9=A2=98=EF=BC=8C=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=A0=87=E7=AD=BE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 3 +++ lib/notion/getAllCategories.js | 22 ++++++++++++++++++---- lib/notion/getAllTags.js | 23 ++++++++++++----------- lib/notion/getNotionData.js | 15 ++++++++++++--- pages/category/index.js | 2 +- themes/NEXT/LayoutCategoryIndex.js | 8 ++++---- themes/NEXT/LayoutTagIndex.js | 2 +- themes/NEXT/components/CategoryGroup.js | 9 +++++---- themes/NEXT/components/CategoryList.js | 8 ++++---- themes/NEXT/components/SideAreaRight.js | 23 +++++++++-------------- 10 files changed, 69 insertions(+), 46 deletions(-) diff --git a/blog.config.js b/blog.config.js index b1e5a876..15718929 100644 --- a/blog.config.js +++ b/blog.config.js @@ -25,6 +25,9 @@ const BLOG = { POSTS_PER_PAGE: 6, // post counts per page POSTS_SORT_BY: 'notion', // 排序方式 'date'按时间,'notion'由notion控制 + PREVIEW_CATEGORY_COUNT: 16, // 首页最多展示的分类数量,0为不限制 + PREVIEW_TAG_COUNT: 16, // 首页最多展示的标签数量,0为不限制 + // 社交链接,不需要可留空白,例如 CONTACT_WEIBO:'' CONTACT_EMAIL: 'tlyong1992@hotmail.com', CONTACT_WEIBO: '', diff --git a/lib/notion/getAllCategories.js b/lib/notion/getAllCategories.js index 8e94e8ba..61aab49c 100644 --- a/lib/notion/getAllCategories.js +++ b/lib/notion/getAllCategories.js @@ -3,11 +3,11 @@ * @param allPosts * @returns {Promise<{}|*[]>} */ -export async function getAllCategories (allPosts) { - if (!allPosts) { +export async function getAllCategories ({ allPosts, categoryOptions, sliceCount = 0 }) { + if (!allPosts || !categoryOptions) { return [] } - + // 计数 let categories = allPosts.map(p => p.category) categories = [...categories.flat()] const categoryObj = {} @@ -18,5 +18,19 @@ export async function getAllCategories (allPosts) { categoryObj[category] = 1 } }) - return categoryObj + const list = [] + categoryOptions.forEach(c => { + 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) + if (sliceCount && sliceCount > 0) { + return list.slice(0, sliceCount) + } else { + return list + } } diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js index f1a9681b..3ac01f54 100644 --- a/lib/notion/getAllTags.js +++ b/lib/notion/getAllTags.js @@ -6,15 +6,13 @@ * @param tagOptions tags的下拉选项 * @returns {Promise<{}|*[]>} */ -export async function getAllTags ({ allPosts, sliceCount = 16, tagOptions }) { - if (!allPosts) { +export async function getAllTags ({ allPosts, sliceCount = 0, tagOptions }) { + if (!allPosts || !tagOptions) { return [] } - + // 计数 let tags = allPosts.map(p => p.tags) tags = [...tags.flat()] - - // 标签计数 const tagObj = {} tags.forEach(tag => { if (tag in tagObj) { @@ -23,13 +21,16 @@ export async function getAllTags ({ allPosts, sliceCount = 16, tagOptions }) { tagObj[tag] = 1 } }) - - // 按照标签数量排序 - const list = Object.keys(tagObj).map((tag) => { - const color = tagOptions.find(option => option.value === tag)?.color || 'gray' - return { name: tag, count: tagObj[tag], color } + const list = [] + 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) + + // 按照数量排序 + // list.sort((a, b) => b.count - a.count) if (sliceCount && sliceCount > 0) { return list.slice(0, sliceCount) } else { diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 7b4aebbe..dd26937e 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -11,6 +11,7 @@ import { getAllTags } from './getAllTags' * @param {*} pageId * @param {*} from * @param latestPostCount 截取最新文章数量 + * @param categoryCount * @param tagsCount 截取标签数量 * @param pageType 过滤的文章类型,数组格式 ['Page','Post'] * @returns { @@ -27,15 +28,17 @@ export async function getGlobalNotionData ({ pageId = BLOG.NOTION_PAGE_ID, from, latestPostCount = 5, - tagsCount = 16, + categoryCount = BLOG.PREVIEW_CATEGORY_COUNT, + tagsCount = BLOG.PREVIEW_TAG_COUNT, pageType = ['Post'] }) { const notionPageData = await getNotionPageData({ pageId, from }) const tagOptions = notionPageData.tagOptions + const categoryOptions = notionPageData.categoryOptions const allPosts = await getAllPosts({ notionPageData, from, pageType }) const postCount = await getAllPostCount({ notionPageData, from }) const customNav = await getCustomNav({ notionPageData }) - const categories = await getAllCategories(allPosts) + const categories = await getAllCategories({ allPosts, categoryOptions, sliceCount: categoryCount }) const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount }) const latestPosts = await getLatestPosts({ notionPageData, from, latestPostCount }) return { allPosts, latestPosts, categories, postCount, customNav, tags } @@ -110,6 +113,11 @@ function getTagOptions (schema) { return tagSchema?.options || {} } +function getCategoryOptions (schema) { + const categorySchema = Object.values(schema).find(e => e.name === 'category') + return categorySchema?.options || {} +} + /** * 调用NotionAPI获取Page数据 * @returns {Promise} @@ -119,7 +127,6 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) { if (!pageRecordMap) { return [] } - pageId = idToUuid(pageId) const collection = Object.values(pageRecordMap.collection)[0]?.value const collectionQuery = pageRecordMap.collection_query @@ -127,6 +134,7 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) { const schema = collection?.schema const rawMetadata = block[pageId].value const tagOptions = getTagOptions(schema) + const categoryOptions = getCategoryOptions(schema) // Check Type Page-Database和Inline-Database if ( @@ -143,6 +151,7 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) { block, schema, tagOptions, + categoryOptions, rawMetadata } } diff --git a/pages/category/index.js b/pages/category/index.js index f9739597..7361a706 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -8,7 +8,7 @@ export default function Category (props) { export async function getStaticProps () { const from = 'category-index-props' - const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from }) + const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from, categoryCount: 0 }) return { props: { diff --git a/themes/NEXT/LayoutCategoryIndex.js b/themes/NEXT/LayoutCategoryIndex.js index b4a5ef51..ac443a94 100644 --- a/themes/NEXT/LayoutCategoryIndex.js +++ b/themes/NEXT/LayoutCategoryIndex.js @@ -12,16 +12,16 @@ export const LayoutCategoryIndex = (props) => { type: 'website' } return -
+
{locale.COMMON.CATEGORY}:
- {Object.keys(categories).map(category => { - return + {categories.map(category => { + return
- {category}({categories[category]}) + {category.name}({category.count})
})} diff --git a/themes/NEXT/LayoutTagIndex.js b/themes/NEXT/LayoutTagIndex.js index 8ddd5bc4..b452874a 100644 --- a/themes/NEXT/LayoutTagIndex.js +++ b/themes/NEXT/LayoutTagIndex.js @@ -12,7 +12,7 @@ export const LayoutTagIndex = (props) => { type: 'website' } return -
+
{locale.COMMON.TAGS}:
{ tags.map(tag => { diff --git a/themes/NEXT/components/CategoryGroup.js b/themes/NEXT/components/CategoryGroup.js index a0c8eed0..1c22d04e 100644 --- a/themes/NEXT/components/CategoryGroup.js +++ b/themes/NEXT/components/CategoryGroup.js @@ -2,16 +2,17 @@ import Link from 'next/link' import React from 'react' const CategoryGroup = ({ currentCategory, categories }) => { + if (!categories) return <> return <>
- {Object.keys(categories).map(category => { - const selected = currentCategory === category - return + {categories.map(category => { + const selected = currentCategory === category.name + return - {category}({categories[category]}) + {category.name}({category.count}) })} diff --git a/themes/NEXT/components/CategoryList.js b/themes/NEXT/components/CategoryList.js index d7447424..5390a769 100644 --- a/themes/NEXT/components/CategoryList.js +++ b/themes/NEXT/components/CategoryList.js @@ -10,10 +10,10 @@ const CategoryList = ({ currentCategory, categories }) => { return