File tree 1 file changed +17
-1
lines changed
.vitepress/theme/composables
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -35,14 +35,30 @@ export default createContentLoader(POST_FILES, {
35
35
categories : frontmatter ?. categories ?? [ ] ,
36
36
tags : frontmatter . tags ?? [ ] ,
37
37
url : url ,
38
- excerpt,
38
+ excerpt : updateImageSrc ( excerpt , url ) ,
39
39
date : formatDate ( frontmatter . date ) ,
40
40
}
41
41
} )
42
42
. sort ( ( a , b ) => b . date . time - a . date . time )
43
43
} ,
44
44
} )
45
45
46
+ /**
47
+ * 更新 excerpt 中 <img> 标签的 src 属性
48
+ * @param {string } excerpt - 原始的 excerpt 字符串
49
+ * @param {string } urlPrefix - 要拼接的 URL 前缀
50
+ * @returns {string } 更新后的 excerpt 字符串
51
+ */
52
+ function updateImageSrc ( excerpt : string | undefined , urlPrefix : string ) {
53
+ if ( excerpt == undefined ) return
54
+ return excerpt . replace (
55
+ / < i m g \s + ( [ ^ > ] * ?) s r c = [ " ' ] \. \/ ( [ ^ " ' ] * ?) [ " ' ] ( [ ^ > ] * ?) > / gi,
56
+ ( match , p1 , p2 , p3 ) => {
57
+ return `<img ${ p1 } src="${ urlPrefix } ${ p2 } "${ p3 } >`
58
+ }
59
+ )
60
+ }
61
+
46
62
function generateTitle (
47
63
frontmatter : Record < string , any > ,
48
64
src : string | undefined
You can’t perform that action at this time.
0 commit comments