Skip to content

Commit

Permalink
add supermd
Browse files Browse the repository at this point in the history
This is actually work that happenend in a branch but
because of an attempt to remove a bunch of vendored
libs from the history of the repo, merging doesn't work
anymore so I'm just merging everything as a single commit anyway.

See the `supermd` branch for the history of this work if you really
care, otherwise I would have squashed everything anyway.

Jokes on you git, your shitty interface in the end has not made me
do anything that I didn't want to do already.
  • Loading branch information
kristoff-it committed Aug 29, 2024
1 parent 6c7174d commit 9141698
Show file tree
Hide file tree
Showing 31 changed files with 4,766 additions and 1,741 deletions.
105 changes: 67 additions & 38 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,46 @@ pub const MultilingualSite = struct {
/// - `name`
/// - `install_path` (if set, unless `link`ing them is mutually exclusive)
build_assets: []const BuildAsset = &.{},
/// A list of localized variants of this website.
/// A list of locales of this website.
///
/// For each entry the following values must be unique:
/// - `locale_code`
/// - `output_prefix_override` (if set)
localized_variants: []const LocalizedVariant,
/// - `code`
/// - `output_prefix_override` (if set) + `host_url_override`
locales: []const Locale,

/// Enables Zine's -Ddebug and -Dscope flags
/// (only useful if you're developing Zine)
debug: bool = false,
};

pub const LocalizedVariant = struct {
/// Site title for this localized variant.
title: []const u8,
/// A language-NATION code, e.g. 'en-US'.
locale_code: []const u8,
/// Content dir for this localized variant.
content_dir_path: []const u8,
/// Set to a non-null value when deploying this variant from a dedicated
/// host (e.g. 'https://us.site.com', 'http://de.site.com').
///
/// It must not contain a subpath.
host_url_override: ?[]const u8 = null,
/// | output_ | host_ | resulting | resulting |
/// | prefix_ | url_ | url | path |
/// | override | override | prefix | prefix |
/// | -------- | ------------- | ---------------- | --------------- |
/// | null | null | site.com/en-US/ | zig-out/en-US/ |
/// | null | "us.site.com" | us.site.com/ | zig-out/en-US/ |
/// | "foo" | null | site.com/foo/ | zig-out/foo/ |
/// | "foo" | "us.site.com" | us.site.com/foo/ | zig-out/foo/ |
/// | "" | null | site.com/ | zig-out/ |
///
/// The last case is how you create a default localized variant.
output_prefix_override: ?[]const u8 = null,
};
/// A localized variant of a multilingual website
pub const Locale = struct {
/// A language-NATION code, e.g. 'en-US', used to identify each
/// individual localized variant of the website.
code: []const u8,
/// A name that identifies this locale, e.g. 'English'
name: []const u8,
/// Content dir for this locale,
content_dir_path: []const u8,
/// Site title for this locale.
site_title: []const u8,
/// Set to a non-null value when deploying this locale from a dedicated
/// host (e.g. 'https://us.site.com', 'http://de.site.com').
///
/// It must not contain a subpath.
host_url_override: ?[]const u8 = null,
/// | output_ | host_ | resulting | resulting |
/// | prefix_ | url_ | url | path |
/// | override | override | prefix | prefix |
/// | -------- | ------------- | ---------------- | --------------- |
/// | null | null | site.com/en-US/ | zig-out/en-US/ |
/// | null | "us.site.com" | us.site.com/ | zig-out/en-US/ |
/// | "foo" | null | site.com/foo/ | zig-out/foo/ |
/// | "foo" | "us.site.com" | us.site.com/foo/ | zig-out/foo/ |
/// | "" | null | site.com/ | zig-out/ |
///
/// The last case is how you create a default locale.
output_prefix_override: ?[]const u8 = null,
};

/// Defines a default Zine project:
Expand Down Expand Up @@ -229,7 +233,7 @@ pub fn multilingualWebsite(b: *std.Build, multi: MultilingualSite) void {
multi.i18n_dir_path,
}) catch unreachable;

