search guides content

This commit is contained in:
aliabd 2022-01-27 23:40:21 +04:00
parent 3ea78b46c5
commit 4360cb341a
2 changed files with 22 additions and 13 deletions

View File

@ -17,7 +17,8 @@ GRADIO_GUIDES_DIR = os.path.join(GRADIO_DIR, "guides")
GRADIO_DEMO_DIR = os.path.join(GRADIO_DIR, "demo")
guide_names = []
guides = []
counter = 0
for guide in sorted(os.listdir(GRADIO_GUIDES_DIR)):
if "template" in guide or "getting_started" in guide:
continue
@ -25,7 +26,14 @@ for guide in sorted(os.listdir(GRADIO_GUIDES_DIR)):
pretty_guide_name = " ".join(
[word.capitalize().replace("Ml", "ML") for word in guide_name.split("_")]
)
guide_names.append((guide_name, pretty_guide_name))
with open(os.path.join(GRADIO_GUIDES_DIR, guide),"r") as f:
guide_content = f.read()
guide_dict = {
"guide_name": guide_name,
"pretty_guide_name": pretty_guide_name,
"guide_content": guide_content,
}
guides.append(guide_dict)
def render_index():
@ -47,7 +55,7 @@ def render_index():
def render_guides_main():
with open("src/guides_main_template.html", encoding='utf-8') as template_file:
template = Template(template_file.read())
output_html = template.render(guide_names=guide_names)
output_html = template.render(guides=guides)
with open(os.path.join("generated", "guides.html"), "w", encoding='utf-8') as generated_template:
generated_template.write(output_html)
@ -255,5 +263,5 @@ if __name__ == "__main__":
render_index()
render_guides_main()
render_guides()
render_docs()
# render_docs()
render_other()

View File

@ -167,11 +167,11 @@
</div>
<div id="guide-list" class="grid grid-cols-1 lg:grid-cols-3 gap-12 pt-12">
{% for guide_name, pretty_guide_name in guide_names %}
<a class="flex lg:col-span-1 flex-col group overflow-hidden relative border-gray-100 rounded-xl border shadow-sm hover:shadow-alternate transition-shadow" href="/{{ guide_name }}">
{% for guide in guides %}
<a class="flex lg:col-span-1 flex-col group overflow-hidden relative border-gray-100 rounded-xl border shadow-sm hover:shadow-alternate transition-shadow" href="/{{ guide.guide_name }}">
<div class="flex flex-col p-4" style="
height: min-content;">
<h2 class="font-semibold group-hover:underline font-serif text-xl">{{ pretty_guide_name }}
<h2 class="font-semibold group-hover:underline font-serif text-xl">{{ guide.pretty_guide_name }}
</h2>
<p class="font-mono text-xs text-gray-500 flex items-center mt-3">By&nbsp;<object title="">Author Name</object>
@ -229,15 +229,16 @@
var filter, i, txtValue;
filter = term.toUpperCase();
var counter = 0
for (i = 0; i < a.length; i++) {
txtValue = a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
{% for guide in guides %}
txtValue = a[{{ loop.index - 1 }}].innerText;
guideContent = {{ guide.guide_content|tojson|safe }}
if (txtValue.toUpperCase().indexOf(filter) > -1 || guideContent.toUpperCase().indexOf(filter) > -1) {
a[{{ loop.index - 1}}].style.display = "";
} else {
a[i].style.display = "none";
a[{{ loop.index - 1 }}].style.display = "none";
counter++;
}
}
{% endfor %}
ngf = document.getElementById("no-guides-found");
if (counter == a.length) {
ngf.style.display = "";