Pārlūkot izejas kodu

tweak project menu with sub lists

Thomas B 1 mēnesi atpakaļ
vecāks
revīzija
06b8ebe50d

+ 3
- 2
input/blog.md Parādīt failu

@@ -9,12 +9,13 @@ noheader: true
9 9
 
10 10
 # Blog Archive
11 11
 
12
-To receive my latest updates, you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.
12
+To receive my latest updates you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.
13 13
 
14 14
 <!--%
15 15
 import datetime
16 16
 year = int(datetime.date.today().year)
17
-printBlogMenu(str(year - 5), None)
17
+
18
+printBlogMenu(str(year - get_conf("blog_years_back") + 1), None)
18 19
 %-->
19 20
 
20 21
 [Click here](blog_old.html) for older blog posts.

+ 3
- 2
input/blog_old.md Parādīt failu

@@ -7,10 +7,11 @@ noheader: true
7 7
 
8 8
 [Click here](blog.html) for the more recent blog posts.
9 9
 
10
-To receive my latest updates, you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.
10
+To receive my latest updates you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.
11 11
 
12 12
 <!--%
13 13
 import datetime
14 14
 year = int(datetime.date.today().year)
15
-printBlogMenu(None, str(year - 5 - 1))
15
+
16
+printBlogMenu(None, str(year - get_conf("blog_years_back")))
16 17
 %-->

+ 1
- 21
input/index.md Parādīt failu

@@ -10,27 +10,7 @@ noheader: true
10 10
 
11 11
 <img id="index-avatar" src="img/ava.jpg">
12 12
 
13
-I'm a <!--%
14
-from datetime import datetime
15
-from datetime import timedelta
16
-from calendar import isleap
17
-
18
-size_of_day = 1. / 366.
19
-size_of_second = size_of_day / (24. * 60. * 60.)
20
-
21
-def date_as_float(dt):
22
-    days_from_jan1 = dt - datetime(dt.year, 1, 1)
23
-    if not isleap(dt.year) and days_from_jan1.days >= 31+28:
24
-        days_from_jan1 += timedelta(1)
25
-    return dt.year + days_from_jan1.days * size_of_day + days_from_jan1.seconds * size_of_second
26
-
27
-start_date = datetime(1994,1,22,0,0)
28
-end_date = datetime.now()
29
-difference_in_years = date_as_float(end_date) - date_as_float(start_date)
30
-
31
-print(int(difference_in_years))
32
-
33
-%--> year old software developer from Germany.
13
+I'm a <!--% print(own_age()) %--> year old software developer from Germany.
34 14
 All of my projects are released as free or open-source software on [my Gitea Server](https://git.xythobuz.de/thomas), [my GitHub profile](https://github.com/xythobuz) and here on my website. Have fun!
35 15
 
36 16
 To receive my latest updates, you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.

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

@@ -4,10 +4,10 @@ position: 10
4 4
 ---
5 5
 
6 6
 This page lists all of my projects that are documented on this website.
7
-Some projects have a specific date and time where I worked on them, so they are listed by date below.
8
-Some others are on-going or still recent for other reasons, these are listed first.
7
+Some bigger topics that are on-going are listed first.
8
+Other projects have a specific date and time where I worked on them, so they are listed by date below.
9 9
 
10
-To receive my latest updates, you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.
10
+To receive my latest updates you can subscribe to the <a href="rss.xml"><img src="img/rss.png">RSS Feed</a>.
11 11
 
12 12
 <!--%
13 13
 printProjectsMenu()

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

@@ -2,6 +2,7 @@ title: 3D Printing
2 2
 description: Reports of my different endeavours in 3D printing
3 3
 parent: projects
4 4
 position: 10
5
+child-id: 3d-printing
5 6
 ---
6 7
 
7 8
 In 2016 I've started experimenting with 3D printers.

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

@@ -4,6 +4,7 @@ description: My Grandfathers self-built model steam engine
4 4
 parent: projects
5 5
 position: 500
6 6
 comments: true
7
+child-id: steam
7 8
 ---
8 9
 
9 10
 In 1992 my grandfather began building his own live model steam engine, in 1:2.7 scale.

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

@@ -3,6 +3,7 @@ description: Collection of various cocktail machine related things
3 3
 parent: projects
4 4
 position: 100
5 5
 comments: true
6
+child-id: drinkrobotics
6 7
 ---
7 8
 
8 9
 ## Ubabot

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

@@ -2,6 +2,7 @@ title: Input Devices
2 2
 description: Mechanical Keyboards and other Human-Machine-Interfaces
3 3
 parent: projects
4 4
 position: 15
5
+child-id: input_devices
5 6
 ---
6 7
 
7 8
 One of the recurring topics in my projects are different kind of input devices.

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

@@ -2,6 +2,7 @@ title: Flying RC Vehicles
2 2
 description: My self-made Quadcopters and other model stuff
3 3
 parent: projects
4 4
 position: 20
5
+child-id: quadcopters
5 6
 ---
6 7
 
7 8
 In the last couple of years I built multiple quadcopters and some other related flying remote-controlled model vehicles.

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

@@ -2,6 +2,7 @@ title: Smart Home
2 2
 description: Home automation without shady cloud companies
3 3
 parent: projects
4 4
 position: 50
5
+child-id: smarthome
5 6
 ---
6 7
 
7 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.

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

@@ -9,6 +9,7 @@ github: https://github.com/xythobuz/xyRobot
9 9
 compat: rob
10 10
 date: 2011-07-28
11 11
 update: 2012-08-30
12
+child-id: xyrobot
12 13
 ---
13 14
 
14 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].

