Initial commit: Basic website rendering, no templating yet.

wch-ch32v003
Felix (xq) Queißner 4 years ago
commit c190601630

1
.gitattributes vendored

@ -0,0 +1 @@
*.zig text=auto eol=lf

@ -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 }} #

2
.gitignore vendored

@ -0,0 +1,2 @@
zig-cache/
render/

3
.gitmodules vendored

@ -0,0 +1,3 @@
[submodule "deps/koino"]
path = deps/koino
url = https://github.com/kivikakk/koino

@ -0,0 +1,3 @@
# Zig Embedded Group - Website and Articles

@ -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);
}

1
deps/koino vendored

@ -0,0 +1 @@
Subproject commit 060611d230cea7996b4518a80137b3e96319a293

@ -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(
\\<!DOCTYPE html>
\\<html lang="en">
\\
\\<head>
\\ <meta charset="utf-8">
\\ <meta name="viewport" content="width=device-width, initial-scale=1">
\\ <title>ZEG</title>
\\<style>
\\ body {
\\ max-width: 40em;
\\ margin-left: auto;
\\ margin-right: auto;
\\ }
\\ h1 {
\\ text-align: center;
\\ }
\\</style>
\\</head>
\\<body>
);
try writer.writeAll(rendered_markdown);
try writer.writeAll(
\\</body>
\\</html>
\\
);
}
},
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);
}

@ -0,0 +1,3 @@
# Embedded Basics
This is a stub.

@ -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 <i>performant</i> 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
Loading…
Cancel
Save