Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 25, 2024
2 parents 077e930 + 2c05ef0 commit f8ff251
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 54 deletions.
1 change: 1 addition & 0 deletions lib/lang/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
COMMON: {
THEME: 'Theme',
ARTICLE_LIST: 'Article List',
RECOMMEND_POSTS: 'Recommend Posts',
MORE: 'More',
NO_MORE: 'No More',
LATEST_POSTS: 'Latest posts',
Expand Down
1 change: 1 addition & 0 deletions lib/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
COMMON: {
THEME: 'Theme',
ARTICLE_LIST: '文章列表',
RECOMMEND_POSTS: '推荐文章',
MORE: '更多',
NO_MORE: '没有更多了',
LATEST_POSTS: '最新发布',
Expand Down
94 changes: 57 additions & 37 deletions lib/notion/getPostBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,49 +81,69 @@ export async function getPageWithRetry(id, from, retryAttempts = 3) {
function filterPostBlocks(id, blockMap, slice) {
const clonePageBlock = deepClone(blockMap)
let count = 0
const blocksToProcess = Object.keys(clonePageBlock?.block || {})

// 循环遍历文档的每个block
for (const i in clonePageBlock?.block) {
const b = clonePageBlock?.block[i]
if (slice && slice > 0 && count > slice) {
delete clonePageBlock?.block[i]
continue
for (let i = 0; i < blocksToProcess.length; i++) {
const blockId = blocksToProcess[i]
const b = clonePageBlock?.block[blockId]

if (slice && slice > 0 && count > slice) {
delete clonePageBlock?.block[blockId]
continue
}

// 当BlockId等于PageId时移除
if (b?.value?.id === id) {
// 此block含有敏感信息
delete b?.value?.properties
continue
}

count++

if (b?.value?.type === 'sync_block' && b?.value?.children) {
const childBlocks = b.value.children
// 移除同步块
delete clonePageBlock.block[blockId]
// 用子块替代同步块
childBlocks.forEach((childBlock, index) => {
const newBlockId = `${blockId}_child_${index}`
clonePageBlock.block[newBlockId] = childBlock
blocksToProcess.splice(i + index + 1, 0, newBlockId)
})
// 重新处理新加入的子块
i--
continue
}

// 处理 c++、c#、汇编等语言名字映射
if (b?.value?.type === 'code') {
if (b?.value?.properties?.language?.[0][0] === 'C++') {
b.value.properties.language[0][0] = 'cpp'
}
// 当BlockId等于PageId时移除
if (b?.value?.id === id) {
// 此block含有敏感信息
delete b?.value?.properties
continue
if (b?.value?.properties?.language?.[0][0] === 'C#') {
b.value.properties.language[0][0] = 'csharp'
}

count++
// 处理 c++、c#、汇编等语言名字映射
if (b?.value?.type === 'code') {
if (b?.value?.properties?.language?.[0][0] === 'C++') {
b.value.properties.language[0][0] = 'cpp'
}
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'
}
}

// 如果是文件,或嵌入式PDF,需要重新加密签名
if (
(b?.value?.type === 'file' ||
b?.value?.type === 'pdf' ||
b?.value?.type === 'video' ||
b?.value?.type === 'audio') &&
b?.value?.properties?.source?.[0][0] &&
b?.value?.properties?.source?.[0][0].indexOf('amazonaws.com') > 0
) {
const oldUrl = b?.value?.properties?.source?.[0][0]
const newUrl = `https://notion.so/signed/${encodeURIComponent(oldUrl)}?table=block&id=${b?.value?.id}`
b.value.properties.source[0][0] = newUrl
if (b?.value?.properties?.language?.[0][0] === 'Assembly') {
b.value.properties.language[0][0] = 'asm6502'
}
}

// 如果是文件,或嵌入式PDF,需要重新加密签名
if (
(b?.value?.type === 'file' ||
b?.value?.type === 'pdf' ||
b?.value?.type === 'video' ||
b?.value?.type === 'audio') &&
b?.value?.properties?.source?.[0][0] &&
b?.value?.properties?.source?.[0][0].indexOf('amazonaws.com') > 0
) {
const oldUrl = b?.value?.properties?.source?.[0][0]
const newUrl = `https://notion.so/signed/${encodeURIComponent(oldUrl)}?table=block&id=${b?.value?.id}`
b.value.properties.source[0][0] = newUrl
}
}

// 去掉不用的字段
if (id === BLOG.NOTION_PAGE_ID) {
Expand Down
2 changes: 1 addition & 1 deletion themes/heo/components/BlogPostCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const BlogPostCard = ({ index, post, showSummary, siteInfo }) => {
{/* 图片封面 */}
{showPageCover && (
<Link href={post?.href} passHref legacyBehavior>
<div className='w-full md:w-5/12 2xl:w-full overflow-hidden'>
<div className='w-full md:w-5/12 2xl:w-full overflow-hidden cursor-pointer select-none'>
<LazyImage
priority={index === 0}
src={post?.pageCoverThumbnail}
Expand Down
2 changes: 1 addition & 1 deletion themes/heo/components/Hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function TodayCard({ cRef, siteInfo }) {
}
/>
<div id='more' className='select-none'>
{locale.COMMON.MORE}
{locale.COMMON.RECOMMEND_POSTS}
</div>
</div>
</div>
Expand Down
35 changes: 27 additions & 8 deletions themes/medium/components/CategoryGroup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import { useGlobal } from '@/lib/global'
import CategoryItem from './CategoryItem'

/**
* 分类
* @param {*} param0
* @returns
*/
const CategoryGroup = ({ currentCategory, categoryOptions }) => {
const { locale } = useGlobal()
if (!categoryOptions) {
return <></>
}
return <div id='category-list' className='pt-4'>
<div className='mb-2'><i className='mr-2 fas fa-th' />分类</div>
<div className='flex flex-wrap'>
{categoryOptions?.map(category => {
const selected = currentCategory === category.name
return <CategoryItem key={category.name} selected={selected} category={category.name} categoryCount={category.count} />
})}
return (
<div id='category-list' className='pt-4'>
<div className='mb-2'>
<i className='mr-2 fas fa-th' />
{locale.COMMON.CATEGORY}
</div>
<div className='flex flex-wrap'>
{categoryOptions?.map(category => {
const selected = currentCategory === category.name
return (
<CategoryItem
key={category.name}
selected={selected}
category={category.name}
categoryCount={category.count}
/>
)
})}
</div>
</div>
</div>
)
}

export default CategoryGroup
17 changes: 10 additions & 7 deletions themes/medium/components/TagGroups.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useGlobal } from '@/lib/global'
import TagItemMini from './TagItemMini'

/**
Expand All @@ -8,17 +9,19 @@ import TagItemMini from './TagItemMini'
* @constructor
*/
const TagGroups = ({ tagOptions, currentTag }) => {
const { locale } = useGlobal()
if (!tagOptions) return <></>
return (
<div id='tags-group' className='dark:border-gray-600 py-4'>
<div className='mb-2'><i className='mr-2 fas fa-tag' />标签</div>
<div className='mb-2'>
<i className='mr-2 fas fa-tag' />
{locale.COMMON.TAGS}
</div>
<div className='space-y-2'>
{
tagOptions?.map(tag => {
const selected = tag.name === currentTag
return <TagItemMini key={tag.name} tag={tag} selected={selected} />
})
}
{tagOptions?.map(tag => {
const selected = tag.name === currentTag
return <TagItemMini key={tag.name} tag={tag} selected={selected} />
})}
</div>
</div>
)
Expand Down

0 comments on commit f8ff251

Please sign in to comment.