@@ -39,12 +39,12 @@ export function makeChanges(
39
39
}
40
40
41
41
// リンクと画像の差分を入れる
42
- const [ linksLc , image ] = findLinksAndImage ( right_ . join ( "\n" ) ) ;
42
+ const [ links , image ] = findLinksAndImage ( right_ . join ( "\n" ) ) ;
43
43
if (
44
- head . linksLc . length !== linksLc . length ||
45
- ! head . linksLc . every ( ( link ) => linksLc . includes ( link ) )
44
+ head . links . length !== links . length ||
45
+ ! head . links . every ( ( link ) => links . includes ( link ) )
46
46
) {
47
- changes . push ( { links : linksLc } ) ;
47
+ changes . push ( { links } ) ;
48
48
}
49
49
if ( head . image !== image ) {
50
50
changes . push ( { image } ) ;
@@ -67,19 +67,30 @@ function findLinksAndImage(text: string): [string[], string | null] {
67
67
}
68
68
} ) ;
69
69
70
- const linksLc = [ ] as string [ ] ;
70
+ /** 重複判定用map
71
+ *
72
+ * bracket link とhashtagを区別できるようにしている
73
+ * - bracket linkならtrue
74
+ *
75
+ * linkの形状はbracket linkを優先している
76
+ */
77
+ const linksLc = new Map < string , boolean > ( ) ;
78
+ const links = [ ] as string [ ] ;
71
79
let image : string | null = null ;
72
80
73
81
const lookup = ( node : Node ) => {
74
82
switch ( node . type ) {
75
83
case "hashTag" :
76
- linksLc . push ( toTitleLc ( node . href ) ) ;
84
+ if ( linksLc . has ( toTitleLc ( node . href ) ) ) return ;
85
+ linksLc . set ( toTitleLc ( node . href ) , false ) ;
86
+ links . push ( node . href ) ;
77
87
return ;
78
- case "link" : {
88
+ case "link" :
79
89
if ( node . pathType !== "relative" ) return ;
80
- linksLc . push ( toTitleLc ( node . href ) ) ;
90
+ if ( linksLc . get ( toTitleLc ( node . href ) ) ) return ;
91
+ linksLc . set ( toTitleLc ( node . href ) , true ) ;
92
+ links . push ( node . href ) ;
81
93
return ;
82
- }
83
94
case "image" :
84
95
case "strongImage" : {
85
96
image ??= node . src . endsWith ( "/thumb/1000" )
@@ -103,7 +114,7 @@ function findLinksAndImage(text: string): [string[], string | null] {
103
114
lookup ( node ) ;
104
115
}
105
116
106
- return [ linksLc , image ] ;
117
+ return [ links , image ] ;
107
118
}
108
119
109
120
function * blocksToNodes ( blocks : Iterable < Block > ) {
0 commit comments