mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-05 07:26:46 +00:00
Merge pull request #3419 from LooseLi/fix-eslint-errors
Fix eslint errors
This commit is contained in:
24
lib/cache/local_file_cache.js
vendored
24
lib/cache/local_file_cache.js
vendored
@@ -6,10 +6,10 @@ const cacheInvalidSeconds = 1000000000 * 1000
|
||||
// 文件名
|
||||
const jsonFile = path.resolve('./data.json')
|
||||
|
||||
export async function getCache (key) {
|
||||
const exist = await fs.existsSync(jsonFile)
|
||||
export function getCache(key) {
|
||||
const exist = fs.existsSync(jsonFile)
|
||||
if (!exist) return null
|
||||
const data = await fs.readFileSync(jsonFile)
|
||||
const data = fs.readFileSync(jsonFile)
|
||||
let json = null
|
||||
if (!data) return null
|
||||
try {
|
||||
@@ -19,7 +19,9 @@ export async function getCache (key) {
|
||||
return null
|
||||
}
|
||||
// 缓存超过有效期就作废
|
||||
const cacheValidTime = new Date(parseInt(json[key + '_expire_time']) + cacheInvalidSeconds)
|
||||
const cacheValidTime = new Date(
|
||||
parseInt(json[key + '_expire_time']) + cacheInvalidSeconds
|
||||
)
|
||||
const currentTime = new Date()
|
||||
if (!cacheValidTime || cacheValidTime < currentTime) {
|
||||
return null
|
||||
@@ -33,17 +35,17 @@ export async function getCache (key) {
|
||||
* @param data
|
||||
* @returns {Promise<null>}
|
||||
*/
|
||||
export async function setCache (key, data) {
|
||||
const exist = await fs.existsSync(jsonFile)
|
||||
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
|
||||
export function setCache(key, data) {
|
||||
const exist = fs.existsSync(jsonFile)
|
||||
const json = exist ? JSON.parse(fs.readFileSync(jsonFile)) : {}
|
||||
json[key] = data
|
||||
json[key + '_expire_time'] = new Date().getTime()
|
||||
fs.writeFileSync(jsonFile, JSON.stringify(json))
|
||||
}
|
||||
|
||||
export async function delCache (key) {
|
||||
const exist = await fs.existsSync(jsonFile)
|
||||
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
|
||||
export function delCache(key) {
|
||||
const exist = fs.existsSync(jsonFile)
|
||||
const json = exist ? JSON.parse(fs.readFileSync(jsonFile)) : {}
|
||||
delete json.key
|
||||
json[key + '_expire_time'] = new Date().getTime()
|
||||
fs.writeFileSync(jsonFile, JSON.stringify(json))
|
||||
@@ -52,7 +54,7 @@ export async function delCache (key) {
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
export async function cleanCache() {
|
||||
export function cleanCache() {
|
||||
const json = {}
|
||||
fs.writeFileSync(jsonFile, JSON.stringify(json))
|
||||
}
|
||||
|
||||
6
lib/cache/redis_cache.js
vendored
6
lib/cache/redis_cache.js
vendored
@@ -13,7 +13,7 @@ export async function getCache(key) {
|
||||
const data = await redisClient.get(key)
|
||||
return data ? JSON.parse(data) : null
|
||||
} catch (e) {
|
||||
console.error('redisClient读取失败 ' + e)
|
||||
console.error(`redisClient读取失败 ${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function setCache(key, data, customCacheTime) {
|
||||
customCacheTime || cacheTime
|
||||
)
|
||||
} catch (e) {
|
||||
console.error('redisClient写入失败 ' + e)
|
||||
console.error(`redisClient写入失败 ${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function delCache(key) {
|
||||
try {
|
||||
await redisClient.del(key)
|
||||
} catch (e) {
|
||||
console.error('redisClient删除失败 ' + e)
|
||||
console.error(`redisClient删除失败 ${String(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -267,12 +267,13 @@ async function convertNotionToSiteDate(pageId, from, pageRecordMap) {
|
||||
categoryOptions: getCategoryOptions(schema)
|
||||
})
|
||||
// 所有标签
|
||||
const tagSchemaOptions = getTagOptions(schema)
|
||||
const tagOptions =
|
||||
getAllTags({
|
||||
allPages,
|
||||
tagOptions: getTagOptions(schema),
|
||||
allPages: allPages ?? [],
|
||||
tagOptions: tagSchemaOptions ?? [],
|
||||
NOTION_CONFIG
|
||||
}) || null
|
||||
}) ?? null
|
||||
// 旧的菜单
|
||||
const customNav = getCustomNav({
|
||||
allPages: collectionData.filter(
|
||||
@@ -280,7 +281,7 @@ async function convertNotionToSiteDate(pageId, from, pageRecordMap) {
|
||||
)
|
||||
})
|
||||
// 新的菜单
|
||||
const customMenu = await getCustomMenu({ collectionData, NOTION_CONFIG })
|
||||
const customMenu = getCustomMenu({ collectionData, NOTION_CONFIG })
|
||||
const latestPosts = getLatestPosts({ allPages, from, latestPostCount: 6 })
|
||||
const allNavPages = getNavPages({ allPages })
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ export function GlobalContextProvider(props) {
|
||||
// 登录验证相关
|
||||
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
|
||||
const { isLoaded, isSignedIn, user } = enableClerk
|
||||
? useUser()
|
||||
? /* eslint-disable-next-line react-hooks/rules-of-hooks */
|
||||
useUser()
|
||||
: { isLoaded: true, isSignedIn: false, user: false }
|
||||
|
||||
// 是否全屏
|
||||
@@ -99,9 +100,11 @@ export function GlobalContextProvider(props) {
|
||||
|
||||
useEffect(() => {
|
||||
const handleStart = url => {
|
||||
const { theme } = router.query
|
||||
if (theme && !url.includes(`theme=${theme}`)) {
|
||||
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${theme}`
|
||||
const themeValue = router.query.theme
|
||||
const themeStr = Array.isArray(themeValue) ? themeValue[0] : themeValue
|
||||
|
||||
if (themeStr && !url.includes(`theme=${themeStr}`)) {
|
||||
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${themeStr}`
|
||||
router.push(newUrl)
|
||||
}
|
||||
if (!onLoading) {
|
||||
|
||||
@@ -1,16 +1,29 @@
|
||||
const axios = require('axios')
|
||||
import axios from 'axios'
|
||||
|
||||
// 定义内容项的接口
|
||||
interface ContentItem {
|
||||
type: string
|
||||
content: string
|
||||
}
|
||||
|
||||
// 定义Notion块的接口
|
||||
interface NotionBlock {
|
||||
object: string
|
||||
type: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
// 发送 Notion API 请求
|
||||
async function postNotion(
|
||||
properties: any,
|
||||
properties: Record<string, unknown>,
|
||||
databaseId: string,
|
||||
listContentMain: any[],
|
||||
listContentMain: ContentItem[],
|
||||
token: string
|
||||
) {
|
||||
): Promise<{ status: number; data: Record<string, unknown> }> {
|
||||
const url = 'https://api.notion.com/v1/pages'
|
||||
|
||||
const children = listContentMain
|
||||
.map(contentMain => {
|
||||
.map((contentMain: ContentItem): NotionBlock | null => {
|
||||
if (contentMain.type === 'paragraph') {
|
||||
return {
|
||||
object: 'block',
|
||||
@@ -51,14 +64,21 @@ async function postNotion(
|
||||
try {
|
||||
const response = await axios.post(url, payload, { headers })
|
||||
return response
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('写入Notion异常', error)
|
||||
throw new Error(`Error posting to Notion: ${error.message}`)
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(`Error posting to Notion: ${errorMessage}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 定义响应结果的接口
|
||||
interface NotionResponse {
|
||||
status: number
|
||||
data: Record<string, unknown>
|
||||
}
|
||||
|
||||
// 处理响应结果
|
||||
function responseResult(response: { status: number; data: any }) {
|
||||
function responseResult(response: NotionResponse): void {
|
||||
if (response.status === 200) {
|
||||
console.log('成功...')
|
||||
console.log(response.data)
|
||||
@@ -68,15 +88,25 @@ function responseResult(response: { status: number; data: any }) {
|
||||
}
|
||||
}
|
||||
|
||||
// 定义用户属性的接口
|
||||
interface UserProperties {
|
||||
id: string
|
||||
avatar: string
|
||||
name: string
|
||||
mail: string
|
||||
lastLoginTime: string
|
||||
token: string
|
||||
}
|
||||
|
||||
// 准备属性字段
|
||||
function notionProperty(
|
||||
id: any,
|
||||
avatar: any,
|
||||
name: any,
|
||||
mail: any,
|
||||
lastLoginTime: any,
|
||||
token: any
|
||||
) {
|
||||
id: string,
|
||||
avatar: string,
|
||||
name: string,
|
||||
mail: string,
|
||||
lastLoginTime: string,
|
||||
token: string
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
id: {
|
||||
rich_text: [
|
||||
|
||||
@@ -6,7 +6,7 @@ import algoliasearch from 'algoliasearch'
|
||||
* 生成全文索引
|
||||
* @param {*} allPages
|
||||
*/
|
||||
const generateAlgoliaSearch = async ({ allPages, force = false }) => {
|
||||
const generateAlgoliaSearch = ({ allPages, force = false }) => {
|
||||
allPages?.forEach(p => {
|
||||
// 判断这篇文章是否需要重新创建索引
|
||||
if (p && !p.password) {
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
/**
|
||||
* 订阅邮件-服务端接口
|
||||
* @param {*} email
|
||||
* @returns
|
||||
*/
|
||||
export default function subscribeToMailchimpApi({ email, first_name = '', last_name = '' }) {
|
||||
* 订阅邮件-服务端接口
|
||||
* @param {*} email
|
||||
* @returns
|
||||
*/
|
||||
export default function subscribeToMailchimpApi({
|
||||
email,
|
||||
first_name = '',
|
||||
last_name = ''
|
||||
}) {
|
||||
const listId = BLOG.MAILCHIMP_LIST_ID // 替换为你的邮件列表 ID
|
||||
const apiKey = BLOG.MAILCHIMP_API_KEY // 替换为你的 API KEY
|
||||
if (!email || !listId || !apiKey) {
|
||||
return {}
|
||||
return Promise.resolve({})
|
||||
}
|
||||
const data = {
|
||||
email_address: email,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from 'fs'
|
||||
|
||||
export async function generateRobotsTxt(props) {
|
||||
export function generateRobotsTxt(props) {
|
||||
const { siteInfo } = props
|
||||
const LINK = siteInfo?.link
|
||||
const content = `
|
||||
|
||||
@@ -5,7 +5,7 @@ import { siteConfig } from './config'
|
||||
* 生成站点地图
|
||||
* @param {*} param0
|
||||
*/
|
||||
export async function generateSitemapXml({ allPages, NOTION_CONFIG }) {
|
||||
export function generateSitemapXml({ allPages, NOTION_CONFIG }) {
|
||||
let link = siteConfig('LINK', BLOG.LINK, NOTION_CONFIG)
|
||||
// 确保链接不以斜杠结尾
|
||||
if (link && link.endsWith('/')) {
|
||||
|
||||
Reference in New Issue
Block a user