@@ -6,6 +6,7 @@ import dropdown from "./alpine-data/dropdown";
6
6
import colorSchemeSwitcher from "./alpine-data/color-scheme-switcher" ;
7
7
import pagination from "./alpine-data/pagination" ;
8
8
import postUtil from "./alpine-data/post-util" ;
9
+ import search from "./alpine-data/search" ;
9
10
10
11
window . Alpine = Alpine ;
11
12
@@ -15,6 +16,8 @@ Alpine.data("colorSchemeSwitcher", colorSchemeSwitcher);
15
16
Alpine . data ( "pagination" , pagination ) ;
16
17
// @ts -ignore
17
18
Alpine . data ( "postUtil" , postUtil ) ;
19
+ // @ts -ignore
20
+ Alpine . data ( "search" , search ) ;
18
21
19
22
Alpine . start ( ) ;
20
23
@@ -83,22 +86,28 @@ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", fun
83
86
} ) ;
84
87
85
88
/*移除HTML标签代码*/
86
- export function removeHTMLTag ( str : String ) {
87
- str = str . replace ( / < .* ?> / g, '' ) ; //去除HTML tag
88
- str = str . replace ( / < \/ ? [ ^ > ] * > / g, '' ) ; //去除HTML tag
89
- str = str . replace ( / [ | ] * \n / g, '\n' ) ; //去除行尾空
90
- str = str . replace ( / \n [ \s | | ] * \r / g, '\n' ) ; //去除多余空行
91
- str = str . replace ( / / ig , '' ) ; //去掉
89
+ export function removeHTMLTag ( str : String ) {
90
+ str = str . replace ( / < .* ?> / g, "" ) ; //去除HTML tag
91
+ str = str . replace ( / < \/ ? [ ^ > ] * > / g, "" ) ; //去除HTML tag
92
+ str = str . replace ( / [ | ] * \n / g, "\n" ) ; //去除行尾空
93
+ str = str . replace ( / \n [ \s | | ] * \r / g, "\n" ) ; //去除多余空行
94
+ str = str . replace ( / / gi , "" ) ; //去掉
92
95
// str = str.replace(/[a-zA-Z]+/g, ''); //去除字母
93
96
return str ;
94
97
}
95
98
96
99
/*阅读时间*/
97
- export function readTime ( ) {
100
+ export function readTime ( ) {
98
101
const contentHtml : HTMLElement | null = document . getElementById ( "content" ) ;
99
102
// @ts -ignore
100
- let str = contentHtml . innerHTML
101
- return '文章共计 ' + removeHTMLTag ( str ) . length + ' 个字,阅读完成需要 ' + Math . ceil ( removeHTMLTag ( str ) . length / 400 ) + ' 分钟' ;
103
+ let str = contentHtml . innerHTML ;
104
+ return (
105
+ "文章共计 " +
106
+ removeHTMLTag ( str ) . length +
107
+ " 个字,阅读完成需要 " +
108
+ Math . ceil ( removeHTMLTag ( str ) . length / 400 ) +
109
+ " 分钟"
110
+ ) ;
102
111
}
103
112
104
113
// 快速返回顶部或底部
@@ -108,7 +117,7 @@ const onScrollToTop = () => {
108
117
if ( window . scrollY < 100 ) {
109
118
backToTop ?. classList . add ( "hidden" ) ;
110
119
backToDown ?. classList . add ( "hidden" ) ;
111
- } else if ( window . scrollY > 300 ) {
120
+ } else if ( window . scrollY > 300 ) {
112
121
backToTop ?. classList . remove ( "hidden" ) ;
113
122
backToDown ?. classList . add ( "hidden" ) ;
114
123
} else {
@@ -118,5 +127,3 @@ const onScrollToTop = () => {
118
127
} ;
119
128
120
129
window . addEventListener ( "scroll" , onScrollToTop ) ;
121
-
122
-
0 commit comments