From 96b10b11ffeee1ede589aaf461bdf598c5c7e167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=28xq=29=20Quei=C3=9Fner?= Date: Sat, 13 Mar 2021 20:19:34 +0100 Subject: [PATCH] Adds atom feed and nice index. --- src/main.zig | 108 +++++++++++++++++++++++++++++++++++++++++++ website/img/atom.svg | 21 +++++++++ website/index.md | 18 ++++---- 3 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 website/img/atom.svg diff --git a/src/main.zig b/src/main.zig index b83db83..ad2b859 100644 --- a/src/main.zig +++ b/src/main.zig @@ -37,6 +37,7 @@ pub fn main() anyerror!void { .arena = std.heap.ArenaAllocator.init(allocator), .articles = std.ArrayList(Article).init(allocator), .tutorials = std.ArrayList(Tutorial).init(allocator), + .images = std.ArrayList([]const u8).init(allocator), }; defer website.deinit(); @@ -74,6 +75,29 @@ pub fn main() anyerror!void { .src_file = "website/tutorials/05-hal.md", }); + // img articles + { + var dir = try root_dir.openDir("img", .{ .iterate = true }); + defer dir.close(); + + var iter = dir.iterate(); + + while (try iter.next()) |entry| { + if (entry.kind != .File) { + std.log.err("Illegal folder in directory website/img: {s}", .{entry.name}); + continue; + } + + const path = try std.fs.path.join(&website.arena.allocator, &[_][]const u8{ + "website", + "img", + entry.name, + }); + + try website.addImage(path); + } + } + // gather articles { var dir = try root_dir.openDir("articles", .{ .iterate = true }); @@ -125,9 +149,16 @@ pub fn main() anyerror!void { var tut_dir = try root_dir.makeOpenPath("tutorials", .{}); defer tut_dir.close(); + var img_dir = try root_dir.makeOpenPath("img", .{}); + defer img_dir.close(); + try website.renderArticles(art_dir); try website.renderTutorials(tut_dir); + + try website.renderAtomFeed(root_dir, "feed.atom"); + + try website.renderImages(img_dir); } } @@ -194,10 +225,12 @@ const Website = struct { arena: std.heap.ArenaAllocator, articles: std.ArrayList(Article), tutorials: std.ArrayList(Tutorial), + images: std.ArrayList([]const u8), fn deinit(self: *Self) void { self.tutorials.deinit(); self.articles.deinit(); + self.images.deinit(); self.arena.deinit(); self.* = undefined; } @@ -219,6 +252,11 @@ const Website = struct { }); } + fn addImage(self: *Self, path: []const u8) !void { + self.is_prepared = false; + try self.images.append(try self.arena.allocator.dupe(u8, path)); + } + fn findTitle(self: *Self, file: []const u8) !?[]const u8 { var doc = blk: { var p = try koino.parser.Parser.init(self.allocator, markdown_options); @@ -467,4 +505,74 @@ const Website = struct { \\ ); } + + fn renderAtomFeed(self: *Self, dir: std.fs.Dir, file_name: []const u8) !void { + var feed_file = try dir.createFile(file_name, .{}); + defer feed_file.close(); + + var feed_writer = feed_file.writer(); + + try feed_writer.writeAll( + \\ + \\ + \\ + \\ Zig Embedded Group + \\ + \\ Zig Embedded Group + \\ https://zeg.random-projects.net/ + \\ + ); + + var last_update = Date{ .year = 0, .month = 0, .day = 0 }; + var article_count: usize = 0; + for (self.articles.items) |article| { + if (last_update.lessThan(article.date)) { + last_update = article.date; + article_count = 0; + } else { + article_count += 1; + } + } + + try feed_writer.print(" {d:0>4}-{d:0>2}-{d:0>2}T{d:0>2}:00:00Z\n", .{ + last_update.year, + last_update.month, + last_update.day, + article_count, // this is fake, but is just here for creating a incremental version for multiple articles a day + }); + + for (self.articles.items) |article| { + const uri_name = try self.urlEscape(removeExtension(article.src_file)); + try feed_writer.print( + \\ + \\ {s} + \\ + \\ zeg.random-projects.net/articles/{s}.htm + \\ {d:0>4}-{d:0>2}-{d:0>2}T00:00:00Z + \\ + \\ + , .{ + article.title, + uri_name, + uri_name, + article.date.year, + article.date.month, + article.date.day, + }); + } + + try feed_writer.writeAll(""); + } + + fn renderImages(self: Self, target_dir: std.fs.Dir) !void { + for (self.images.items) |img| { + try std.fs.Dir.copyFile( + std.fs.cwd(), + img, + target_dir, + std.fs.path.basename(img), + .{}, + ); + } + } }; diff --git a/website/img/atom.svg b/website/img/atom.svg new file mode 100644 index 0000000..b870f3e --- /dev/null +++ b/website/img/atom.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/website/index.md b/website/index.md index 6fdd918..e3cdf07 100644 --- a/website/index.md +++ b/website/index.md @@ -2,7 +2,7 @@ This group was formed to document and improve the embedded programming experience with the [Zig programming language](https://ziglang.org). -## Goals +## 🏁 Goals - Provide documents on how to get started with embedded programming (for absolute newbies) - Provide example snippets for certain architectures (LPC, STM32, AVR, ...) @@ -10,7 +10,7 @@ This group was formed to document and improve the embedded programming experienc - Create a common interface/HAL over several architectures - Create a performant common set of drivers for external platforms -## Introduction to embedded programming +## πŸ§‘β€πŸ« Introduction to embedded programming If you've never done any embedded development before, it's a good point to start with one of our tutorials: @@ -28,15 +28,17 @@ If you've never done any embedded development before, it's a good point to start - [What device to chose?](tutorials/04-chose-device.htm) - [Introduction to HAL 9001](tutorials/05-hal.htm) -## Latest Articles +## πŸ“š Latest Articles The latest articles on embedded programming with Zig: -[See all articles...](articles.htm) +[↗️ See all articles...](articles.htm) -## Code +[![Atom Feed](img/atom.svg) Subscribe the Atom feed](feed.atom) + +## πŸ’» Code Here are some highlighted projects the ZEG provides: @@ -48,15 +50,15 @@ Here are some highlighted projects the ZEG provides: - [zCOM Network Driver](#) - [TinySSL](#) -[See all repositories...](https://github.com/ZigEmbeddedGroup/) +[↗️ See all repositories...](https://github.com/ZigEmbeddedGroup/) -## Community +## πŸ’¬ Community This group uses the already existing community infrastructures that exist for Zig: - [Zig Programming Language - Discord Server](https://discord.gg/TyzJXjser6) -## Members +## πŸ‘₯ Members - [Felix "xq" Queißner](https://github.com/MasterQ32/) - [Matthew "mattnite" Knight](https://github.com/mattnite/)