Update update-readme.js

This commit is contained in:
Aleksandr Statciuk 2021-10-15 19:59:42 +03:00
parent 5f9cf5130b
commit 6dba6ea503

View file

@ -18,29 +18,18 @@ async function main() {
data.push({ data.push({
countryFlag: country.flag, countryFlag: country.flag,
countryName: country.name, countryName: country.name,
stateName: country.state,
guideUrl: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'), guideUrl: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'),
channelCount: parsed.channels.length channelCount: parsed.channels.length
}) })
}) })
data = data data = data.sort((a, b) => {
.sort((a, b) => {
var countryNameA = a.countryName.toLowerCase() var countryNameA = a.countryName.toLowerCase()
var countryNameB = b.countryName.toLowerCase() var countryNameB = b.countryName.toLowerCase()
var stateNameA = a.stateName.toLowerCase()
var stateNameB = b.stateName.toLowerCase()
if (countryNameA < countryNameB) return -1 if (countryNameA < countryNameB) return -1
if (countryNameA > countryNameB) return 1 if (countryNameA > countryNameB) return 1
if (stateNameA < stateNameB) return -1
if (stateNameA > stateNameB) return 1
return b.channelCount - a.channelCount return b.channelCount - a.channelCount
}) })
.map(i => {
if (i.stateName) delete i.countryName
return i
})
console.log('Generating table...') console.log('Generating table...')
const table = generateTable(data, ['Country', 'Channels', 'EPG']) const table = generateTable(data, ['Country', 'Channels', 'EPG'])
@ -64,12 +53,10 @@ function generateTable(data, header) {
output += '\t<tbody>\n' output += '\t<tbody>\n'
for (let item of data) { for (let item of data) {
const size = data.filter(i => i.countryName && i.countryName === item.countryName).length const size = data.filter(i => i.countryName === item.countryName).length
let root = output.indexOf(item.countryName) === -1 let root = output.indexOf(item.countryName) === -1
const rowspan = root && size > 1 ? ` rowspan="${size}"` : '' const rowspan = root && size > 1 ? ` rowspan="${size}"` : ''
const name = item.stateName const name = item.countryName
? `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${item.stateName}`
: item.countryName
const cell1 = root const cell1 = root
? `<td align="left" valign="top" nowrap${rowspan}>${item.countryFlag}&nbsp;${name}</td>` ? `<td align="left" valign="top" nowrap${rowspan}>${item.countryFlag}&nbsp;${name}</td>`
: '' : ''