-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_logo_table.js
More file actions
52 lines (42 loc) · 1.54 KB
/
generate_logo_table.js
File metadata and controls
52 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { readdirSync, readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const README_PATH = resolve(__dirname, '..', 'README.md')
const LOGO_EXPORT_PATH = resolve(__dirname, '..', 'logo', 'export')
const LOGO_RELATIVE_BASE = 'logo/export'
const LOGO_TABLE_START = '<!-- LOGO_TABLE_START -->'
const LOGO_TABLE_END = '<!-- LOGO_TABLE_END -->'
const exportedLogos = readdirSync(LOGO_EXPORT_PATH)
const svgLogos = exportedLogos.filter(filename => filename.endsWith('.svg'))
let table = `
<table>
<thead>
<tr>
<th>Logo</th>
<th>Download</th>
</tr>
</thead>
<tbody>\n`
for(const logo of svgLogos) {
const name = logo.replace('.svg', '').replace(/_/g, ' ')
const svgURL = `${LOGO_RELATIVE_BASE}/${logo}`
const pngURL = `${LOGO_RELATIVE_BASE}/${logo.replace('.svg', '.png')}`
console.log({
name,
svgURL,
pngURL
})
const row = [
`<img style="width: 100px;" src="${svgURL}" />`,
`\n[Download SVG](${svgURL})<br>\n[Download PNG](${pngURL})`
].map(e => `<td>\n${e}\n</td>`).join('\n')
table += `<tr>\n<td colspan="2">\n${name}\n</td>\n</tr>\n`
table += `<tr>\n${row}\n</tr>\n`
}
table += `</tbody>\n</table>`
const readmeContent = readFileSync(README_PATH).toString();
const updatedReadmeContent = `
${readmeContent.substr(0, readmeContent.indexOf(LOGO_TABLE_START) + LOGO_TABLE_START.length)}
${table}
${readmeContent.substr(readmeContent.indexOf(LOGO_TABLE_END), readmeContent.length)}
`.trim()
writeFileSync(README_PATH, updatedReadmeContent)