Compare commits
No commits in common. "a467a9038ec908d39dcf4a56683223a09ebded30" and "b09a83d10f582b8d32144f6f4a3ed91a347dce40" have entirely different histories.
a467a9038e
...
b09a83d10f
2 changed files with 13 additions and 32 deletions
11
Lista de páginas.gen
Executable file
11
Lista de páginas.gen
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/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,15 +67,11 @@ 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, ".zig") or
|
||||
if (endsWith(u8, entry.name, ".sh") or
|
||||
endsWith(u8, entry.name, ".md") or
|
||||
endsWith(u8, entry.name, ".css") or
|
||||
endsWith(u8, entry.name, ".png") or
|
||||
|
@ -87,17 +83,11 @@ 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;
|
||||
|
@ -154,7 +144,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);
|
||||
|
||||
|
@ -231,23 +221,3 @@ 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