Compare commits
3 commits
b09a83d10f
...
a467a9038e
Author | SHA1 | Date | |
---|---|---|---|
a467a9038e | |||
0077353224 | |||
34abffdbb6 |
2 changed files with 32 additions and 13 deletions
|
@ -1,11 +0,0 @@
|
|||
#!/bin/sh
|
||||
echo "<ul>"
|
||||
for file in *.md; do
|
||||
title="$(basename "$file" .md)"
|
||||
echo "<li><a href='$title.html'>$title</a></li>"
|
||||
done
|
||||
for file in *.gen; do
|
||||
title="$(basename "$file" .gen)"
|
||||
echo "<li><a href='$title.html'>$title</a></li>"
|
||||
done
|
||||
echo "</ul>"
|
34
compilar.zig
34
compilar.zig
|
@ -67,11 +67,15 @@ pub fn main() !void {
|
|||
var build_dir = try cwd.makeOpenPath("build", .{});
|
||||
defer build_dir.close();
|
||||
|
||||
var page_list = std.ArrayList([]const u8).init(allocator);
|
||||
defer page_list.deinit();
|
||||
defer for (page_list.items) |item| allocator.free(item);
|
||||
|
||||
while (try cwd_iterator.next()) |entry| {
|
||||
if (entry.kind != .File) continue;
|
||||
|
||||
// Autocopiarnos :)
|
||||
if (endsWith(u8, entry.name, ".sh") or
|
||||
if (endsWith(u8, entry.name, ".zig") or
|
||||
endsWith(u8, entry.name, ".md") or
|
||||
endsWith(u8, entry.name, ".css") or
|
||||
endsWith(u8, entry.name, ".png") or
|
||||
|
@ -83,11 +87,17 @@ pub fn main() !void {
|
|||
try cwd.copyFile(entry.name, build_dir, entry.name, .{});
|
||||
}
|
||||
|
||||
if (endsWith(u8, entry.name, ".md") or endsWith(u8, entry.name, ".gen")) {
|
||||
try page_list.append(try allocator.dupe(u8, try stripExtension(entry.name)));
|
||||
}
|
||||
|
||||
if (endsWith(u8, entry.name, ".md"))
|
||||
try generateMarkdown(allocator, cwd, entry.name, build_dir);
|
||||
if (endsWith(u8, entry.name, ".gen"))
|
||||
try generateExecutable(allocator, cwd, entry.name, build_dir);
|
||||
}
|
||||
|
||||
try generatePageList(allocator, build_dir, page_list.items);
|
||||
}
|
||||
|
||||
const Writer = std.io.BufferedWriter(4096, std.fs.File.Writer).Writer;
|
||||
|
@ -144,7 +154,7 @@ fn generateMarkdown(
|
|||
const html = c.cmark_markdown_to_html(
|
||||
markdown.ptr,
|
||||
markdown.len,
|
||||
c.CMARK_OPT_UNSAFE, //| c.CMARK_OPT_SMART,
|
||||
c.CMARK_OPT_UNSAFE | c.CMARK_OPT_SMART,
|
||||
);
|
||||
defer std.c.free(html);
|
||||
|
||||
|
@ -221,3 +231,23 @@ fn generateExecutable(
|
|||
}
|
||||
try output.writeAll(result.stdout);
|
||||
}
|
||||
|
||||
fn generatePageList(
|
||||
allocator: std.mem.Allocator,
|
||||
build_dir: std.fs.Dir,
|
||||
page_list: []const []const u8,
|
||||
) !void {
|
||||
_ = allocator;
|
||||
const name = "Lista de páginas";
|
||||
var output = try build_dir.createFile(name ++ ".html", .{});
|
||||
defer output.close();
|
||||
try header(output.writer(), name, "compilar.zig", .{});
|
||||
|
||||
try output.writeAll("<ul>");
|
||||
for (page_list) |page| {
|
||||
try output.writer().print(
|
||||
\\<li><a href="{0s}.html">{0s}</a></li>
|
||||
, .{page});
|
||||
}
|
||||
try output.writeAll("</ul>");
|
||||
}
|
||||
|
|
Reference in a new issue