+ 88
- 18
macros.py Parādīt failu

@@ -11,12 +11,9 @@ import time
11 11
 import codecs
12 12
 from datetime import datetime
13 13
 
14
-DEFAULT_LANG = "en"
15
-BASE_URL = "https://www.xythobuz.de"
16
-
17
-# =============================================================================
14
+# -----------------------------------------------------------------------------
18 15
 # Python 2/3 hacks
19
-# =============================================================================
16
+# -----------------------------------------------------------------------------
20 17
 
21 18
 PY3 = sys.version_info[0] == 3
22 19
 
@@ -32,6 +29,50 @@ else:
32 29
         return urlparse.parse_qs(urlparse.urlparse(link).query)['v'][0]
33 30
 
34 31
 # -----------------------------------------------------------------------------
32
+# config "system"
33
+# -----------------------------------------------------------------------------
34
+
35
+conf = {
36
+    "default_lang": "en",
37
+    "base_url": "https://www.xythobuz.de",
38
+
39
+    "birthday": datetime(1994, 1, 22, 0, 0),
40
+    "blog_years_back": 6,
41
+}
42
+
43
+def get_conf(name):
44
+    return conf[name]
45
+
46
+# -----------------------------------------------------------------------------
47
+# local vars for compatibility
48
+# -----------------------------------------------------------------------------
49
+
50
+DEFAULT_LANG = get_conf("default_lang")
51
+BASE_URL = get_conf("base_url")
52
+
53
+# -----------------------------------------------------------------------------
54
+# birthday calculation
55
+# -----------------------------------------------------------------------------
56
+
57
+from datetime import timedelta
58
+from calendar import isleap
59
+
60
+size_of_day = 1. / 366.
61
+size_of_second = size_of_day / (24. * 60. * 60.)
62
+
63
+def date_as_float(dt):
64
+    days_from_jan1 = dt - datetime(dt.year, 1, 1)
65
+    if not isleap(dt.year) and days_from_jan1.days >= 31+28:
66
+        days_from_jan1 += timedelta(1)
67
+    return dt.year + days_from_jan1.days * size_of_day + days_from_jan1.seconds * size_of_second
68
+
69
+def difference_in_years(start_date, end_date):
70
+    return int(date_as_float(end_date) - date_as_float(start_date))
71
+
72
+def own_age():
73
+    return difference_in_years(get_conf("birthday"), datetime.now())
74
+
75
+# -----------------------------------------------------------------------------
35 76
 # sub page helper macro
36 77
 # -----------------------------------------------------------------------------
37 78
 
@@ -119,7 +160,7 @@ def githubCommitBadge(p, showInline = False):
119 160
             ret += ".svg?logo=git&style=flat\" /></a>"
120 161
     return ret
121 162
 
122
-def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStartDate = False, nicelyFormatFullDate = False, lastyear = "0", lang = "", showLastCommit = True):
163
+def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStartDate = False, nicelyFormatFullDate = False, lastyear = "0", lang = "", showLastCommit = True, hide_description = False, indent_count = 0, updates_as_heading = False):
123 164
     title = p.title
124 165
     if lang != "":
125 166
         if p.get("title_" + lang, "") != "":
@@ -127,7 +168,10 @@ def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStart
127 168
     if title == "Blog":
128 169
         title = p.post
129 170
 
130
-    year = p.get("date", "")[0:4]
171
+    if updates_as_heading:
172
+        year = p.get("update", p.get("date", ""))[0:4]
173
+    else:
174
+        year = p.get("date", "")[0:4]
131 175
     if year != lastyear:
132 176
         lastyear = year
133 177
         if yearsAsHeading:
@@ -146,14 +190,16 @@ def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStart
146 190
         if nicelyFormatFullDate:
147 191
             dateto = " - " + datetime.strptime(p.get("update", p.date), "%Y-%m-%d").strftime("%B %d, %Y")
148 192
 
149
-    print("  * **[%s](%s)**%s" % (title, p.url, dateto))
193
+    indent = "  " * (indent_count + 1)
194
+    print(indent + "* **[%s](%s)**%s" % (title, p.url, dateto))
150 195
 
151
-    if p.get("description", "") != "":
152
-        description = p.get("description", "")
153
-        if lang != "":
154
-            if p.get("description_" + lang, "") != "":
155
-                description = p.get("description_" + lang, "")
156
-        print("<br><span class=\"listdesc\">" + description + "</span>")
196
+    if hide_description == False:
197
+        if p.get("description", "") != "":
198
+            description = p.get("description", "")
199
+            if lang != "":
200
+                if p.get("description_" + lang, "") != "":
201
+                    description = p.get("description_" + lang, "")
202
+            print("<br><span class=\"listdesc\">" + description + "</span>")
157 203
 
