@@ -39,12 +39,12 @@ export function makeChanges(
3939 }
4040
4141 // リンクと画像の差分を入れる
42- const [ linksLc , image ] = findLinksAndImage ( right_ . join ( "\n" ) ) ;
42+ const [ links , image ] = findLinksAndImage ( right_ . join ( "\n" ) ) ;
4343 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 ) )
4646 ) {
47- changes . push ( { links : linksLc } ) ;
47+ changes . push ( { links } ) ;
4848 }
4949 if ( head . image !== image ) {
5050 changes . push ( { image } ) ;
@@ -67,19 +67,30 @@ function findLinksAndImage(text: string): [string[], string | null] {
6767 }
6868 } ) ;
6969
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 [ ] ;
7179 let image : string | null = null ;
7280
7381 const lookup = ( node : Node ) => {
7482 switch ( node . type ) {
7583 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 ) ;
7787 return ;
78- case "link" : {
88+ case "link" :
7989 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 ) ;
8193 return ;
82- }
8394 case "image" :
8495 case "strongImage" : {
8596 image ??= node . src . endsWith ( "/thumb/1000" )
@@ -103,7 +114,7 @@ function findLinksAndImage(text: string): [string[], string | null] {
103114 lookup ( node ) ;
104115 }
105116
106- return [ linksLc , image ] ;
117+ return [ links , image ] ;
107118}
108119
109120function * blocksToNodes ( blocks : Iterable < Block > ) {
0 commit comments