@@ -26,13 +26,19 @@ export default (options: Options = {}): Metalsmith.Plugin => {
26
26
const debug = metalsmith . debug ( 'metalsmith-github-profile' ) ;
27
27
debug ( 'running with options: %O' , defaultedOptions ) ;
28
28
29
+ const normalizedFilenames = Object . keys ( files ) . map ( ( resource ) =>
30
+ resource . replace ( / [ / \\ ] / g, '/' ) ,
31
+ ) ;
32
+
29
33
// For each HTML file that matches the given pattern
30
34
metalsmith . match ( defaultedOptions . html , Object . keys ( files ) ) . forEach ( ( filename ) => {
31
35
debug ( 'processing file: %s' , filename ) ;
32
36
33
37
const file = files [ filename ] ;
34
38
const $ = cheerio . load ( file . contents ) ;
35
39
40
+ let fileChanged = false ;
41
+
36
42
// For each given tag
37
43
Object . keys ( defaultedOptions . tags ) . forEach ( ( tag ) => {
38
44
let attributes = defaultedOptions . tags [ tag ] ?? [ ] ;
@@ -70,9 +76,6 @@ export default (options: Options = {}): Metalsmith.Plugin => {
70
76
}
71
77
72
78
// Find all input files matching the glob in the tag
73
- const normalizedFilenames = Object . keys ( files ) . map ( ( resource ) =>
74
- resource . replace ( / [ / \\ ] / g, '/' ) ,
75
- ) ;
76
79
const resources = metalsmith
77
80
. match ( relativeGlob , normalizedFilenames )
78
81
. map ( ( resource ) => resource . replace ( / [ / \\ ] / g, '/' ) )
@@ -86,12 +89,15 @@ export default (options: Options = {}): Metalsmith.Plugin => {
86
89
resource . insertBefore ( $ ( elem ) ) ;
87
90
} ) ;
88
91
$ ( elem ) . remove ( ) ;
92
+ fileChanged = true ;
89
93
}
90
94
} ) ;
91
95
} ) ;
92
96
} ) ;
93
97
94
- file . contents = Buffer . from ( $ . html ( ) ) ;
98
+ if ( fileChanged ) {
99
+ file . contents = Buffer . from ( $ . html ( ) ) ;
100
+ }
95
101
} ) ;
96
102
97
103
done ( ) ;
0 commit comments