2 Commits

Auteur SHA1 Bericht Datum
  Thomas B 768b3a956a fix ordering of subprojects in project list 1 maand geleden
  Thomas B 5346ee55e3 generic menu printing functions 1 maand geleden

+ 2
- 1
input/projects/3d-printing.md Bestand weergeven

@@ -3,6 +3,7 @@ description: Reports of my different endeavours in 3D printing
3 3
 parent: projects
4 4
 position: 10
5 5
 child-id: 3d-printing
6
+sort-order: position
6 7
 ---
7 8
 
8 9
 In 2016 I've started experimenting with 3D printers.
@@ -10,7 +11,7 @@ In the meantime, I've modified my printers quite a bit and also written about it
10 11
 Here are all the articles that are part of my 3D printing series:
11 12
 
12 13
 <!--%
13
-print3DPrintingMenu()
14
+printMenu()
14 15
 %-->
15 16
 
16 17
 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).

+ 4
- 2
input/projects/input_devices.md Bestand weergeven

@@ -3,17 +3,19 @@ description: Mechanical Keyboards and other Human-Machine-Interfaces
3 3
 parent: projects
4 4
 position: 15
5 5
 child-id: input_devices
6
+sort-order: date
6 7
 ---
7 8
 
8 9
 One of the recurring topics in my projects are different kind of input devices.
9 10
 Here you can find all pages in this category.
10 11
 
11 12
 <!--%
12
-printInputDevicesMenu()
13
+printMenu()
13 14
 %-->
14 15
 
15 16
 The following pages are also related to this topic.
16 17
 
17 18
 <!--%
18
-printInputDevicesRelatedMenu()
19
+mpages = [p for p in pages if p.get("show_in_input_devices", "false") == "true"]
20
+printMenuDate(mpages)
19 21
 %-->

+ 4
- 2
input/projects/quadcopters.md Bestand weergeven

@@ -3,6 +3,7 @@ description: My self-made Quadcopters and other model stuff
3 3
 parent: projects
4 4
 position: 20
5 5
 child-id: quadcopters
6
+sort-order: position
6 7
 ---
7 8
 
8 9
 In the last couple of years I built multiple quadcopters and some other related flying remote-controlled model vehicles.
@@ -12,13 +13,14 @@ All of these I'm flying with [FatShark Dominator v3 Camo Blue](https://hobbyking
12 13
 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 14
 
14 15
 <!--%
15
-printQuadcopterMenu()
16
+printMenu()
16 17
 %-->
17 18
 
18 19
 The following projects and blog posts are also related to my Quadcopter endeavours.
19 20
 
20 21
 <!--%
21
-printQuadcopterRelatedMenu()
22
+mpages = [p for p in pages if p.get("show_in_quadcopters", "false") == "true"]
23
+printMenuDate(mpages)
22 24
 %-->
23 25
 
24 26
 You can find all my Betaflight configuration dumps and related files [here](https://git.xythobuz.de/thomas/copter-configs).

+ 2
- 1
input/projects/smarthome.md Bestand weergeven

@@ -3,6 +3,7 @@ description: Home automation without shady cloud companies
3 3
 parent: projects
4 4
 position: 50
5 5
 child-id: smarthome
6
+sort-order: position
6 7
 ---
7 8
 
8 9
 With the appearance of cheap WiFi-capable microcontrollers in recent years, like the ESP8266 and the ESP32, the Internet of Things and Smart Home automation have been on my mind.
@@ -12,5 +13,5 @@ And the data should also be hosted on machines I control.
12 13
 The pages in this category document different parts of my setup at home.
13 14
 
14 15
 <!--%
15
-printSmarthomeMenu()
16
+printMenu()
16 17
 %-->

+ 1
- 0
input/projects/xyrobot.md Bestand weergeven

@@ -10,6 +10,7 @@ compat: rob
10 10
 date: 2011-07-28
11 11
 update: 2012-08-30
12 12
 child-id: xyrobot
13
+sort-order: position
13 14
 ---
14 15
 
15 16
 This is my robot project. A self-made PCB with an AtMega2560 controls everything. The robot has a [Bluetooth module][1], a [Gameboy Camera][2] and my [RAM module][3]. I bought the [RN-KeyLCD][4] and the [RN-VN2][5] from [Roboternetz][6].

+ 35
- 54
macros.py Bestand weergeven

@@ -265,6 +265,11 @@ def printProjectsMenu():
265 265
 
266 266
         # print subpages for these top-level items
267 267
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
268
+        order = p.get("sort-order", "date")
269
+        if order == "position":
270
+            subpages.sort(key=lambda p: p["position"])
271
+        else:
272
+            subpages.sort(key=lambda p: p["date"], reverse = True)
268 273
         if len(subpages) > 0:
269 274
             print("<ul>")
270 275
             for sp in subpages:
@@ -285,7 +290,11 @@ def printProjectsMenu():
285 290
 
286 291
         # print subpages for these top-level items
287 292
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
288
-        subpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
293
+        order = p.get("sort-order", "date")
294
+        if order == "position":
295
+            subpages.sort(key=lambda p: p["position"])
296
+        else:
297
+            subpages.sort(key=lambda p: p["date"], reverse = True)
289 298
         if len(subpages) > 0:
290 299
             print("<ul>")
291 300
             for sp in subpages:
@@ -294,59 +303,31 @@ def printProjectsMenu():
294 303
 
295 304
     print("</ul>")
296 305
 
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>")
306
+def printMenuGeneric(mpages = None, sortKey = None, sortReverse = True):
307
+    if mpages == None:
308
+        mpages = [p for p in pages if p.get("parent", "__none__") == page["child-id"] and p.lang == "en"]
309
+    if sortKey != None:
310
+        mpages.sort(key = sortKey, reverse = sortReverse)
311
+
312
+    if len(mpages) > 0:
313
+        print("<ul id='menulist'>")
314
+        for p in mpages:
315
+            printMenuItem(p, False, True, True)
316
+        print("</ul>")
317
+
318
+def printMenuDate(mpages = None, sortReverse = True):
319
+    sortKey = lambda p: p["date"]
320
+    printMenuGeneric(mpages, sortKey, sortReverse)
321
+
322
+def printMenuPositional(mpages = None):
323
+    printMenuGeneric(mpages, lambda p: int(p["position"]), False)
324
+
325
+def printMenu(mpages = None):
326
+    order = page.get("sort-order", "date")
327
+    if order == "position":
328
+        printMenuPositional(mpages)
329
+    else:
330
+        printMenuDate(mpages)
350 331
 
351 332
 def printRobotMenuEnglish():
352 333
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]

Laden…
Annuleren
Opslaan