Update update-readme.js

This commit is contained in:
Aleksandr Statciuk 2021-10-15 05:51:20 +03:00
parent 8fe353e090
commit cf47dd2d4b

View file

@ -12,23 +12,35 @@ async function main() {
files.forEach(filename => { files.forEach(filename => {
const countryCode = filename.match(/\.gh\-pages\/guides\/(.*)\/.*/i)[1] const countryCode = filename.match(/\.gh\-pages\/guides\/(.*)\/.*/i)[1]
const country = countries.find(c => c.code === countryCode) const country = countries.find(c => c.code === countryCode)
if (!country) return
const epg = file.read(filename) const epg = file.read(filename)
const parsed = parser.parse(epg) const parsed = parser.parse(epg)
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.sort((a, b) => { data = data
var nameA = a.countryName.toLowerCase() .sort((a, b) => {
var nameB = b.countryName.toLowerCase() var countryNameA = a.countryName.toLowerCase()
if (nameA < nameB) return -1 var countryNameB = b.countryName.toLowerCase()
if (nameA > nameB) return 1 var stateNameA = a.stateName.toLowerCase()
return b.channelCount - a.channelCount var stateNameB = b.stateName.toLowerCase()
}) 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
})
.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'])
@ -52,11 +64,14 @@ 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 === item.countryName).length const size = data.filter(i => i.countryName && 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
? `&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;${item.countryName}</td>` ? `<td align="left" valign="top" nowrap${rowspan}>${item.countryFlag}&nbsp;${name}</td>`
: '' : ''
output += `\t\t<tr>${cell1}<td align="right" nowrap>${item.channelCount}</td><td align="left" nowrap><code>${item.guideUrl}</code></td></tr>\n` output += `\t\t<tr>${cell1}<td align="right" nowrap>${item.channelCount}</td><td align="left" nowrap><code>${item.guideUrl}</code></td></tr>\n`
} }