Pārlūkot izejas kodu

fix ordering of subprojects in project list

Thomas B 2 nedēļas atpakaļ
vecāks
revīzija
768b3a956a

+ 2
- 1
input/projects/3d-printing.md Parādīt failu

@@ -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
-printMenuPositional()
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).

+ 2
- 1
input/projects/input_devices.md Parādīt failu

@@ -3,13 +3,14 @@ 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
-printMenuDate()
13
+printMenu()
13 14
 %-->
14 15
 
15 16
 The following pages are also related to this topic.

+ 2
- 1
input/projects/quadcopters.md Parādīt failu

@@ -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,7 +13,7 @@ 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
-printMenuPositional()
16
+printMenu()
16 17
 %-->
17 18
 
18 19
 The following projects and blog posts are also related to my Quadcopter endeavours.

+ 2
- 1
input/projects/smarthome.md Parādīt failu

@@ -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
-printMenuPositional()
16
+printMenu()
16 17
 %-->

+ 1
- 0
input/projects/xyrobot.md Parādīt failu

@@ -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].

+ 20
- 4
macros.py Parādīt failu

@@ -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,7 +303,7 @@ def printProjectsMenu():
294 303
 
295 304
     print("</ul>")
296 305
 
297
-def printMenu(mpages = None, sortKey = None, sortReverse = True):
306
+def printMenuGeneric(mpages = None, sortKey = None, sortReverse = True):
298 307
     if mpages == None:
299 308
         mpages = [p for p in pages if p.get("parent", "__none__") == page["child-id"] and p.lang == "en"]
300 309
     if sortKey != None:
@@ -308,10 +317,17 @@ def printMenu(mpages = None, sortKey = None, sortReverse = True):
308 317
 
309 318
 def printMenuDate(mpages = None, sortReverse = True):
310 319
     sortKey = lambda p: p["date"]
311
-    printMenu(mpages, sortKey, sortReverse)
320
+    printMenuGeneric(mpages, sortKey, sortReverse)
312 321
 
313 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 332
 def printRobotMenuEnglish():
317 333
     mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]

Notiek ielāde…
Atcelt
Saglabāt