for (multi.localized_variants) |v| {
for (multi.locales) |v| {
if (v.host_url_override) |_| {
@panic("TODO: a variant specifies a dedicated host but multihost support for the dev server has not been implemented yet.");
}
Expand Down Expand Up @@ -335,20 +339,45 @@ fn defaultZineOptions(b: *std.Build, debug: bool) ZineOptions {

pub fn scriptyReferenceDocs(
project: *std.Build,
output_file_path: []const u8,
shtml_output_file_path: []const u8,
smd_output_file_path: []const u8,
) void {
const zine_dep = project.dependencyFromBuildZig(
zine,
.{ .optimize = .Debug },
);

const run_docgen = project.addRunArtifact(zine_dep.artifact("docgen"));
const reference_md = run_docgen.addOutputFileArg("scripty_reference.md");
const run_step = project.step(
"docgen",
"Regenerates Scripty reference docs",
);

{
const run_docgen = project.addRunArtifact(
zine_dep.artifact("shtml_docgen"),
);

const reference_md = run_docgen.addOutputFileArg(
"shtml_scripty_reference.smd",
);

const wf = project.addWriteFiles();
wf.addCopyFileToSource(reference_md, output_file_path);
const wf = project.addWriteFiles();
wf.addCopyFileToSource(reference_md, shtml_output_file_path);

run_step.dependOn(&wf.step);
}
{
const run_docgen = project.addRunArtifact(
zine_dep.artifact("smd_docgen"),
);

const desc = project.fmt("Regenerates Scripty reference docs in '{s}'", .{output_file_path});
const run_step = project.step("docgen", desc);
run_step.dependOn(&wf.step);
const reference_md = run_docgen.addOutputFileArg(
"smd_scripty_reference.smd",
);

const wf = project.addWriteFiles();
wf.addCopyFileToSource(reference_md, smd_output_file_path);

run_step.dependOn(&wf.step);
}
}
29 changes: 15 additions & 14 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
.name = "zine",
.version = "0.0.0",
.dependencies = .{
.gfm = .{
.url = "git+https://github.com/kristoff-it/cmark-gfm.git#b7034624e7da6857a26e4720cd7fde26d5bc715c",
.hash = "122018a99dd8299e00d6b3279fc5fee9f93fd4c773db34f6390fcbed320cf4d652c1",
.supermd = .{
.url = "git+https://github.com/kristoff-it/supermd#125305aa31ef41e9ad9c3fcd5e72ec9219c5206a",
.hash = "1220998444347b7a7f9535b12f00ceb87bd33499185ad0eabf4f3c10182715e50bb2",
},
.scripty = .{
.url = "git+https://github.com/kristoff-it/scripty#df8c11380f9e9bec34809f2242fb116d27cf39d6",
.hash = "122014e78d7c69d93595993b3231f3141368e22634b332b0b91a2fb73a8570f147a5",
},
.superhtml = .{
.url = "git+https://github.com/kristoff-it/superhtml#85a2c6116cc17a00bb7ecdd3e2d6ae84fa5530c4",
.hash = "1220dacd73752dd1a1950bbc8866036f8e06c69eb404cd033b04e2fad85d8cb115f1",
},
.ziggy = .{
.url = "git+https://github.com/kristoff-it/ziggy#c66f47bc632c66668d61fa06eda112b41d6e5130",
.hash = "1220115ff095a3c970cc90fce115294ba67d6fbc4927472dc856abc51e2a1a9364d7",
},
.mime = .{
.url = "git+https://github.com/andrewrk/mime.git#0b676643886b1e2f19cf11b4e15b028768708342",
Expand All @@ -14,17 +26,6 @@
.url = "git+https://github.com/karlseguin/websocket.zig.git#c77f87d0e6548865636eb9781106a8be72e5755a",
.hash = "12208720b772330f309cfb48957f4152ee0930b716837d0c1d07fee2dea2f4dc712e",
},
.frontmatter = .{
.path = "frontmatter",
},
.superhtml = .{
.url = "git+https://github.com/kristoff-it/superhtml#c9fe65c67ac9d4f1bf30e2f78d4a60bf42b0b26d",
.hash = "12206d96e7bb0e807def94910d0509252f2727b2096052eaf013842a4581a6531020",
},
.ziggy = .{
.url = "git+https://github.com/kristoff-it/ziggy#20c8088dbf4b22dc2f6e21d289cfb3dcc25c8cae",
.hash = "12206a0d6884ef31e3d4e47d5c9c6c4121b0a891258d6072ad7f5bac826803d29d36",
},
.zeit = .{
.url = "git+https://github.com/rockorager/zeit#02b347da743098f1bf8a88e590d38011b188ab51",
.hash = "1220478f0d836049cef3e203e665103c0c280b87d3c74b50c8b79c4054a6624498f9",
Expand Down
Loading

0 comments on commit 9141698

Please sign in to comment.