mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Add search to the docs
This commit is contained in:
parent
2ecd181c25
commit
ba83edd8f5
|
@ -339,17 +339,34 @@ def generate_documentation(scheme_file):
|
|||
|
||||
types.add(tlobject.result)
|
||||
|
||||
types = sorted(types)
|
||||
methods = sorted(methods, key=lambda m: m.name)
|
||||
|
||||
request_names = ', '.join('"' + get_class_name(m) + '"' for m in methods)
|
||||
type_names = ', '.join('"' + get_class_name(t) + '"' for t in types)
|
||||
|
||||
request_urls = ', '.join('"' + get_create_path_for(m) + '"' for m in methods)
|
||||
type_urls = ', '.join('"' + get_path_for_type(t) + '"' for t in types)
|
||||
|
||||
replace_dict = {
|
||||
'type_count': len(types),
|
||||
'method_count': len(methods),
|
||||
'constructor_count': len(methods) - len(tlobjects),
|
||||
'layer': layer
|
||||
'layer': layer,
|
||||
|
||||
'request_names': request_names,
|
||||
'type_names': type_names,
|
||||
'request_urls': request_urls,
|
||||
'type_urls': type_urls
|
||||
}
|
||||
|
||||
with open('../res/core.html') as infile:
|
||||
with open(original_paths['index_all'], 'w') as outfile:
|
||||
outfile.write(infile.read()
|
||||
.format_map(replace_dict))
|
||||
text = infile.read()
|
||||
for key, value in replace_dict.items():
|
||||
text = text.replace('{' + key + '}', str(value))
|
||||
|
||||
outfile.write(text)
|
||||
|
||||
# Everything done
|
||||
print('Documentation generated.')
|
||||
|
|
|
@ -6,9 +6,22 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="css/docs.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Nunito|Source+Code+Pro" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
overflow: scroll;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main_div">
|
||||
<input id="searchBox" type="text" onkeyup="updateSearch()"
|
||||
placeholder="Search for requests and types…" autofocus />
|
||||
|
||||
<div id="searchDiv">
|
||||
<table id="searchTable"></table>
|
||||
</div>
|
||||
|
||||
<div id="contentDiv">
|
||||
<h1>Telethon API</h1>
|
||||
<p>This documentation was generated straight from the <code>scheme.tl</code>
|
||||
provided by Telegram. However, there is no official documentation per se
|
||||
|
@ -140,5 +153,71 @@ messages = result.messages</pre>
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
contentDiv = document.getElementById("contentDiv");
|
||||
searchDiv = document.getElementById("searchDiv");
|
||||
searchBox = document.getElementById("searchBox");
|
||||
searchTable = document.getElementById("searchTable");
|
||||
|
||||
requests = [{request_names}];
|
||||
types = [{type_names}];
|
||||
|
||||
requestsu = [{request_urls}];
|
||||
typesu = [{type_urls}];
|
||||
|
||||
function updateSearch() {
|
||||
if (searchBox.value) {
|
||||
contentDiv.style.display = "none";
|
||||
searchDiv.style.display = "";
|
||||
|
||||
var foundRequests = [];
|
||||
var foundRequestsu = [];
|
||||
for (var i = 0; i < requests.length; ++i) {
|
||||
if (requests[i].toLowerCase().indexOf(searchBox.value) != -1) {
|
||||
foundRequests.push(requests[i]);
|
||||
foundRequestsu.push(requestsu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var foundTypes = [];
|
||||
var foundTypesu = [];
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
if (types[i].toLowerCase().indexOf(searchBox.value) != -1) {
|
||||
foundTypes.push(types[i]);
|
||||
foundTypesu.push(typesu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var top = foundRequests.length > foundTypes.length ?
|
||||
foundRequests.length : foundTypes.length;
|
||||
|
||||
result = "";
|
||||
for (var i = 0; i <= top; ++i) {
|
||||
result += "<tr><td>";
|
||||
|
||||
if (i < foundRequests.length) {
|
||||
result +=
|
||||
'<a href="'+foundRequestsu[i]+'">'+foundRequests[i]+'</a>';
|
||||
}
|
||||
|
||||
result += "</td><td>";
|
||||
|
||||
if (i < foundTypes.length) {
|
||||
result +=
|
||||
'<a href="'+foundTypesu[i]+'">'+foundTypes[i]+'</a>';
|
||||
}
|
||||
|
||||
result += "</td></tr>";
|
||||
}
|
||||
searchTable.innerHTML = result;
|
||||
} else {
|
||||
contentDiv.style.display = "";
|
||||
searchDiv.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
updateSearch();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -108,6 +108,20 @@ span.sh4 {
|
|||
color: #06c;
|
||||
}
|
||||
|
||||
#searchBox {
|
||||
width: 100%;
|
||||
border: none;
|
||||
height: 20px;
|
||||
padding: 8px;
|
||||
font-size: 16px;
|
||||
border-radius: 2px;
|
||||
border: 2px solid #ddd;
|
||||
}
|
||||
|
||||
#searchBox:placeholder-shown {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
h1 {
|
||||
font-size: 18px;
|
||||
|
|
Loading…
Reference in New Issue
Block a user