Skip to content

Commit 868ec16

Browse files
committed
Add dates and sorting, and first blogpost
1 parent 684b9fe commit 868ec16

File tree

4 files changed

+74
-26
lines changed

4 files changed

+74
-26
lines changed

src/wiiiikiiii.nim

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,94 @@ import std/paths
55
import std/strformat
66
import std/json
77
import std/tables
8+
import std/algorithm
89

910
const pageName = "pogging.fish"
1011
const donation = ""
1112
const tmpl = readFile("wiki/templates/base.html")
13+
let meta = parseFile("wiki/meta.json")
1214

13-
proc applyTemplate(page: string, tags: string = ""): string =
15+
proc applyTemplate(page: string, tags: string = "", date: string = "(meta pages have no date)"): string =
1416
return multireplace(tmpl,
1517
[("__varHtmlpage__var", page),
1618
("__varTags__var", tags),
19+
("__varCreationdate__var", date),
1720
("__varWikiName__var", pageName),
1821
("__varDonate__var", donation)
1922
]
2023
)
2124

25+
proc getPostDate(i: string): int =
26+
let d = meta{i}{"creationdate"}
27+
if d == nil:
28+
return 19700101
29+
else:
30+
return d.getInt()
31+
32+
proc customCmp(i: (string, string, string), i2: (string, string, string)): int =
33+
return cmp(
34+
getPostDate(i[0]),
35+
getPostDate(i2[0])
36+
)
37+
38+
proc intToDate(i: int): string =
39+
let s = $i
40+
return fmt"{s[0..3]}-{s[4..5]}-{s[6..7]}"
41+
2242
proc createLink(i: (string, string, string)): string =
23-
return fmt"<p><a href=/{i[0]}>{i[1]}</a><small>&ThickSpace;{i[2]}</small><p>"
43+
return fmt"<p><a href=/{i[0]}>{i[1]}</a> on {intToDate(getPostDate(i[0]))} <small>&ThickSpace;{i[2]}</small><p>"
44+
45+
proc getPostTags(i: string): JsonNode =
46+
let t = meta{i}{"tags"}
47+
if t == nil:
48+
return newJArray()
49+
else:
50+
return t
2451

2552
proc main() =
2653
if dirExists(Path("generated")):
2754
removeDir(Path("generated"))
2855
createDir(Path("generated"))
2956
createDir(Path("generated/tags"))
3057
writeFile("generated/base.css", readFile("wiki/templates/base.css"))
31-
let meta = parseFile("wiki/meta.json")
3258
# Generate html files
3359
var index = newSeq[(string, string, string)]()
34-
var tags = initTable[string, seq[(string, string)]]()
60+
var tags = initTable[string, string]()
3561
for i in walkDirRec(Path("wiki/pages")):
3662
let basePath = Path(string(i).split("/")[2..^1].join("/")).changeFileExt(".html")
37-
for dir in string(i).split("/")[0..^2]:
63+
for dir in string(i).split("/")[2..^2]:
3864
createDir(Path("generated/" & dir))
39-
let metadata = meta{string(basePath).replace(".html", ".md")}
65+
let metadata = meta{string(basePath)}
4066
let original = readFile(string(i))
4167
let name = original.split("\n")[0].replace("#", "")
4268
var tagstring = ""
43-
if metadata != nil and metadata{"tags"} != nil:
44-
var first = true
45-
for tag_j in metadata{"tags"}:
46-
let tag = tag_j.getStr()
47-
if not first:
48-
tagstring &= ", "
49-
tagstring &= fmt"<a href=/tags/{tag}.html>{tag}</a>"
50-
first = false
51-
if not tags.hasKey(tag):
52-
tags[tag] = @[]
53-
tags[tag].add((string(basePath), name))
69+
var first = true
70+
for tag_j in getPostTags(string(basePath)):
71+
let tag = tag_j.getStr()
72+
if not first:
73+
tagstring &= ", "
74+
tagstring &= fmt"<a href=/tags/{tag}.html>{tag}</a>"
75+
first = false
76+
if not tags.hasKey(tag):
77+
tags[tag] = ""
5478
let path = "generated/" & string(basePath)
5579
index.add((string(basePath), name, tagstring))
5680
let mdhtml = markdown(original)
57-
writeFile(string(path), applyTemplate(mdhtml, fmt"<p>{tagstring}</p>"))
81+
writeFile(string(path), applyTemplate(mdhtml, fmt"<p>{tagstring}</p>", fmt"{intToDate(getPostDate(string(basePath)))}"))
5882
# Create index page
5983
var indexhtml = "<h2>Looking for something specific? Do CTRL+F to find it!</h2>"
6084
indexhtml &= "tag listing: "
85+
index.sort(customCmp, SortOrder.Descending)
6186
for i in tags.keys():
6287
indexhtml &= fmt"<a href=/tags/{i}.html>{i}</a>&MediumSpace;"
63-
var tagFile = fmt"<h1>Listing for tag '{i}'</h1>"
64-
for tag in tags[i]:
65-
tagFile &= fmt"<p><a href=/{tag[0]}>{tag[1]}</a></p>"
66-
writeFile(fmt"generated/tags/{i}.html", applyTemplate(tagFile))
88+
tags[i] &= fmt"<h1>Listing for tag '{i}'</h1>"
89+
indexhtml &= "<p>(newest posts are first.)</p>"
6790
for i in index:
6891
indexhtml &= createLink(i)
92+
for tag in getPostTags(i[0]):
93+
tags[tag.getStr()] &= createLink(i)
94+
for i in tags.keys():
95+
writeFile(fmt"generated/tags/{i}.html", applyTemplate(tags[i]))
6996
writeFile("generated/indexpage.html", applyTemplate(indexhtml))
7097

7198

wiki/meta.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
2-
"about.md": {
3-
"tags": ["misc", "meta"]
2+
"about.html": {
3+
"tags": ["misc", "meta"],
4+
"creationdate": 20250111
45
},
5-
"index.md": {
6-
"tags": ["misc", "meta"]
6+
"index.html": {
7+
"tags": ["misc", "meta"],
8+
"creationdate": 20250111
9+
},
10+
"blogs/20250112.html": {
11+
"tags": ["blog"],
12+
"creationdate": 20250112
713
}
814
}

wiki/pages/blogs/20250112.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# First Blog Post
2+
This is the beginning of my blog on this site, in this blog I will walk through the things I still have to do on this website.
3+
4+
## Adding Image Support
5+
6+
It should be *fairly* simple. I just need to make it so whenever the code finds a non-markdown file it copies it without converting it to HTML.
7+
8+
## Improve Styling
9+
10+
The website looks fine as of right now but I think some things could be moved around or resized to improve the experience.
11+
12+
## Clean up code
13+
14+
Its quite messy and hacked together right now so it could do with some work, but thats not my #1 priority as of right now.

wiki/templates/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ <h1 class="title">
2121
</nav>
2222
<hr>
2323
<span class="content">
24+
<p>Posted on __varCreationdate__var</p>
2425
__varTags__var
2526
__varHtmlpage__var
2627
</span>

0 commit comments

Comments
 (0)