Skip to content

Commit 9375ec4

Browse files
committed
2 parents 544abe8 + 40ef1ac commit 9375ec4

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

lib/db/getSiteData.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
526526
return (
527527
post &&
528528
post?.slug &&
529-
!post?.slug?.startsWith('http') &&
529+
// !post?.slug?.startsWith('http') &&
530530
(post?.status === 'Invisible' || post?.status === 'Published')
531531
)
532532
})

lib/notion/getPageProperties.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import { siteConfig } from '../config'
88
import {
99
checkStartWithHttp,
1010
convertUrlStartWithOneSlash,
11-
getLastSegmentFromUrl,
12-
sliceUrlFromHttp
11+
getLastSegmentFromUrl
1312
} from '../utils'
1413
import { extractLangPrefix } from '../utils/pageId'
1514
import { mapImgUrl } from './mapImage'
@@ -188,29 +187,26 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
188187
properties.name = properties.title ?? ''
189188
}
190189

191-
// 开启伪静态路径
192-
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
193-
if (
194-
!properties?.href?.endsWith('.html') &&
195-
!properties?.href?.startsWith('http') &&
196-
properties?.href !== '' &&
197-
properties?.href !== '#' &&
198-
properties?.href !== '/'
199-
) {
200-
properties.href += '.html'
201-
}
202-
}
203-
204-
// 检查处理外链
205-
properties.href = checkStartWithHttp(properties?.href)
206-
? sliceUrlFromHttp(properties?.href)
207-
: convertUrlStartWithOneSlash(properties?.href)
208-
209-
// 设置链接在页内或新页面打开
210-
if (properties.href?.indexOf('http') === 0) {
190+
// http or https 开头的视为外链
191+
if (checkStartWithHttp(properties?.slug)) {
192+
properties.href = properties?.slug
211193
properties.target = '_blank'
212194
} else {
213195
properties.target = '_self'
196+
// 伪静态路径右侧拼接.html
197+
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
198+
if (
199+
!properties?.href?.endsWith('.html') &&
200+
!properties?.href?.startsWith('http') &&
201+
properties?.href !== '' &&
202+
properties?.href !== '#' &&
203+
properties?.href !== '/'
204+
) {
205+
properties.href += '.html'
206+
}
207+
}
208+
// 相对路径转绝对路径:url左侧拼接 /
209+
convertUrlStartWithOneSlash(properties?.href)
214210
}
215211

216212
// 如果跳转链接是多语言,则在新窗口打开
@@ -239,6 +235,10 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
239235
* @returns
240236
*/
241237
function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
238+
// 外链不处理
239+
if (checkStartWithHttp(postProperties.slug)) {
240+
return postProperties.slug
241+
}
242242
let fullPrefix = ''
243243
const allSlugPatterns = siteConfig(
244244
'POST_URL_PREFIX',

lib/utils/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export const memorize = Component => {
4747
return memo(MemoizedComponent)
4848
}
4949

50-
// 转换外链
50+
/**
51+
* 诸如 article/https://test.com 等被错误拼接前缀的slug进行处理
52+
* 转换为 https://test.com
53+
* @param {*} str
54+
* @returns
55+
*/
5156
export function sliceUrlFromHttp(str) {
5257
// 检查字符串是否包含http
5358
if (str?.includes('http:') || str?.includes('https:')) {
@@ -99,7 +104,7 @@ export function checkStartWithHttp(str) {
99104
// 检查字符串是否包含http
100105
if (str?.indexOf('http:') === 0 || str?.indexOf('https:') === 0) {
101106
// 如果包含,找到http的位置
102-
return str?.indexOf('http') > -1
107+
return true
103108
} else {
104109
// 不包含
105110
return false

pages/sitemap.xml.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function generateLocalesSitemap(link, allPages, locale) {
5555
priority: '0.7'
5656
},
5757
{
58-
loc: `${link}${locale}/feed`,
58+
loc: `${link}${locale}/rss/feed.xml`,
5959
lastmod: new Date().toISOString().split('T')[0],
6060
changefreq: 'daily',
6161
priority: '0.7'

0 commit comments

Comments
 (0)