From c19060163054fbdf24a9ecdad070b5c04a654f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=28xq=29=20Quei=C3=9Fner?= Date: Wed, 10 Mar 2021 12:21:04 +0100 Subject: [PATCH] Initial commit: Basic website rendering, no templating yet. --- .gitattributes | 1 + .github/workflows/website.yml | 30 +++++++ .gitignore | 2 + .gitmodules | 3 + README.md | 3 + build.zig | 32 +++++++ deps/koino | 1 + src/main.zig | 111 +++++++++++++++++++++++++ website/articles/01-embedded-basics.md | 3 + website/index.md | 44 ++++++++++ 10 files changed, 230 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/workflows/website.yml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 README.md create mode 100644 build.zig create mode 160000 deps/koino create mode 100644 src/main.zig create mode 100644 website/articles/01-embedded-basics.md create mode 100644 website/index.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0cb064a --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.zig text=auto eol=lf diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 0000000..e0db162 --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,30 @@ +name: Render Website + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + submodules: "recursive" + + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v1 + with: + version: master + + - name: Render website + run: | + zig build gen + + - name: Deploy with SCP + uses: noobly314/deploy-with-scp@v1 + with: + src: render/ + dest: zeg/ + username: generic-ci + server-ip: random-projects.net + ssh-key: ${{ secrets.WEBSITE_PRIVATE_KEY }} # diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b14c7fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +zig-cache/ +render/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3fc6085 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/koino"] + path = deps/koino + url = https://github.com/kivikakk/koino diff --git a/README.md b/README.md new file mode 100644 index 0000000..61d47cc --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Zig Embedded Group - Website and Articles + + diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..8056841 --- /dev/null +++ b/build.zig @@ -0,0 +1,32 @@ +const std = @import("std"); + +const pkgs = struct { + const koino = std.build.Pkg{ + .name = "koino", + .path = "./deps/koino/src/koino.zig", + .dependencies = &[_]std.build.Pkg{ + std.build.Pkg{ .name = "libpcre", .path = "deps/koino/vendor/libpcre.zig/src/main.zig" }, + std.build.Pkg{ .name = "htmlentities", .path = "deps/koino/vendor/htmlentities.zig/src/main.zig" }, + std.build.Pkg{ .name = "clap", .path = "deps/koino/vendor/zig-clap/clap.zig" }, + std.build.Pkg{ .name = "zunicode", .path = "deps/koino/vendor/zunicode/src/zunicode.zig" }, + }, + }; +}; + +const linkPcre = @import("deps/koino/vendor/libpcre.zig/build.zig").linkPcre; + +pub fn build(b: *std.build.Builder) !void { + const target = b.standardTargetOptions(.{}); + const mode = b.standardReleaseOptions(); + + const render_website = b.addExecutable("zeg-website", "src/main.zig"); + render_website.setTarget(target); + render_website.setBuildMode(mode); + try linkPcre(render_website); + render_website.addPackage(pkgs.koino); + + const gen_cmd = render_website.run(); + + const gen_step = b.step("gen", "Generates the website"); + gen_step.dependOn(&gen_cmd.step); +} diff --git a/deps/koino b/deps/koino new file mode 160000 index 0000000..060611d --- /dev/null +++ b/deps/koino @@ -0,0 +1 @@ +Subproject commit 060611d230cea7996b4518a80137b3e96319a293 diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..afab84d --- /dev/null +++ b/src/main.zig @@ -0,0 +1,111 @@ +const std = @import("std"); +const koino = @import("koino"); + +pub fn main() anyerror!void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + + const allocator = &gpa.allocator; + + var root_dir = try std.fs.walkPath(allocator, "website"); + defer root_dir.deinit(); + + const markdown_options = koino.Options{ + .extensions = .{ + .table = true, + .autolink = true, + .strikethrough = true, + }, + }; + + while (try root_dir.next()) |entry| { + switch (entry.kind) { + // we create the directories by forcing them + .Directory => {}, + + .File => { + const ext = std.fs.path.extension(entry.path); + if (std.mem.eql(u8, ext, ".md")) { + std.log.info("render {s}", .{entry.path}); + + const out_name = try std.mem.concat(allocator, u8, &[_][]const u8{ + entry.path[8 .. entry.path.len - 3], + ".htm", + }); + defer allocator.free(out_name); + + var out_path = try std.fs.path.join(allocator, &[_][]const u8{ + "render", out_name, + }); + defer allocator.free(out_path); + + if (std.fs.path.dirname(out_path)) |dir| { + std.debug.print("{s}\n", .{dir}); + try std.fs.cwd().makePath(dir); + } + + var markdown_input = try std.fs.cwd().readFileAlloc(allocator, entry.path, 10_000_000); + defer allocator.free(markdown_input); + + var rendered_markdown = try markdownToHtml(allocator, markdown_options, markdown_input); + defer gpa.allocator.free(rendered_markdown); + + var output_file = try std.fs.cwd().createFile(out_path, .{}); + defer output_file.close(); + + var writer = output_file.writer(); + + try writer.writeAll( + \\ + \\ + \\ + \\ + \\ + \\ + \\ ZEG + \\ + \\ + \\ + ); + + try writer.writeAll(rendered_markdown); + + try writer.writeAll( + \\ + \\ + \\ + ); + } + }, + + else => std.debug.panic("Unsupported file type {s} in directory!", .{@tagName(entry.kind)}), + } + } +} + +fn markdownToHtmlInternal(resultAllocator: *std.mem.Allocator, internalAllocator: *std.mem.Allocator, options: koino.Options, markdown: []const u8) ![]u8 { + var p = try koino.parser.Parser.init(internalAllocator, options); + try p.feed(markdown); + + var doc = try p.finish(); + p.deinit(); + + defer doc.deinit(); + + return try koino.html.print(resultAllocator, p.options, doc); +} + +pub fn markdownToHtml(allocator: *std.mem.Allocator, options: koino.Options, markdown: []const u8) ![]u8 { + var arena = std.heap.ArenaAllocator.init(allocator); + defer arena.deinit(); + return markdownToHtmlInternal(allocator, &arena.allocator, options, markdown); +} diff --git a/website/articles/01-embedded-basics.md b/website/articles/01-embedded-basics.md new file mode 100644 index 0000000..3e17739 --- /dev/null +++ b/website/articles/01-embedded-basics.md @@ -0,0 +1,3 @@ +# Embedded Basics + +This is a stub. \ No newline at end of file diff --git a/website/index.md b/website/index.md new file mode 100644 index 0000000..b331cdd --- /dev/null +++ b/website/index.md @@ -0,0 +1,44 @@ +# Zig Embedded Group + +This group was formed to document and improve the embedded programming experience with the [Zig programming language](https://ziglang.org). + +Right now, this group has the following members: + +- [Felix "xq" Queißner](https://github.com/masterQ32/) +- [Matthew "mattnite" Knight](https://github.com/mattnite/) +- [Vesim](https://github.com/vesim987/) +- [Timon "FireFox317" Kruiper](https://github.com/FireFox317) +- [Martin "SpexGuy" Wickham](https://github.com/SpexGuy) + +## Goals + +- Provide documents on how to get started with embedded programming (for absolute newbies) +- Provide example snippets for certain architectures (LPC, STM32, AVR, ...) +- Create register definition libraries +- Create a common interface/HAL over several architectures +- Create a performant common set of drivers for external platforms + +## Community + +This group uses the already existing community infrastructures that exist for Zig: + +- [Zig Programming Language - Discord Server](https://discord.gg/TyzJXjser6) + +## Planned Documents/Articles + +- Getting started with embedded (not specific to a platform) + Contains info about basic digital electronics, what MMIO is and how it works, what are the differences to "normal" programs how is the startup pocess, ... +- Getting started with + - Arduino/AVR + - LPC1768 + - STM32 + - MSP430 + - ESP2866/ESP32 + - NRF52 + - Raspberry PI +- Using `async` code on embedded. +- Make your own keyboard with zig (and replace qmk) + +## Required Stuff + +- Fanart by the guy from ziglings \ No newline at end of file