Browse Source

put updates to existing pages in rss feed

Thomas Buck 1 year ago
parent
commit
40ff4481a6
1 changed files with 41 additions and 5 deletions
  1. 41
    5
      macros.py

+ 41
- 5
macros.py View File

@@ -306,6 +306,10 @@ def printLatestRelease(user, repo):
306 306
 # preconvert hooks
307 307
 # -----------------------------------------------------------------------------
308 308
 
309
+# -----------------------------------------------------------------------------
310
+# multi language support
311
+# -----------------------------------------------------------------------------
312
+
309 313
 def hook_preconvert_anotherlang():
310 314
     MKD_PATT = r'\.(?:md|mkd|mdown|markdown)$'
311 315
     _re_lang = re.compile(r'^[\s+]?lang[\s+]?[:=]((?:.|\n )*)', re.MULTILINE)
@@ -356,7 +360,9 @@ def hook_preconvert_anotherlang():
356 360
 
357 361
     pages[:] = vpages
358 362
 
359
-
363
+# -----------------------------------------------------------------------------
364
+# compatibility redirect for old website URLs
365
+# -----------------------------------------------------------------------------
360 366
 
361 367
 _COMPAT = """        case "%s":
362 368
             $loc = "%s/%s";
@@ -399,7 +405,9 @@ def hook_preconvert_compat():
399 405
     fp.write("?>")
400 406
     fp.close()
401 407
 
402
-
408
+# -----------------------------------------------------------------------------
409
+# sitemap generation
410
+# -----------------------------------------------------------------------------
403 411
 
404 412
 _SITEMAP = """<?xml version="1.0" encoding="UTF-8"?>
405 413
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -431,6 +439,10 @@ def hook_preconvert_sitemap():
431 439
 # postconvert hooks
432 440
 # -----------------------------------------------------------------------------
433 441
 
442
+# -----------------------------------------------------------------------------
443
+# rss feed generation
444
+# -----------------------------------------------------------------------------
445
+
434 446
 _RSS = """<?xml version="1.0"?>
435 447
 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
436 448
 <channel>
@@ -443,6 +455,7 @@ _RSS = """<?xml version="1.0"?>
443 455
 <lastBuildDate>%s</lastBuildDate>
444 456
 <docs>http://blogs.law.harvard.edu/tech/rss</docs>
445 457
 <generator>Poole</generator>
458
+<ttl>720</ttl>
446 459
 %s
447 460
 </channel>
448 461
 </rss>
@@ -454,28 +467,43 @@ _RSS_ITEM = """
454 467
     <link>%s</link>
455 468
     <description>%s</description>
456 469
     <pubDate>%s</pubDate>
470
+    <atom:updated>%s</atom:updated>
457 471
     <guid>%s</guid>
458 472
 </item>
459 473
 """
460 474
 
461 475
 def hook_postconvert_rss():
462 476
     items = []
477
+
478
+    # all pages with "date" get put into feed
463 479
     posts = [p for p in pages if "date" in p]
464
-    posts.sort(key=lambda p: p.date, reverse=True)
465
-    posts = posts[:10]
480
+
481
+    # sort by update if available, date else
482
+    posts.sort(key=lambda p: p.get("update", p.date), reverse=True)
483
+
484
+    # only put 20 most recent items in feed
485
+    posts = posts[:20]
486
+
466 487
     for p in posts:
467 488
         title = p.title
468 489
         if "post" in p:
469 490
             title = p.post
491
+
470 492
         link = "%s/%s" % (BASE_URL, p.url)
493
+
471 494
         desc = p.html.replace("href=\"img", "%s%s%s" % ("href=\"", BASE_URL, "/img"))
472 495
         desc = desc.replace("src=\"img", "%s%s%s" % ("src=\"", BASE_URL, "/img"))
473 496
         desc = desc.replace("href=\"/img", "%s%s%s" % ("href=\"", BASE_URL, "/img"))
474 497
         desc = desc.replace("src=\"/img", "%s%s%s" % ("src=\"", BASE_URL, "/img"))
475 498
         desc = htmlspecialchars(desc)
499
+
476 500
         date = time.mktime(time.strptime("%s 12" % p.date, "%Y-%m-%d %H"))
477 501
         date = email.utils.formatdate(date)
478
-        items.append(_RSS_ITEM % (title, link, desc, date, link))
502
+
503
+        update = time.mktime(time.strptime("%s 12" % p.get("update", p.date), "%Y-%m-%d %H"))
504
+        update = email.utils.formatdate(update)
505
+
506
+        items.append(_RSS_ITEM % (title, link, desc, date, update, link))
479 507
 
480 508
     items = "".join(items)
481 509
 
@@ -491,6 +519,10 @@ def hook_postconvert_rss():
491 519
     fp.write(rss)
492 520
     fp.close()
493 521
 
522
+# -----------------------------------------------------------------------------
523
+# compatibility redirect for old mobile pages
524
+# -----------------------------------------------------------------------------
525
+
494 526
 _COMPAT_MOB = """        case "%s":
495 527
             $loc = "%s/%s";
496 528
             break;
@@ -535,6 +567,10 @@ def hook_postconvert_mobilecompat():
535 567
     fp.write("?>")
536 568
     fp.close()
537 569
 
570
+# -----------------------------------------------------------------------------
571
+# displaying filesize for download links
572
+# -----------------------------------------------------------------------------
573
+
538 574
 def hook_postconvert_size():
539 575
     file_ext = '|'.join(['pdf', 'zip', 'rar', 'ods', 'odt', 'odp', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'exe', 'brd', 'plist'])
540 576
     def matched_link(matchobj):

Loading…
Cancel
Save