@@ -40,18 +40,24 @@ async function generateChangelogFromGitHubReleases(paths, repo) {
40
40
} ) ;
41
41
42
42
paths . forEach ( ( p ) => {
43
- fs . writeFileSync ( ` ${ p } / changelog.md` , updateChangelog ( markdown ) ) ;
43
+ fs . writeFileSync ( path . join ( p , ' changelog.md' ) , updateChangelog ( markdown ) ) ;
44
44
} ) ;
45
45
}
46
46
47
- function copyChangelogFromRoot ( paths ) {
48
- const changelogPath = findPathInParentOrThrow ( 'CHANGELOG.md' ) ;
47
+ function copyChangelogFromRoot ( paths , hasDefaultChangelog ) {
48
+ const sourceChangelogPath = findPathInParentOrThrow ( 'CHANGELOG.md' ) ;
49
49
50
50
for ( const docsPath of paths ) {
51
- if ( fs . existsSync ( path . join ( docsPath , 'changelog.md' ) ) && fs . statSync (
52
- path . join ( docsPath , 'changelog.md' ) ) . mtime >= fs . statSync ( changelogPath ) . mtime ) continue ;
53
- const changelog = fs . readFileSync ( changelogPath , 'utf-8' ) ;
54
- fs . writeFileSync ( `${ docsPath } /changelog.md` , updateChangelog ( changelog ) ) ;
51
+ const targetChangelogPath = path . join ( docsPath , 'changelog.md' ) ;
52
+
53
+ if ( fs . existsSync ( targetChangelogPath )
54
+ && fs . statSync ( targetChangelogPath ) . mtime >= fs . statSync ( sourceChangelogPath ) . mtime
55
+ && ! hasDefaultChangelog . get ( docsPath ) ) {
56
+ continue ;
57
+ }
58
+
59
+ const changelog = fs . readFileSync ( sourceChangelogPath , 'utf-8' ) ;
60
+ fs . writeFileSync ( targetChangelogPath , updateChangelog ( changelog ) ) ;
55
61
}
56
62
}
57
63
@@ -81,11 +87,7 @@ function theme(
81
87
) ,
82
88
] ;
83
89
84
- if ( options . changelogFromRoot ) {
85
- copyChangelogFromRoot ( pathsToCopyChangelog ) ;
86
- } else {
87
- await generateChangelogFromGitHubReleases ( pathsToCopyChangelog , `${ context . siteConfig . organizationName } /${ context . siteConfig . projectName } ` ) ;
88
- }
90
+ const hasDefaultChangelog = new Map ( ) ;
89
91
90
92
for ( const p of pathsToCopyChangelog ) {
91
93
// the changelog page has to exist for the sidebar to work - async loadContent() is (apparently) not awaited for by sidebar
@@ -97,6 +99,13 @@ sidebar_label: Changelog
97
99
It seems that the changelog is not available.
98
100
This either means that your Docusaurus setup is misconfigured, or that your GitHub repository contains no releases yet.
99
101
` ) ;
102
+ hasDefaultChangelog . set ( p , true ) ;
103
+ }
104
+
105
+ if ( options . changelogFromRoot ) {
106
+ copyChangelogFromRoot ( pathsToCopyChangelog , hasDefaultChangelog ) ;
107
+ } else {
108
+ await generateChangelogFromGitHubReleases ( pathsToCopyChangelog , `${ context . siteConfig . organizationName } /${ context . siteConfig . projectName } ` ) ;
100
109
}
101
110
} catch ( e ) {
102
111
// eslint-disable-next-line no-console
0 commit comments