@@ -6,10 +6,9 @@ import formatDate from '../utils/formatDate'
6
6
import md5 from 'js-md5'
7
7
import { siteConfig } from '../config'
8
8
import {
9
- checkStartWithHttp ,
10
- convertUrlStartWithOneSlash ,
11
- getLastSegmentFromUrl ,
12
- sliceUrlFromHttp
9
+ checkStartWithHttp ,
10
+ convertUrlStartWithOneSlash ,
11
+ getLastSegmentFromUrl
13
12
} from '../utils'
14
13
import { extractLangPrefix } from '../utils/pageId'
15
14
import { mapImgUrl } from './mapImage'
@@ -188,29 +187,26 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
188
187
properties . name = properties . title ?? ''
189
188
}
190
189
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 ?. href ) ) {
192
+ properties . href = properties ?. slug
211
193
properties . target = '_blank'
212
194
} else {
213
195
properties . target = '_self'
196
+ // 伪静态路径右侧拼接.html
197
+ if ( siteConfig ( 'PSEUDO_STATIC' , false , NOTION_CONFIG ) ) {
198
+ if (
199
+ ! properties ?. href ?. endsWith ( '.html' ) &&
200
+ properties ?. href !== '' &&
201
+ properties ?. href !== '#' &&
202
+ properties ?. href !== '/'
203
+ ) {
204
+ properties . href += '.html'
205
+ }
206
+ }
207
+
208
+ // 相对路径转绝对路径:url左侧拼接 /
209
+ properties . href = convertUrlStartWithOneSlash ( properties ?. href )
214
210
}
215
211
216
212
// 如果跳转链接是多语言,则在新窗口打开
@@ -239,6 +235,10 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
239
235
* @returns
240
236
*/
241
237
function generateCustomizeSlug ( postProperties , NOTION_CONFIG ) {
238
+ // 外链不处理
239
+ if ( checkStartWithHttp ( postProperties . slug ) ) {
240
+ return postProperties . slug
241
+ }
242
242
let fullPrefix = ''
243
243
const allSlugPatterns = siteConfig (
244
244
'POST_URL_PREFIX' ,
@@ -290,5 +290,10 @@ function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
290
290
if ( fullPrefix . endsWith ( '/' ) ) {
291
291
fullPrefix = fullPrefix . substring ( 0 , fullPrefix . length - 1 ) // 去掉尾部部的"/"
292
292
}
293
- return `${ fullPrefix } /${ postProperties . slug ?? postProperties . id } `
293
+
294
+ if ( fullPrefix ) {
295
+ return `${ fullPrefix } /${ postProperties . slug ?? postProperties . id } `
296
+ } else {
297
+ return `${ postProperties . slug ?? postProperties . id } `
298
+ }
294
299
}
0 commit comments