Update website

- faster site loading
- added more channels
This commit is contained in:
Aleksandr Statciuk 2022-01-25 20:51:23 +03:00
parent 7fb8250025
commit 3f5ff5b671
2 changed files with 208 additions and 193 deletions

View file

@ -1,54 +1,158 @@
document.addEventListener('alpine:init', () => { const ChannelItem = {
Alpine.data('list', () => ({ props: ['channel'],
isLoading: true, template: `
query: '', <tr>
_query: '', <td class="is-vcentered" style="min-width: 150px; text-align: center">
items: [], <img
loading="lazy"
v-show="channel.logo"
:src="channel.logo"
style="max-width: 100px; max-height: 50px; vertical-align: middle"
/>
</td>
<td class="is-vcentered" nowrap>
<p v-text="channel.name"></p>
</td>
<td class="is-vcentered" nowrap>
<code v-text="channel.id"></code>
</td>
<td class="is-vcentered">
<p v-for="guide in channel.guides"><code style="white-space: nowrap" v-text="guide"></code></p>
</td>
</tr>
`
}
search() { const CountryItem = {
this._query = this.query.toLowerCase() components: {
}, ChannelItem
},
async init() { props: ['item', 'query'],
const countries = await fetch('api/countries.json') data() {
.then(response => response.json()) return {
.catch(console.log) count: 0
const channels = await fetch('api/channels.json')
.then(response => response.json())
.catch(console.log)
let items = {}
for (let channel of channels) {
if (!items[channel.country]) {
if (!countries[channel.country]) {
console.log('Warning: Wrong country code', channel)
continue
}
const country = countries[channel.country]
items[channel.country] = {
flag: country.flag,
name: country.name,
expanded: false,
channels: []
}
}
channel.hash = `${channel.id}_${channel.name}`.toLowerCase()
items[channel.country].channels.push(channel)
}
items = Object.values(items).sort((a, b) => {
if (a.name > b.name) return 1
if (a.name < b.name) return -1
return 0
})
this.items = items
this.isLoading = false
} }
})) },
}) computed: {
countryChannels() {
if (!this.query) return this.item.channels
return (
this.item.channels.filter(c => {
return c.key.includes(this.query)
}) || []
)
}
},
watch: {
countryChannels: function (value) {
this.count = value.length
}
},
template: `
<div
class="card mb-3 is-shadowless"
style="border: 1px solid #dbdbdb"
v-show="countryChannels && countryChannels.length > 0"
>
<div
class="card-header is-shadowless is-clickable"
@click="item.expanded = !item.expanded"
>
<span class="card-header-title">{{item.flag}}&nbsp;{{item.name}}</span>
<button class="card-header-icon" aria-label="more options">
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">
<path
v-show="!item.expanded"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="48"
d="M112 184l144 144 144-144"
/>
<path
v-show="item.expanded"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="48"
d="M112 328l144-144 144 144"
/>
</svg>
</span>
</button>
</div>
<div class="card-content" v-show="item.expanded || (count > 0 && query.length)">
<div class="table-container">
<table class="table" style="min-width: 100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>TVG-ID</th>
<th>EPG</th>
</tr>
</thead>
<tbody>
<channel-item v-for="channel in countryChannels" :channel="channel"></channel-item>
</tbody>
</table>
</div>
</div>
</div>
`
}
const App = {
components: {
CountryItem
},
data() {
return {
isLoading: true,
query: '',
normQuery: '',
items: []
}
},
methods: {
search() {
this.normQuery = this.query.replace(/\s/g, '').toLowerCase()
}
},
async mounted() {
const guides = await fetch('https://iptv-org.github.io/epg/api/channels.json')
.then(response => response.json())
.catch(console.log)
const channels = await fetch('https://iptv-org.github.io/api/channels.json')
.then(response => response.json())
.then(arr =>
arr.map(c => {
const found = guides.find(g => g.id === c.id)
c.key = `${c.id}_${c.name}`.replace(/\s/g, '').toLowerCase()
c.guides = found ? found.guides : []
return c
})
)
.then(arr => groupBy(arr, 'country'))
.catch(console.log)
const countries = await fetch('https://iptv-org.github.io/api/countries.json')
.then(response => response.json())
.catch(console.log)
this.items = countries.map(i => {
i.expanded = false
i.channels = channels[i.code] || []
return i
})
this.isLoading = false
}
}
Vue.createApp(App).mount('#app')

