Browse Source

fix ordering of subprojects in project list

Thomas B 2 weeks ago
parent
commit
768b3a956a

+ 2
- 1
input/projects/3d-printing.md View File

3
 parent: projects
3
 parent: projects
4
 position: 10
4
 position: 10
5
 child-id: 3d-printing
5
 child-id: 3d-printing
6
+sort-order: position
6
 ---
7
 ---
7
 
8
 
8
 In 2016 I've started experimenting with 3D printers.
9
 In 2016 I've started experimenting with 3D printers.
10
 Here are all the articles that are part of my 3D printing series:
11
 Here are all the articles that are part of my 3D printing series:
11
 
12
 
12
 <!--%
13
 <!--%
13
-printMenuPositional()
14
+printMenu()
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).
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).

+ 2
- 1
input/projects/input_devices.md View File

3
 parent: projects
3
 parent: projects
4
 position: 15
4
 position: 15
5
 child-id: input_devices
5
 child-id: input_devices
6
+sort-order: date
6
 ---
7
 ---
7
 
8
 
8
 One of the recurring topics in my projects are different kind of input devices.
9
 One of the recurring topics in my projects are different kind of input devices.
9
 Here you can find all pages in this category.
10
 Here you can find all pages in this category.
10
 
11
 
11
 <!--%
12
 <!--%
12
-printMenuDate()
13
+printMenu()
13
 %-->
14
 %-->
14
 
15
 
15
 The following pages are also related to this topic.
16
 The following pages are also related to this topic.

+ 2
- 1
input/projects/quadcopters.md View File

3
 parent: projects
3
 parent: projects
4
 position: 20
4
 position: 20
5
 child-id: quadcopters
5
 child-id: quadcopters
6
+sort-order: position
6
 ---
7
 ---
7
 
8
 
8
 In the last couple of years I built multiple quadcopters and some other related flying remote-controlled model vehicles.
9
 In the last couple of years I built multiple quadcopters and some other related flying remote-controlled model vehicles.
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
 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
-printMenuPositional()
16
+printMenu()
16
 %-->
17
 %-->
17
 
18
 
18
 The following projects and blog posts are also related to my Quadcopter endeavours.
19
 The following projects and blog posts are also related to my Quadcopter endeavours.

+ 2
- 1
input/projects/smarthome.md View File

3
 parent: projects
3
 parent: projects
4
 position: 50
4
 position: 50
5
 child-id: smarthome
5
 child-id: smarthome
6
+sort-order: position
6
 ---
7
 ---
7
 
8
 
8
 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.
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
 The pages in this category document different parts of my setup at home.
13
 The pages in this category document different parts of my setup at home.
13
 
14
 
14
 <!--%
15
 <!--%
15
-printMenuPositional()
16
+printMenu()
16
 %-->
17
 %-->

+ 1
- 0
input/projects/xyrobot.md View File

10
 date: 2011-07-28
10
 date: 2011-07-28
11
 update: 2012-08-30
11
 update: 2012-08-30
12
 child-id: xyrobot
12
 child-id: xyrobot
13
+sort-order: position
13
 ---
14
 ---
14
 
15
 
15
 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].
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].

+ 20
- 4
macros.py View File

265
 
265
 
266
         # print subpages for these top-level items
266
         # print subpages for these top-level items
267
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
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
         if len(subpages) > 0:
273
         if len(subpages) > 0:
269
             print("<ul>")
274
             print("<ul>")
270
             for sp in subpages:
275
             for sp in subpages:
285
 
290
 
286
         # print subpages for these top-level items
291
         # print subpages for these top-level items
287
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
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
         if len(subpages) > 0:
298
         if len(subpages) > 0:
290
             print("<ul>")
299
             print("<ul>")
291
             for sp in subpages:
300
             for sp in subpages:
294
 
303
 
295
     print("</ul>")
304
     print("</ul>")
296
 
305
 
297
-def printMenu(mpages = None, sortKey = None, sortReverse = True):
306
+def printMenuGeneric(mpages = None, sortKey = None, sortReverse = True):
298
     if mpages == None:
307
     if mpages == None:
299
         mpages = [p for p in pages if p.get("parent", "__none__") == page["child-id"] and p.lang == "en"]
308
         mpages = [p for p in pages if p.get("parent", "__none__") == page["child-id"] and p.lang == "en"]
300
     if sortKey != None:
309
     if sortKey != None:
308
 
317
 
309
 def printMenuDate(mpages = None, sortReverse = True):
318
 def printMenuDate(mpages = None, sortReverse = True):
310
     sortKey = lambda p: p["date"]
319
     sortKey = lambda p: p["date"]
311
-    printMenu(mpages, sortKey, sortReverse)
320
+    printMenuGeneric(mpages, sortKey, sortReverse)
312
 
321
 
313
 def printMenuPositional(mpages = None):
322
 def printMenuPositional(mpages = None):
314
-    printMenu(mpages, lambda p: int(p["position"]), False)
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)
315
 
331
 
316
 def printRobotMenuEnglish():
332
 def printRobotMenuEnglish():
317
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]
333
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]

Loading…
Cancel
Save