158 204
     if showLastCommit:
159 205
         link = githubCommitBadge(p)
@@ -165,10 +211,13 @@ def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStart
165 211
 def printRecentMenu(count = 5):
166 212
     posts = [p for p in pages if "date" in p and p.lang == "en"]
167 213
     posts.sort(key=lambda p: p.get("update", p.get("date")), reverse=True)
214
+
168 215
     if count > 0:
169 216
         posts = posts[0:count]
217
+
218
+    lastyear = "0"
170 219
     for p in posts:
171
-        printMenuItem(p, False, False, False, True, "0", "", False)
220
+        lastyear = printMenuItem(p, count == 0, False, False, True, lastyear, "", False, False, 0, True)
172 221
 
173 222
 def printBlogMenu(year_min=None, year_max=None):
174 223
     posts = [p for p in pages if "post" in p and p.lang == "en"]
@@ -186,23 +235,44 @@ def printBlogMenu(year_min=None, year_max=None):
186 235
 def printProjectsMenu():
187 236
     # prints all pages with parent 'projects' or 'stuff'.
188 237
     # first the ones without date, sorted by position.
238
+    # this first section includes sub-headings for children
189 239
     # then afterwards those with date, split by year.
190 240
     # also supports blog posts with parent.
191 241
     enpages = [p for p in pages if p.lang == "en"]
192 242
 
243
+    # select pages without date
193 244
     dpages = [p for p in enpages if p.get("date", "") == ""]
245
+    # only those that have a parent in ['projects', 'stuff']
194 246
     mpages = [p for p in dpages if any(x in p.get("parent", "") for x in [ 'projects', 'stuff' ])]
247
+    # sort by position
195 248
     mpages.sort(key=lambda p: [int(p.get("position", "999"))])
249
+    # print all pages
196 250
     for p in mpages:
197 251
         printMenuItem(p)
198 252
 
253
+        # print subpages for these top-level items
254
+        subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
255
+        for sp in subpages:
256
+            printMenuItem(sp, False, True, True, False, "0", "", False, True, 1)
257
+
258
+    # slect pages with a date
199 259
     dpages = [p for p in enpages if p.get("date", "") != ""]
260
+    # only those that have a parent in ['projects', 'stuff']
200 261
     mpages = [p for p in dpages if any(x in p.get("parent", "") for x in [ 'projects', 'stuff' ])]
262
+    # sort by date
201 263
     mpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
264
+
265
+    # print all pages
202 266
     lastyear = "0"
203 267
     for p in mpages:
204 268
         lastyear = printMenuItem(p, True, True, False, False, lastyear)
205 269
 
270
+        # print subpages for these top-level items
271
+        subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
272
+        subpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
273
+        for sp in subpages:
274
+            printMenuItem(sp, False, True, True, False, "0", "", False, True, 1)
275
+
206 276
 def print3DPrintingMenu():
207 277
     mpages = [p for p in pages if p.get("parent", "") == "3d-printing" and p.lang == "en"]
208 278
     mpages.sort(key=lambda p: int(p["position"]))
@@ -487,9 +557,9 @@ def hook_preconvert_anotherlang():
487 557
             langs.append(lang)
488 558
 
489 559
             if lang == "en":
490
-                filename = re.sub(MKD_PATT, "%s\g<0>" % "", p.fname).split(os.path.sep)[-1]
560
+                filename = re.sub(MKD_PATT, r"%s\g<0>" % "", p.fname).split(os.path.sep)[-1]
491 561
             else:
492
-                filename = re.sub(MKD_PATT, ".%s\g<0>" % lang, p.fname).split(os.path.sep)[-1]
562
+                filename = re.sub(MKD_PATT, r".%s\g<0>" % lang, p.fname).split(os.path.sep)[-1]
493 563
 
494 564
             vp = Page(filename, virtual=text)
495 565
             # Copy real page attributes to the virtual page
@@ -746,6 +816,6 @@ def hook_postconvert_size():
746 816
         except:
747 817
             print("Unable to estimate file size for %s" % matchobj.group(1))
748 818
             return '<a href=\"%s\">%s</a>' % (matchobj.group(1), matchobj.group(3))
749
-    _re_url = '<a href=\"([^\"]*?\.(%s))\">(.*?)<\/a>' % file_ext
819
+    _re_url = r'<a href=\"([^\"]*?\.(%s))\">(.*?)<\/a>' % file_ext
750 820
     for p in pages:
751 821
         p.html = re.sub(_re_url, matched_link, p.html)

+ 5
- 0
static/css/style.css Parādīt failu

@@ -183,6 +183,11 @@ a.anchor {
183 183
     margin-right: 0.5em;
184 184
 }
185 185
 
186
+ul ul {
187
+    font-size: 0.75em;
188
+    margin-bottom: 1em;
189
+}
190
+
186 191
 a:link, a:visited {
187 192
     text-decoration: none;
188 193
 }

Notiek ielāde…
Atcelt
Saglabāt