Browse Source

added a homepage generator

Izaya 2 months ago
parent
commit
63ab3b285f
2 changed files with 51 additions and 0 deletions
  1. 1
    0
      genall.sh
  2. 50
    0
      home.lua

+ 1
- 0
genall.sh View File

@@ -2,3 +2,4 @@
2 2
 ./genpages.lua
3 3
 ./blog.lua
4 4
 ./tags.lua
5
+./home.lua

+ 50
- 0
home.lua View File

@@ -0,0 +1,50 @@
1
+#!/usr/bin/env lua
2
+local sitelib = require "sitelib"
3
+local fs = require "lfs"
4
+local articles = 4
5
+
6
+print("Finding blog posts...")
7
+local ftab = {}
8
+for file in fs.dir(sitelib.srcpath.."/blog") do
9
+ if file:sub(1,1) ~= "." then
10
+  local index = tonumber(file:match("(%d+).md"))
11
+  if index then
12
+   ftab[index] = file
13
+  end
14
+ end
15
+end
16
+
17
+local pages = {}
18
+for i = #ftab, #ftab-(articles-1), -1 do
19
+ local f = io.open(sitelib.srcpath.."/blog/"..ftab[i])
20
+ local c = f:read("*a")
21
+ f:close()
22
+ local page = sitelib.parsepage(c)
23
+ pages[#pages+1] = {page.title,"/blog/"..tostring(i)..".html"}
24
+end
25
+
26
+print("Reading template...")
27
+local f = io.open(sitelib.includepath.."/home-top.html","rb")
28
+local header = f:read("*a")
29
+f:close()
30
+local f = io.open(sitelib.includepath.."/home-end.html","rb")
31
+local footer = f:read("*a")
32
+f:close()
33
+
34
+print("Writing index...")
35
+local f = io.open(sitelib.outpath.."/index.html","wb")
36
+f:write(header)
37
+while #pages > 0 do
38
+ local lp, rp = table.remove(pages,1), table.remove(pages,1)
39
+ f:write('<div class="wrapper">')
40
+ f:write(' <div class="left-column">')
41
+ f:write('  <h2><a href="'..lp[2]..'">'..lp[1]..'</a></h2>')
42
+ f:write(' </div>')
43
+ f:write(' <div class="right-column">')
44
+ f:write('  <h2><a href="'..rp[2]..'">'..rp[1]..'</a></h2>')
45
+ f:write(' </div>')
46
+ f:write('</div>')
47
+end
48
+f:write(footer)
49
+f:write(sitelib.footer)
50
+f:close()