瀏覽代碼

generic menu printing functions

Thomas B 7 月之前
父節點
當前提交
5346ee55e3
共有 5 個檔案被更改,包括 26 行新增59 行删除
  1. 1
    1
      input/projects/3d-printing.md
  2. 3
    2
      input/projects/input_devices.md
  3. 3
    2
      input/projects/quadcopters.md
  4. 1
    1
      input/projects/smarthome.md
  5. 18
    53
      macros.py

+ 1
- 1
input/projects/3d-printing.md 查看文件

10
 Here are all the articles that are part of my 3D printing series:
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
 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).
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 查看文件

9
 Here you can find all pages in this category.
9
 Here you can find all pages in this category.
10
 
10
 
11
 <!--%
11
 <!--%
12
-printInputDevicesMenu()
12
+printMenuDate()
13
 %-->
13
 %-->
14
 
14
 
15
 The following pages are also related to this topic.
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 查看文件

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! 👮
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
 The following projects and blog posts are also related to my Quadcopter endeavours.
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
 You can find all my Betaflight configuration dumps and related files [here](https://git.xythobuz.de/thomas/copter-configs).
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 查看文件

12
 The pages in this category document different parts of my setup at home.
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 查看文件

294
 
294
 
295
     print("</ul>")
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
 def printRobotMenuEnglish():
316
 def printRobotMenuEnglish():
352
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]
317
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]

Loading…
取消
儲存