Skip to content

Commit

Permalink
Generate feed.xml content
Browse files Browse the repository at this point in the history
  • Loading branch information
mliezun committed Jan 10, 2024
1 parent 83a3f2f commit 58ef8f3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
44 changes: 43 additions & 1 deletion src/feed.gr
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
let u = import("./utils.gr")
let html = import("./html.gr")

fn generate_feed(posts) {
return ""
let renderer = html.Renderer()
posts = u.sortBy(posts, fn (a, b) {
if a["date"] < b["date"] {
return 1
} elif a["date"] > b["date"] {
return -1
} else {
return 0
}
})
let content = ["xml", ["xmlns", "http://www.w3.org/2005/Atom"], [
["generator", ["uri", "https://github.com/mliezun/mliezun.github.io", "version", "20240110"], [
"mliezun.github.io"
]],
["link", ["href", "https://mliezun.github.io/feed.xml", "rel", "self", "type", "application/atom+xml"]],
["link", ["href", "https://mliezun.github.io/", "rel", "alternate", "type", "text/html"]],
["id", [], ["https://mliezun.github.io/"]],
["title", [], ["mliezun.github.io"]],
["updated", [], [posts[0]["date"]]],
["subtitle", [], ["I'm Miguel. Here I write mainly about programming and side projects."]],
]]
let entries = u.map(posts, fn (p) {
let post_obj = p["post_obj"]
let url = "https://mliezun.github.io" + p["url"]
let date = p["date"]
return ["entry", [], [
["title", ["type", "html"], [post_obj.title]],
["id", [], [url]],
["updated", [], [date]],
["link", ["href", url, "rel", "alternate", "type", "text/html"]],
["content", ["type", "html", "xml:base", url], post_obj.content],
["author", [], [
["name", [], "Miguel Liezun"]
]],
["category", ["term", "posts"]],
["summary", ["type", "html"], [post_obj.excerpt]]
]]
})
content[2] = content[2] + entries
return renderer.render([content])
}
2 changes: 1 addition & 1 deletion src/generate_site.gr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let w = web.Web()

for url, route in w.routes {
let basePath = "./docs"
if route["class"] == "html" {
if route["class"] == "html" or url == "/feed.xml" {
let fullPath = ""
if url == "/" {
fullPath = basePath + "/index.html"
Expand Down
26 changes: 24 additions & 2 deletions src/html.gr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@ let u = import("utils.gr")

class Renderer {
init() {
this.tags = ["!DOCTYPE HTML", "LITERAL", "a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "command", "datalist", "dd", "del", "details", "dfn", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "map", "mark", "menu", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "var", "video", "wbr"]
this.voidTags = ["!DOCTYPE HTML", "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]
this.tags = [
# HTML Tags
"!DOCTYPE HTML", "LITERAL", "a", "abbr", "address", "area", "article", "aside", "audio",
"b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption",
"cite", "code", "col", "colgroup", "command", "datalist", "dd", "del", "details", "dfn",
"div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form",
"h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe",
"img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "map", "mark",
"menu", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output",
"p", "param", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section",
"select", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "table",
"tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u",
"ul", "var", "video", "wbr",
# XML Tags
"xml", "id", "updated", "subtitle", "entry", "author", "name", "updated", "content",
"generator", "category", "summary",
]
this.voidTags = [
# HTML Tags
"!DOCTYPE HTML", "area", "base", "br", "col", "command", "embed", "hr", "img", "input",
"keygen", "link", "meta", "param", "source", "track", "wbr",
# XML Tags
"category",
]
}

# Renders [tag, props, content]
Expand Down
5 changes: 3 additions & 2 deletions src/router.gr
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ fn get_routes() {
})

# Build rss feed
io.println("feed", feed.generate_feed(posts))
routes["/feed.xml"] = {
"class": "static",
"content": feed.generate_feed(posts)
"content": feed.generate_feed(posts),
}

# Build index using posts dicts
Expand All @@ -110,7 +111,7 @@ fn get_routes() {
"author": "Miguel Liezun",
"tags": "software,tech,fun",
"date": "",
"excerpt": "Blog about programming and side projects",
"excerpt": "I'm Miguel. Here I write mainly about programming and side projects.",
"content_type": nil
}
}
Expand Down

0 comments on commit 58ef8f3

Please sign in to comment.