Sfoglia il codice sorgente

automatically decide whether to link to main.py or to the directory

Falko Schindler 2 anni fa
parent
commit
8ae978cbcc
2 ha cambiato i file con 7 aggiunte e 2 eliminazioni
  1. 1 1
      main.py
  2. 6 1
      website/style.py

+ 1 - 1
main.py

@@ -217,7 +217,7 @@ ui.run()
             example_link('OpenCV Webcam', 'uses OpenCV to capture images from a webcam')
             example_link('OpenCV Webcam', 'uses OpenCV to capture images from a webcam')
             example_link('SVG Clock', 'displays an analog clock by updating an SVG with `ui.timer`')
             example_link('SVG Clock', 'displays an analog clock by updating an SVG with `ui.timer`')
             example_link('Progress', 'demonstrates a progress bar for heavy computations')
             example_link('Progress', 'demonstrates a progress bar for heavy computations')
-            example_link('NGINX Subpath', 'shows the setup to serve an app behind a reverse proxy subpath', filename='')
+            example_link('NGINX Subpath', 'shows the setup to serve an app behind a reverse proxy subpath')
             example_link('Local File Picker', 'demonstrates a dialog for selecting files locally on the server')
             example_link('Local File Picker', 'demonstrates a dialog for selecting files locally on the server')
 
 
     with ui.row().classes('bg-primary w-full min-h-screen mt-16'):
     with ui.row().classes('bg-primary w-full min-h-screen mt-16'):

+ 6 - 1
website/style.py

@@ -1,3 +1,4 @@
+from pathlib import Path
 from typing import List
 from typing import List
 
 
 from nicegui import ui
 from nicegui import ui
@@ -26,8 +27,12 @@ def subtitle(content: str) -> ui.markdown:
     return ui.markdown(content).classes('text-xl sm:text-2xl md:text-3xl leading-7')
     return ui.markdown(content).classes('text-xl sm:text-2xl md:text-3xl leading-7')
 
 
 
 
-def example_link(title: str, description: str, *, filename: str = 'main.py') -> None:
+def example_link(title: str, description: str) -> None:
     name = title.lower().replace(' ', '_')
     name = title.lower().replace(' ', '_')
+    directory = Path(__file__).parent.parent / 'examples' / name
+    content = [p for p in directory.glob('*') if p.name != '__pycache__' and not p.name.startswith('.')]
+    print(name, content, flush=True)
+    filename = 'main.py' if len(content) == 1 else ''
     with ui.link(target=f'https://github.com/zauberzeug/nicegui/tree/main/examples/{name}/{filename}') \
     with ui.link(target=f'https://github.com/zauberzeug/nicegui/tree/main/examples/{name}/{filename}') \
             .classes('bg-[#5898d420] p-4 self-stretch rounded flex flex-col gap-2') \
             .classes('bg-[#5898d420] p-4 self-stretch rounded flex flex-col gap-2') \
             .style('box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1)'):
             .style('box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1)'):