diff --git a/src/feed.gr b/src/feed.gr index aa6dc03..52b5ea7 100644 --- a/src/feed.gr +++ b/src/feed.gr @@ -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]) } diff --git a/src/generate_site.gr b/src/generate_site.gr index c1819b0..811f898 100644 --- a/src/generate_site.gr +++ b/src/generate_site.gr @@ -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" diff --git a/src/html.gr b/src/html.gr index 25aaa55..c824612 100644 --- a/src/html.gr +++ b/src/html.gr @@ -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] diff --git a/src/router.gr b/src/router.gr index d727b3a..b736652 100644 --- a/src/router.gr +++ b/src/router.gr @@ -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 @@ -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 } }