File tree 7 files changed +27
-7
lines changed
7 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -85,16 +85,13 @@ mixin make_comments
85
85
if theme .valine .enable == true
86
86
a#comments
87
87
#vcomments ( style ="margin: 0 30px" )
88
- script Anatolo.comment.load();
89
88
90
89
if theme .gitment
91
90
if theme .gitment .enable == true
92
91
a#comments
93
92
#gitment_container ( style ="padding: 10px" )
94
- script Anatolo.comment.load();
95
93
96
94
if theme .gitalk
97
95
if theme .gitalk .enable == true
98
96
a#comments
99
97
#gitalk_container ( style ="padding: 10px" )
100
- script Anatolo.comment.load();
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { darkLightToggle } from './dark-light-toggle';
4
4
import { site } from './site' ;
5
5
6
6
async function getPageTitle ( ) {
7
- return ( await site . thisPage ( ) ) . title ?? document . querySelector ( 'title' ) ?. textContent ;
7
+ return ( await site . thisPage ( ) ) ? .title ?? document . querySelector ( 'title' ) ?. textContent ?? '' ;
8
8
}
9
9
10
10
// Classes for interacting with elements in static HTML
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ let config: CommentConfig | null = null;
6
6
7
7
export async function load ( retry = 3 ) {
8
8
if ( ! config ) return ;
9
+ const id = ( await Anatolo . getPageTitle ( ) ) . slice ( 0 , 50 ) ;
10
+ if ( ! id ) return ;
9
11
if ( config . valine ?. enable && ( window as any ) . Valine ) {
10
12
new ( window as any ) . Valine ( {
11
13
el : '#vcomments' ,
@@ -21,7 +23,6 @@ export async function load(retry = 3) {
21
23
avatar : config . valine . avatar ,
22
24
} ) ;
23
25
}
24
- const id = ( await Anatolo . getPageTitle ( ) ) . slice ( 0 , 50 ) ;
25
26
if ( config . gitment ?. enable && ( window as any ) . Gitment ) {
26
27
var git_ment = {
27
28
id,
@@ -50,7 +51,7 @@ export async function load(retry = 3) {
50
51
}
51
52
}
52
53
53
- router . onPageChange ( load ) ;
54
+ router . onPageChange ( ( ) => load ( ) . catch ( ( ) => { } ) ) ;
54
55
55
56
export function setConfig ( conf : CommentConfig ) {
56
57
config = conf ;
Original file line number Diff line number Diff line change 1
1
import { make_friends_list } from '@/utils/main' ;
2
2
import { AnatoloRef } from './ref' ;
3
3
import { site } from './site' ;
4
+ import { loadScript } from '@/utils/load-script' ;
4
5
5
6
type RouterState = { url : string ; body : string ; title : string ; scrollY ?: number } ;
6
7
@@ -212,6 +213,7 @@ export class AnatoloRouter {
212
213
213
214
handlePage ( ) {
214
215
this . scrollToHash ( ) ;
216
+ this . reloadScript ( ) ;
215
217
this . pageChangeFns . forEach ( ( fn ) => {
216
218
try {
217
219
fn ( ) ;
@@ -229,6 +231,16 @@ export class AnatoloRouter {
229
231
onPageChange ( fn : ( ) => void ) {
230
232
this . pageChangeFns . push ( fn ) ;
231
233
}
234
+
235
+ reloadScript ( ) {
236
+ const body_scripts = document . querySelector ( 'main-outlet' ) ?. getElementsByTagName ( 'script' ) ;
237
+ for ( const script of body_scripts ?? [ ] ) {
238
+ loadScript ( {
239
+ url : script . src ,
240
+ script : script . textContent ,
241
+ } ) ;
242
+ }
243
+ }
232
244
}
233
245
234
246
export const router = new AnatoloRouter ( ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,6 @@ export const site = {
31
31
32
32
async thisPage ( ) {
33
33
await site . data ( ) ;
34
- return urlMap . get ( site . thisPageUrl ( ) ) as WebPage ;
34
+ return urlMap . get ( site . thisPageUrl ( ) ) ;
35
35
} ,
36
36
} ;
Original file line number Diff line number Diff line change
1
+ export async function loadScript ( config : { url ?: string | null ; script ?: string | null } ) {
2
+ if ( config . url ) {
3
+ config . script = await fetch ( config . url ) . then ( ( r ) => r . text ( ) ) ;
4
+ }
5
+ if ( ! config . script ) {
6
+ return ;
7
+ }
8
+ const runner = new Function ( config . script ) ;
9
+ runner ( ) ;
10
+ }
You can’t perform that action at this time.
0 commit comments