Explorar el Código

generic menu printing functions

Thomas B hace 1 mes
padre
commit
5346ee55e3

+ 1
- 1
input/projects/3d-printing.md Ver fichero

@@ -10,7 +10,7 @@ In the meantime, I've modified my printers quite a bit and also written about it
10 10
 Here are all the articles that are part of my 3D printing series:
11 11
 
12 12
 <!--%
13
-print3DPrintingMenu()
13
+printMenuPositional()
14 14
 %-->
15 15
 
16 16
 If you're interested in my 3D print designs, take a look [at my Thingiverse account](https://www.thingiverse.com/xythobuz/designs) or my [Git Repository](https://git.xythobuz.de/thomas/3d-print-designs).

+ 3
- 2
input/projects/input_devices.md Ver fichero

@@ -9,11 +9,12 @@ One of the recurring topics in my projects are different kind of input devices.
9 9
 Here you can find all pages in this category.
10 10
 
11 11
 <!--%
12
-printInputDevicesMenu()
12
+printMenuDate()
13 13
 %-->
14 14
 
15 15
 The following pages are also related to this topic.
16 16
 
17 17
 <!--%
18
-printInputDevicesRelatedMenu()
18
+mpages = [p for p in pages if p.get("show_in_input_devices", "false") == "true"]
19
+printMenuDate(mpages)
19 20
 %-->

+ 3
- 2
input/projects/quadcopters.md Ver fichero

@@ -12,13 +12,14 @@ All of these I'm flying with [FatShark Dominator v3 Camo Blue](https://hobbyking
12 12
 Of course I'm not flying illegally, I have a model flight insurance and I am a registered UAV pilot in the European Union! 👮
13 13
 
14 14
 <!--%
15
-printQuadcopterMenu()
15
+printMenuPositional()
16 16
 %-->
17 17
 
18 18
 The following projects and blog posts are also related to my Quadcopter endeavours.
19 19
 
20 20
 <!--%
21
-printQuadcopterRelatedMenu()
21
+mpages = [p for p in pages if p.get("show_in_quadcopters", "false") == "true"]
22
+printMenuDate(mpages)
22 23
 %-->
23 24
 
24 25
 You can find all my Betaflight configuration dumps and related files [here](https://git.xythobuz.de/thomas/copter-configs).

+ 1
- 1
input/projects/smarthome.md Ver fichero

@@ -12,5 +12,5 @@ And the data should also be hosted on machines I control.
12 12
 The pages in this category document different parts of my setup at home.
13 13
 
14 14
 <!--%
15
-printSmarthomeMenu()
15
+printMenuPositional()
16 16
 %-->

+ 18
- 53
macros.py Ver fichero

@@ -294,59 +294,24 @@ def printProjectsMenu():
294 294
 
295 295
     print("</ul>")
296 296
 
297
-def print3DPrintingMenu():
298
-    mpages = [p for p in pages if p.get("parent", "") == "3d-printing" and p.lang == "en"]
299
-    mpages.sort(key=lambda p: int(p["position"]))
300
-
301
-    print("<ul id='menulist'>")
302
-    for p in mpages:
303
-        printMenuItem(p, False, True, True)
304
-    print("</ul>")
305
-
306
-def printInputDevicesMenu():
307
-    mpages = [p for p in pages if p.get("parent", "") == "input_devices" and p.lang == "en"]
308
-    mpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
309
-
310
-    print("<ul id='menulist'>")
311
-    for p in mpages:
312
-        printMenuItem(p, False, True, True)
313
-    print("</ul>")
314
-
315
-def printInputDevicesRelatedMenu():
316
-    mpages = [p for p in pages if p.get("show_in_input_devices", "false") == "true"]
317
-    mpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
318
-
319
-    print("<ul id='menulist'>")
320
-    for p in mpages:
321
-        printMenuItem(p, False, True, True)
322
-    print("</ul>")
323
-
324
-def printSmarthomeMenu():
325
-    mpages = [p for p in pages if p.get("parent", "") == "smarthome" and p.lang == "en"]
326
-    mpages.sort(key=lambda p: int(p["position"]))
327
-
328
-    print("<ul id='menulist'>")
329
-    for p in mpages:
330
-        printMenuItem(p, False, True, True)
331
-    print("</ul>")
332
-
333
-def printQuadcopterMenu():
334
-    mpages = [p for p in pages if p.get("parent", "") == "quadcopters" and p.lang == "en"]
335
-    mpages.sort(key=lambda p: int(p["position"]))
336
-
337
-    print("<ul id='menulist'>")
338
-    for p in mpages:
339
-        printMenuItem(p, False, True, True)
340
-    print("</ul>")
341
-
342
-def printQuadcopterRelatedMenu():
343
-    mpages = [p for p in pages if p.get("show_in_quadcopters", "false") == "true"]
344
-    mpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
345
-
346
-    print("<ul id='menulist'>")
347
-    for p in mpages:
348
-        printMenuItem(p, False, True, True)
349
-    print("</ul>")
297
+def printMenu(mpages = None, sortKey = None, sortReverse = True):
298
+    if mpages == None:
299
+        mpages = [p for p in pages if p.get("parent", "__none__") == page["child-id"] and p.lang == "en"]
300
+    if sortKey != None:
301
+        mpages.sort(key = sortKey, reverse = sortReverse)
302
+
303
+    if len(mpages) > 0:
304
+        print("<ul id='menulist'>")
305
+        for p in mpages:
306
+            printMenuItem(p, False, True, True)
307
+        print("</ul>")
308
+
309
+def printMenuDate(mpages = None, sortReverse = True):
310
+    sortKey = lambda p: p["date"]
311
+    printMenu(mpages, sortKey, sortReverse)
312
+
313
+def printMenuPositional(mpages = None):
314
+    printMenu(mpages, lambda p: int(p["position"]), False)
350 315
 
351 316
 def printRobotMenuEnglish():
352 317
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]

Loading…
Cancelar
Guardar