View file

@ -5,154 +5,65 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>iptv-org/epg</title> <title>iptv-org/epg</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css" />
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> <script src="https://unpkg.com/vue@next"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash.groupby@4.6.0/index.js"></script>
</head> </head>
<body style="background-color: #f6f8fa; min-height: 100vh"> <body style="background-color: #f6f8fa; min-height: 100vh">
<div class="navbar" style="background-color: transparent"> <div id="app">
<div class="navbar-end"> <div class="navbar" style="background-color: transparent">
<div class="navbar-item"> <div class="navbar-end">
<a href="https://github.com/iptv-org/epg"> <div class="navbar-item">
<span class="icon"> <a href="https://github.com/iptv-org/epg">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> <span class="icon">
<path <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
d="M256 32C132.3 32 32 134.9 32 261.7c0 101.5 64.2 187.5 153.2 217.9a17.56 17.56 0 003.8.4c8.3 0 11.5-6.1 11.5-11.4 0-5.5-.2-19.9-.3-39.1a102.4 102.4 0 01-22.6 2.7c-43.1 0-52.9-33.5-52.9-33.5-10.2-26.5-24.9-33.6-24.9-33.6-19.5-13.7-.1-14.1 1.4-14.1h.1c22.5 2 34.3 23.8 34.3 23.8 11.2 19.6 26.2 25.1 39.6 25.1a63 63 0 0025.6-6c2-14.8 7.8-24.9 14.2-30.7-49.7-5.8-102-25.5-102-113.5 0-25.1 8.7-45.6 23-61.6-2.3-5.8-10-29.2 2.2-60.8a18.64 18.64 0 015-.5c8.1 0 26.4 3.1 56.6 24.1a208.21 208.21 0 01112.2 0c30.2-21 48.5-24.1 56.6-24.1a18.64 18.64 0 015 .5c12.2 31.6 4.5 55 2.2 60.8 14.3 16.1 23 36.6 23 61.6 0 88.2-52.4 107.6-102.3 113.3 8 7.1 15.2 21.1 15.2 42.5 0 30.7-.3 55.5-.3 63 0 5.4 3.1 11.5 11.4 11.5a19.35 19.35 0 004-.4C415.9 449.2 480 363.1 480 261.7 480 134.9 379.7 32 256 32z" <path
/> d="M256 32C132.3 32 32 134.9 32 261.7c0 101.5 64.2 187.5 153.2 217.9a17.56 17.56 0 003.8.4c8.3 0 11.5-6.1 11.5-11.4 0-5.5-.2-19.9-.3-39.1a102.4 102.4 0 01-22.6 2.7c-43.1 0-52.9-33.5-52.9-33.5-10.2-26.5-24.9-33.6-24.9-33.6-19.5-13.7-.1-14.1 1.4-14.1h.1c22.5 2 34.3 23.8 34.3 23.8 11.2 19.6 26.2 25.1 39.6 25.1a63 63 0 0025.6-6c2-14.8 7.8-24.9 14.2-30.7-49.7-5.8-102-25.5-102-113.5 0-25.1 8.7-45.6 23-61.6-2.3-5.8-10-29.2 2.2-60.8a18.64 18.64 0 015-.5c8.1 0 26.4 3.1 56.6 24.1a208.21 208.21 0 01112.2 0c30.2-21 48.5-24.1 56.6-24.1a18.64 18.64 0 015 .5c12.2 31.6 4.5 55 2.2 60.8 14.3 16.1 23 36.6 23 61.6 0 88.2-52.4 107.6-102.3 113.3 8 7.1 15.2 21.1 15.2 42.5 0 30.7-.3 55.5-.3 63 0 5.4 3.1 11.5 11.4 11.5a19.35 19.35 0 004-.4C415.9 449.2 480 363.1 480 261.7 480 134.9 379.7 32 256 32z"
</svg> />
</span> </svg>
</a> </span>
</a>
</div>
</div> </div>
</div> </div>
</div> <div class="section">
<div class="section"> <div class="container">
<div class="container" x-data="list"> <div class="columns is-centered">
<div class="columns is-centered"> <div class="column is-9">
<div class="column is-9"> <form class="mb-5" @submit.prevent="search()">
<form class="mb-5" @submit.prevent="search()"> <div class="field has-addons">
<div class="field has-addons"> <div class="control is-expanded">
<div class="control is-expanded"> <input
<input class="input"
class="input" type="search"
type="search" v-model="query"
x-model="query" placeholder="Search by channel name..."
placeholder="Search by channel name..." />
/> </div>
</div> <div class="control">
<div class="control"> <button class="button is-info" type="submit">
<button class="button is-info" type="submit"> <span class="icon is-small is-right">
<span class="icon is-small is-right"> <svg
<svg xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem; height: 1.25rem"
style="width: 1.25rem; height: 1.25rem" viewBox="0 0 512 512"
viewBox="0 0 512 512" >
> <path
<path fill="#ffffff"
fill="#ffffff" d="M456.69 421.39L362.6 327.3a173.81 173.81 0 0034.84-104.58C397.44 126.38 319.06 48 222.72 48S48 126.38 48 222.72s78.38 174.72 174.72 174.72A173.81 173.81 0 00327.3 362.6l94.09 94.09a25 25 0 0035.3-35.3zM97.92 222.72a124.8 124.8 0 11124.8 124.8 124.95 124.95 0 01-124.8-124.8z"
d="M456.69 421.39L362.6 327.3a173.81 173.81 0 0034.84-104.58C397.44 126.38 319.06 48 222.72 48S48 126.38 48 222.72s78.38 174.72 174.72 174.72A173.81 173.81 0 00327.3 362.6l94.09 94.09a25 25 0 0035.3-35.3zM97.92 222.72a124.8 124.8 0 11124.8 124.8 124.95 124.95 0 01-124.8-124.8z" />
/> </svg>
</svg> </span>
</span> </button>
</button>
</div>
</div>
</form>
<div x-show="isLoading" class="level">
<div class="level-item">Loading...</div>
</div>
<template x-for="item in items">
<div
class="card mb-3 is-shadowless"
style="border: 1px solid #dbdbdb"
x-data="{
count: 0,
get countryChannels() {
if (!_query) return item.channels
const normQuery = _query.toLowerCase()
return item.channels.filter(c => {
return c.hash.includes(normQuery)
}) || []
}
}"
x-show="countryChannels.length > 0"
x-init="$watch('countryChannels', value => {
count = value.length
})"
>
<div
class="card-header is-shadowless is-clickable"
@click="item.expanded = !item.expanded"
>
<span class="card-header-title" x-text="`${item.flag} ${item.name}`"></span>
<button class="card-header-icon" aria-label="more options">
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">
<path
x-show="!item.expanded"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="48"
d="M112 184l144 144 144-144"
/>
<path
x-show="item.expanded"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="48"
d="M112 328l144-144 144 144"
/>
</svg>
</span>
</button>
</div>
<div class="card-content" x-show="item.expanded || (count > 0 && _query.length)">
<div class="table-container">
<table class="table" style="min-width: 100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>TVG-ID</th>
<th>EPG</th>
</tr>
</thead>
<tbody>
<template x-for="channel in countryChannels">
<tr>
<td class="is-vcentered" style="min-width: 150px; text-align: center">
<img
loading="lazy"
x-show="channel.logo"
:src="channel.logo"
style="max-width: 100px; max-height: 50px; vertical-align: middle"
/>
</td>
<td class="is-vcentered" nowrap>
<template x-for="name in channel.name">
<p x-text="name"></p>
</template>
</td>
<td class="is-vcentered" nowrap>
<code x-text="channel.id"></code>
</td>
<td class="is-vcentered">
<template x-for="guide in channel.guides">
<p><code style="white-space: nowrap" x-text="guide"></code></p>
</template>
</td>
</tr>
</template>
</tbody>
</table>
</div> </div>
</div> </div>
</form>
<div v-show="isLoading" class="level">
<div class="level-item">Loading...</div>
</div> </div>
</template>
<country-item v-for="item in items" :item="item" :query="normQuery"></country-item>
</div>
</div> </div>
</div> </div>
</div> </div>