Adds atom feed and nice index.

wch-ch32v003
Felix (xq) Queißner 4 years ago
parent d56f0bf86e
commit 96b10b11ff

@ -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(
\\<?xml version="1.0" encoding="utf-8"?>
\\<feed xmlns="http://www.w3.org/2005/Atom">
\\ <author>
\\ <name>Zig Embedded Group</name>
\\ </author>
\\ <title>Zig Embedded Group</title>
\\ <id>https://zeg.random-projects.net/</id>
\\
);
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(" <updated>{d:0>4}-{d:0>2}-{d:0>2}T{d:0>2}:00:00Z</updated>\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(
\\ <entry>
\\ <title>{s}</title>
\\ <link href="https://zeg.random-projects.net/articles/{s}.htm" />
\\ <id>zeg.random-projects.net/articles/{s}.htm</id>
\\ <updated>{d:0>4}-{d:0>2}-{d:0>2}T00:00:00Z</updated>
\\ </entry>
\\
, .{
article.title,
uri_name,
uri_name,
article.date.year,
article.date.month,
article.date.day,
});
}
try feed_writer.writeAll("</feed>");
}
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),
.{},
);
}
}
};

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1em" height="1em" id="RSSicon" viewBox="0 0 256 256">
<defs>
<linearGradient x1="0.085" y1="0.085" x2="0.915" y2="0.915" id="RSSg">
<stop offset="0.0" stop-color="#E3702D" />
<stop offset="0.1071" stop-color="#EA7D31" />
<stop offset="0.3503" stop-color="#F69537" />
<stop offset="0.5" stop-color="#FB9E3A" />
<stop offset="0.7016" stop-color="#EA7C31" />
<stop offset="0.8866" stop-color="#DE642B" />
<stop offset="1.0" stop-color="#D95B29" />
</linearGradient>
</defs>
<rect width="256" height="256" rx="55" ry="55" x="0" y="0" fill="#CC5D15" />
<rect width="246" height="246" rx="50" ry="50" x="5" y="5" fill="#F49C52" />
<rect width="236" height="236" rx="47" ry="47" x="10" y="10" fill="url(#RSSg)" />
<circle cx="68" cy="189" r="24" fill="#FFF" />
<path d="M160 213h-34a82 82 0 0 0 -82 -82v-34a116 116 0 0 1 116 116z" fill="#FFF" />
<path d="M184 213A140 140 0 0 0 44 73 V 38a175 175 0 0 1 175 175z" fill="#FFF" />
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -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 <i>performant</i> 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:
<!-- ARTICLES -->
[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/)

Loading…
Cancel
Save