@@ -11,23 +11,29 @@ function generateThemeLink(username: string, theme: string): string {
11
11
return `[${ theme } ]: https://github-readme-profile-alpha.vercel.app/api?username=${ username } &theme=${ theme } ` ;
12
12
}
13
13
14
+ function createThemeRows (
15
+ themesArray : string [ ] ,
16
+ itemsPerRow : number ,
17
+ username : string
18
+ ) : { themesPreviewTable : string ; themesPreviewLink : string } {
19
+ let themesPreviewTable = "" ;
20
+ let themesPreviewLink = "" ;
21
+
22
+ for ( let i = 0 ; i < themesArray . length ; i += itemsPerRow ) {
23
+ const rowThemes = themesArray . slice ( i , i + itemsPerRow ) ;
24
+
25
+ themesPreviewTable += `| ${ rowThemes . map ( generateThemeMarkdown ) . join ( " | " ) } |\n` ;
26
+ themesPreviewLink += rowThemes . map ( theme => generateThemeLink ( username , theme ) ) . join ( "\n" ) + "\n" ;
27
+ }
28
+
29
+ return { themesPreviewTable, themesPreviewLink } ;
30
+ }
31
+
14
32
export function generateReadmeThemes ( username : string ) : string {
15
33
const availableThemes = Object . keys ( themes ) ;
16
34
const itemsPerRow = 3 ;
17
35
18
- let themesPreviewTable = "" ;
19
- for ( let i = 0 ; i < availableThemes . length ; i += itemsPerRow ) {
20
- const themesSlice = availableThemes . slice ( i , i + itemsPerRow ) ;
21
- const row = themesSlice . map ( theme => generateThemeMarkdown ( theme ) ) . join ( " | " ) ;
22
- themesPreviewTable += `| ${ row } |\n` ;
23
- }
24
-
25
- let themesPreviewLink = "" ;
26
- for ( let i = 0 ; i < availableThemes . length ; i += 1 ) {
27
- const themesSlice = availableThemes . slice ( i , i + 1 ) ;
28
- const row = themesSlice . map ( theme => generateThemeLink ( username , theme ) ) . join ( "\n" ) ;
29
- themesPreviewLink += `${ row } \n` ;
30
- }
36
+ const { themesPreviewTable, themesPreviewLink } = createThemeRows ( availableThemes , itemsPerRow , username ) ;
31
37
32
38
const readmeContent = `<!-- DO NOT EDIT THIS FILE DIRECTLY -->
33
39
## Available Themes
0 commit comments