index.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. import os
  3. from datetime import datetime
  4. from operator import itemgetter
  5. base = """
  6. <html>
  7. <head>
  8. <meta charset="UTF-8">
  9. <title>Ryozuki Blog</title>
  10. <meta name="description" content="All blog entries are listed here.">
  11. <meta name="author" content="Ryozuki">
  12. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  13. <link rel="stylesheet" href="/css/code.css">
  14. <link rel="stylesheet" href="/css/style.css">
  15. <meta name="twitter:card" content="summary" />
  16. <meta name="twitter:site" content="https://ryozuki.xyz/" />
  17. <meta name="twitter:creator" content="@ryozu_ki" />
  18. <meta property="og:title" content="Ryozuki Blog" />
  19. <meta property="og:description" content="All blog entries are listed here." />
  20. <meta name='medium' content='blog'>
  21. </head>
  22. <body>
  23. <div class="container">
  24. <a href="/">cd /</a>
  25. <h2>Ryozuki Blog Index</h2>
  26. <ul>
  27. {body}
  28. </ul>
  29. </div>
  30. </body>
  31. </html>
  32. """
  33. if __name__ == "__main__":
  34. index = []
  35. for x in os.listdir("blog"):
  36. name, ext = os.path.splitext(x)
  37. if ext != ".info":
  38. continue
  39. with open(f"blog/{x}") as f:
  40. title = f.readline().replace("\n", "").strip()
  41. about = f.readline().replace("\n", "").strip()
  42. date = f.readline().strip().replace("\n", "")
  43. index.append((
  44. datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f'),
  45. f"<li>[<span class='green'>{date}</span>] <a href='/blog/{name}.html'>{title}</a></li>"
  46. ))
  47. body = ""
  48. index.sort(key=itemgetter(0))
  49. for x in index:
  50. body += x[1] + "\n"
  51. with open("public/blog/index.html", 'w') as f:
  52. f.write(base.replace("{body}", body))