@@ -2,22 +2,19 @@ import fs from "fs";
2
2
import { themes } from "../themes/index.js" ;
3
3
4
4
const TARGET_FILE = "./themes/README.md" ;
5
- const LINKS_FLAG_MAP = {
6
- repo :"<!-- REPO_CARD_LINKS -->" ,
7
- stats :"<!-- STATS_CARD_LINKS -->" ,
8
- } ;
9
- const TABLE_FLAG_MAP = {
10
- repo :"<!-- REPO_CARD_TABLE -->" ,
11
- stats :"<!-- STATS_CARD_TABLE -->" ,
12
- } ;
5
+ const REPO_CARD_LINKS_FLAG = "<!-- REPO_CARD_LINKS -->" ;
6
+ const STAT_CARD_LINKS_FLAG = "<!-- STATS_CARD_LINKS -->" ;
7
+
8
+ const STAT_CARD_TABLE_FLAG = "<!-- STATS_CARD_TABLE -->" ;
9
+ const REPO_CARD_TABLE_FLAG = "<!-- REPO_CARD_TABLE -->" ;
13
10
14
11
const THEME_TEMPLATE = `## Available Themes
15
12
16
13
<!-- DO NOT EDIT THIS FILE DIRECTLY -->
17
14
18
15
With inbuilt themes, you can customize the look of the card without doing any manual customization.
19
16
20
- Use \`?theme=THEME_NAME\` parameter like so:
17
+ Use \`?theme=THEME_NAME\` parameter like so :-
21
18
22
19
\`\`\`md
23
20

@@ -29,44 +26,44 @@ Use \`?theme=THEME_NAME\` parameter like so:
29
26
30
27
| | | |
31
28
| :--: | :--: | :--: |
32
- ${ TABLE_FLAG_MAP . stats }
29
+ ${ STAT_CARD_TABLE_FLAG }
33
30
34
31
## Repo Card
35
32
36
33
> These themes work both for the Stats Card and Repo Card.
37
34
38
35
| | | |
39
36
| :--: | :--: | :--: |
40
- ${ TABLE_FLAG_MAP . repo }
37
+ ${ REPO_CARD_TABLE_FLAG }
41
38
42
- ${ LINKS_FLAG_MAP . stats }
39
+ ${ STAT_CARD_LINKS_FLAG }
40
+
41
+ ${ REPO_CARD_LINKS_FLAG }
43
42
44
- ${ LINKS_FLAG_MAP . repo }
45
43
46
44
[add-theme]: https://github.com/anuraghazra/github-readme-stats/edit/master/themes/index.js
47
45
48
46
Want to add a new theme? Consider reading the [contribution guidelines](../CONTRIBUTING.md#themes-contribution) :D
49
47
` ;
50
48
51
- const createMdLink = ( theme , type ) => {
52
- const baseLink =
53
- type === "repo"
54
- ?"api/pin/?username=anuraghazra&repo=github-readme-stats"
55
- :"api?username=anuraghazra" ;
56
- return `\n[${ theme } ]: https://github-readme-stats.vercel.app/${ baseLink } &cache_seconds=86400&theme=${ theme } ` ;
49
+ const createRepoMdLink = ( theme ) => {
50
+ return `\n[${ theme } _repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=${ theme } ` ;
51
+ } ;
52
+ const createStatMdLink = ( theme ) => {
53
+ return `\n[${ theme } ]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=${ theme } ` ;
57
54
} ;
58
55
59
- const generateLinks = ( type ) => {
56
+ const generateLinks = ( fn ) => {
60
57
return Object . keys ( themes )
61
- . map ( ( name ) => createMdLink ( name , type ) )
58
+ . map ( ( name ) => fn ( name ) )
62
59
. join ( "" ) ;
63
60
} ;
64
61
65
- const createTableItem = ( { link, label} ) => {
62
+ const createTableItem = ( { link, label, isRepoCard } ) => {
66
63
if ( ! link || ! label ) {
67
64
return "" ;
68
65
}
69
- return `\`${ label } \` ![${ link } ][${ link } ]` ;
66
+ return `\`${ label } \` ![${ link } ][${ link } ${ isRepoCard ? "_repo" : "" } ]` ;
70
67
} ;
71
68
72
69
const generateTable = ( { isRepoCard} ) => {
@@ -76,23 +73,22 @@ const generateTable = ({ isRepoCard }) => {
76
73
) ;
77
74
78
75
for ( let i = 0 ; i < themesFiltered . length ; i += 3 ) {
79
- const [ one , two , three ] = themesFiltered . slice ( i , i + 3 ) ;
80
-
81
- const tableItem1 = createTableItem ( { link :one , label :one } ) ;
82
- const tableItem2 = createTableItem ( { link :two , label :two } ) ;
83
- const tableItem3 = createTableItem ( { link :three , label :three } ) ;
84
-
85
- if ( i + 3 >= themesFiltered . length ) {
86
- // If last row add your theme placeholder.
87
- if ( ! three ) {
88
- rows . push (
89
- `${ tableItem1 } |${ tableItem2 } | [Add your theme][add-theme] |` ,
90
- ) ;
91
- } else {
92
- rows . push ( `| [Add your theme][add-theme] | | |` ) ;
93
- }
94
- } else {
95
- rows . push ( `|${ tableItem1 } |${ tableItem2 } |${ tableItem3 } |` ) ;
76
+ const one = themesFiltered [ i ] ;
77
+ const two = themesFiltered [ i + 1 ] ;
78
+ const three = themesFiltered [ i + 2 ] ;
79
+
80
+ let tableItem1 = createTableItem ( { link :one , label :one , isRepoCard} ) ;
81
+ let tableItem2 = createTableItem ( { link :two , label :two , isRepoCard} ) ;
82
+ let tableItem3 = createTableItem ( { link :three , label :three , isRepoCard} ) ;
83
+
84
+ if ( three === undefined ) {
85
+ tableItem3 = `[Add your theme][add-theme]` ;
86
+ }
87
+ rows . push ( `|${ tableItem1 } |${ tableItem2 } |${ tableItem3 } |` ) ;
88
+
89
+ // if it's the last row & the row has no empty space push a new row
90
+ if ( three && i + 3 === themesFiltered . length ) {
91
+ rows . push ( `| [Add your theme][add-theme] | | |` ) ;
96
92
}
97
93
}
98
94
@@ -102,16 +98,16 @@ const generateTable = ({ isRepoCard }) => {
102
98
const buildReadme = ( ) => {
103
99
return THEME_TEMPLATE . split ( "\n" )
104
100
. map ( ( line ) => {
105
- if ( line . includes ( LINKS_FLAG_MAP . repo ) ) {
106
- return generateLinks ( "repo" ) ;
101
+ if ( line . includes ( REPO_CARD_LINKS_FLAG ) ) {
102
+ return generateLinks ( createRepoMdLink ) ;
107
103
}
108
- if ( line . includes ( LINKS_FLAG_MAP . stats ) ) {
109
- return generateLinks ( "stats" ) ;
104
+ if ( line . includes ( STAT_CARD_LINKS_FLAG ) ) {
105
+ return generateLinks ( createStatMdLink ) ;
110
106
}
111
- if ( line . includes ( TABLE_FLAG_MAP . repo ) ) {
107
+ if ( line . includes ( REPO_CARD_TABLE_FLAG ) ) {
112
108
return generateTable ( { isRepoCard :true } ) ;
113
109
}
114
- if ( line . includes ( TABLE_FLAG_MAP . stats ) ) {
110
+ if ( line . includes ( STAT_CARD_TABLE_FLAG ) ) {
115
111
return generateTable ( { isRepoCard :false } ) ;
116
112
}
117
113
return line ;
@@ -120,5 +116,3 @@ const buildReadme = () => {
120
116
} ;
121
117
122
118
fs . writeFileSync ( TARGET_FILE , buildReadme ( ) ) ;
123
-
124
- console . log ( "README.md updated successfully!" ) ;