-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
207 lines (183 loc) · 7.96 KB
/
index.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html lang="ml">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>സർവ്വവിജ്ഞാനകോശം Sarvavijnanakosam</title>
<meta name="description" content="കേരള ഗവണ്മെൻ്റ് സാംസ്കാരികവകുപ്പിൻ്റെ സ്റ്റേറ്റ് ഇൻസ്റ്റിറ്റ്യൂട്ട് ഓഫ്
എൻസൈക്ലോപീഡിക് പബ്ലിക്കേഷൻസ് പ്രസിദ്ധീകരിക്കുന്ന മലയാളത്തിലെ ഒരു വിജ്ഞാനകോശമാണ് സർവ്വവിജ്ഞാനകോശം" />
<meta name="keywords"
content="sarvavijnanakosam, malayalam encyclopaedia, malayalam index, keralam, kerala, malayalam, translation, knowledge, culture, vijnanakosam, മലയാളം, സർവ്വവിജ്ഞാനകോശം, കേരളം" />
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet" />
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<!-- MDB -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.2.0/mdb.min.css" rel="stylesheet" />
<style>
body {
text-align: center;
max-width: 640px;
margin: 30px auto;
}
img {
max-width: 100%;
}
.title {
font-size: 4rem;
}
@media (max-width: 640px) {
.title {
font-size: 2rem;
}
}
#search-only {
display: none;
}
#table {
display: none;
}
#search-form {
margin-bottom: 10px;
}
.entry {
text-align: left;
padding: 10px;
margin: 5px;
font-size: larger;
display: flex;
gap: 5px;
}
.vol {
background-color: gray;
color: white;
padding: 10px 5px;
}
</style>
</head>
<body>
<h1 class="title">
<img src="./sarvavijnanakosham.png" alt="സര്വ്വവിജ്ഞാനകോശം" />
</h1>
<div id="home-only">
<img src="https://sarva.kerala.gov.in/wp-content/uploads/2018/11/home-page-banner-1.jpg">
</div>
<form id="search-form">
<div class="input-group">
<button class="btn btn-dark dropdown-toggle" type="button" data-mdb-dropdown-init data-mdb-ripple-init
aria-expanded="false">
സര്വ്വവിജ്ഞാനകോശം
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">സര്വ്വവിജ്ഞാനകോശം</a></li>
</ul>
<div class="form-outline" data-mdb-input-init>
<input type="search" id="search" class="form-control" />
<label class="form-label" for="search">തിരയുക</label>
</div>
<button type="submit" class="btn btn-dark" data-mdb-ripple-init>
<i class="fas fa-search"></i>
</button>
</div>
</form>
<div id="search-only">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div id="table"></div>
<footer class="text-center text-lg-start bg-body-tertiary text-muted">
<section class="">
<div class="container text-center mt-5 p-5">
<div class="row">
<div class="col"><a href="http://web-edition.sarvavijnanakosam.gov.in">Open Knowledge ♥</a></div>
<div class="col"><a href="https://poorna.smc.org.in">Type Malayalam</a></div>
<div class="col"><a href="https://smc.org.in/fonts/">Download Fonts</a></div>
</div>
<hr class="hr-blurry" />
<div class="row">
<div class="col">Concept by <a href="https://opendatakerala.org">OpenDataKerala</a></div>
<div class="col">Powered by <a href="https://www.mediawiki.org">MediaWiki</a></div>
</div>
</div>
</section>
</footer>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.2.0/mdb.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.min.js"
integrity="sha512-dfX5uYVXzyU8+KHqj8bjo7UkOdg18PaOtpa48djpNbZHwExddghZ+ZmzWT06R5v6NSk3ZUfsH6FNEDepLx9hPQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
const q = document.getElementById('search');
q.value = "";
const download = new Promise((resolve, reject) => {
Papa.parse("./Sarvavijnanakosam.csv", {
download: true,
header: true,
complete: function (results) {
resolve(results.data);
}
})
})
const search = document.getElementById('search-form');
// https://stackoverflow.com/a/494348
function createElementFromHTML(htmlString) {
var div = document.createElement('div');
div.innerHTML = htmlString.trim();
// Change this to div.childNodes to support multiple top-level nodes.
return div.firstChild;
}
const orderByScore = (list, scorer) => {
const scored = list.map(item => ({ item, score: scorer(item) }))
.filter(i => i.score > 0);
scored.sort((a, b) => b.score - a.score)
return scored.map(i => i.item);
}
const searchInData = (data, term) => {
return orderByScore(data, (item) => {
if (item.title === term) return 100;
if (item.transliteration === term) return 100;
if (item.title.startsWith(term)) return 50;
if (item.transliteration.startsWith(term)) return 50;
if (item.title.includes(term)) return 20;
if (item.transliteration.includes(term)) return 20;
return 0;
})
}
const getResultEntry = (row) => createElementFromHTML(`
<div class="entry">
<div class="vol">${row.volume}</div>
<a href="${row.link}">${row.title}</a>
</div>
`);
const getRandomBetween = (a, b) => {
const diff = b - a;
return a + Math.random() * diff;
}
search.addEventListener('submit', (e) => {
e.preventDefault();
const t = document.getElementById("table");
t.style.display = 'none';
t.replaceChildren();
document.getElementById('search-only').style.display = 'block';
download.then((data) => {
const results = searchInData(data, q.value.toLowerCase())
if (results.length > 0) {
results.slice(0, 20).forEach(row => {
t.appendChild(getResultEntry(row));
})
} else {
t.appendChild(createElementFromHTML(`
<div>"${q.value}"ക്കു വേണ്ടിയുള്ള തിരച്ചിലില് ഒന്നും കണ്ടെത്താനായില്ല</div>
`))
}
return data;
})
setTimeout(() => {
document.getElementById('search-only').style.display = 'none';
t.style.display = 'block';
}, getRandomBetween(500, 2500))
})
</script>
</body>
</html>