Skip to content

Commit

Permalink
Build flags to generate website data, remove old website dir (#3012)
Browse files Browse the repository at this point in the history
This adds a default-false `-Demit-webdata` build option. This emits some
files we copy over to our website (in the future I'll automate this more
to make a PR or something).

This also removes the old `website/` folder, all of the content was
moved to the website repo which is more updated.
  • Loading branch information
mitchellh authored Dec 19, 2024
2 parents 34dca81 + d947fa3 commit e7ca135
Show file tree
Hide file tree
Showing 75 changed files with 165 additions and 10,676 deletions.
46 changes: 46 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ pub fn build(b: *std.Build) !void {
break :emit_docs path != null;
};

const emit_webdata = b.option(
bool,
"emit-webdata",
"Build the website data for the website.",
) orelse false;

const emit_xcframework = b.option(
bool,
"emit-xcframework",
Expand Down Expand Up @@ -588,6 +594,11 @@ pub fn build(b: *std.Build) !void {
b.getInstallStep().dependOn(&b.addInstallFile(placeholder, path).step);
}

// Web data
if (emit_webdata) {
try buildWebData(b, config);
}

// App (Linux)
if (target.result.os.tag == .linux and config.app_runtime != .none) {
// https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
Expand Down Expand Up @@ -1578,6 +1589,41 @@ fn buildDocumentation(
}
}

/// Generate the website reference data that we merge into the
/// official Ghostty website. This isn't meant to be part of any
/// actual build.
fn buildWebData(
b: *std.Build,
config: BuildConfig,
) !void {
const webgen_config = b.addExecutable(.{
.name = "webgen_config",
.root_source_file = b.path("src/main.zig"),
.target = b.host,
});
try addHelp(b, webgen_config, config);

{
const buildconfig = config: {
var copy = config;
copy.exe_entrypoint = .webgen_config;
break :config copy;
};

const options = b.addOptions();
try buildconfig.addOptions(options);
webgen_config.root_module.addOptions("build_options", options);
}

const webgen_config_step = b.addRunArtifact(webgen_config);
const webgen_config_out = webgen_config_step.captureStdOut();

b.getInstallStep().dependOn(&b.addInstallFile(
webgen_config_out,
"share/ghostty/webdata/config.mdx",
).step);
}

fn benchSteps(
b: *std.Build,
target: std.Build.ResolvedTarget,
Expand Down
109 changes: 109 additions & 0 deletions src/build/webgen/main_config.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const std = @import("std");
const Config = @import("../../config/Config.zig");
const help_strings = @import("help_strings");

pub fn main() !void {
const output = std.io.getStdOut().writer();
try genConfig(output);
}

pub fn genConfig(writer: anytype) !void {
// Write the header
try writer.writeAll(
\\---
\\title: Reference
\\description: Reference of all Ghostty configuration options.
\\---
\\
\\This is a reference of all Ghostty configuration options. These
\\options are ordered roughly by how common they are to be used
\\and grouped with related options. I recommend utilizing your
\\browser's search functionality to find the option you're looking
\\for.
\\
\\In the future, we'll have a more user-friendly way to view and
\\organize these options.
\\
\\
);

@setEvalBranchQuota(3000);
const fields = @typeInfo(Config).Struct.fields;
inline for (fields, 0..) |field, i| {
if (field.name[0] == '_') continue;
if (!@hasDecl(help_strings.Config, field.name)) continue;

// Write the field name.
try writer.writeAll("## `");
try writer.writeAll(field.name);
try writer.writeAll("`\n");

// For all subsequent fields with no docs, they are grouped
// with the previous field.
if (i + 1 < fields.len) {
inline for (fields[i + 1 ..]) |next_field| {
if (next_field.name[0] == '_') break;
if (@hasDecl(help_strings.Config, next_field.name)) break;

try writer.writeAll("## `");
try writer.writeAll(next_field.name);
try writer.writeAll("`\n");
}
}

// Newline after our headers
try writer.writeAll("\n");

var iter = std.mem.splitScalar(
u8,
@field(help_strings.Config, field.name),
'\n',
);

// We do some really rough markdown "parsing" here so that
// we can fix up some styles for what our website expects.
var block: ?enum {
/// Plaintext, do nothing.
text,

/// Code block, wrap in triple backticks. We use indented
/// code blocks in our comments but the website parser only
/// supports triple backticks.
code,
} = null;

while (iter.next()) |s| {
// Empty line resets our block
if (std.mem.eql(u8, s, "")) {
if (block) |v| switch (v) {
.text => {},
.code => try writer.writeAll("```\n"),
};
block = null;

try writer.writeAll("\n");
continue;
}

// If we don't have a block figure out our type.
if (block == null) {
if (std.mem.startsWith(u8, s, " ")) {
block = .code;
try writer.writeAll("```\n");
} else {
block = .text;
}
}

try writer.writeAll(switch (block.?) {
.text => s,
.code => if (std.mem.startsWith(u8, s, " "))
s[4..]
else
s,
});
try writer.writeAll("\n");
}
try writer.writeAll("\n");
}
}
1 change: 1 addition & 0 deletions src/build_config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub const ExeEntrypoint = enum {
helpgen,
mdgen_ghostty_1,
mdgen_ghostty_5,
webgen_config,
bench_parser,
bench_stream,
bench_codepoint_width,
Expand Down
16 changes: 8 additions & 8 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ const c = @cImport({
///
/// Valid values are:
///
/// * `legacy` - Use a legacy method to determine grapheme width, such as
/// wcswidth This maximizes compatibility with legacy programs but may result
/// in incorrect grapheme width for certain graphemes such as skin-tone
/// emoji, non-English characters, etc.
/// * `legacy` - Use a legacy method to determine grapheme width, such as
/// wcswidth This maximizes compatibility with legacy programs but may result
/// in incorrect grapheme width for certain graphemes such as skin-tone
/// emoji, non-English characters, etc.
///
/// This is called "legacy" and not something more specific because the
/// behavior is undefined and we want to retain the ability to modify it.
/// For example, we may or may not use libc `wcswidth` now or in the future.
/// This is called "legacy" and not something more specific because the
/// behavior is undefined and we want to retain the ability to modify it.
/// For example, we may or may not use libc `wcswidth` now or in the future.
///
/// * `unicode` - Use the Unicode standard to determine grapheme width.
/// * `unicode` - Use the Unicode standard to determine grapheme width.
///
/// If a running program explicitly enables terminal mode 2027, then `unicode`
/// width will be forced regardless of this configuration. When mode 2027 is
Expand Down
1 change: 1 addition & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const entrypoint = switch (build_config.exe_entrypoint) {
.helpgen => @import("helpgen.zig"),
.mdgen_ghostty_1 => @import("build/mdgen/main_ghostty_1.zig"),
.mdgen_ghostty_5 => @import("build/mdgen/main_ghostty_5.zig"),
.webgen_config => @import("build/webgen/main_config.zig"),
.bench_parser => @import("bench/parser.zig"),
.bench_stream => @import("bench/stream.zig"),
.bench_codepoint_width => @import("bench/codepoint-width.zig"),
Expand Down
3 changes: 0 additions & 3 deletions website/.eslintrc.json

This file was deleted.

35 changes: 0 additions & 35 deletions website/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion website/.prettierignore

This file was deleted.

48 changes: 0 additions & 48 deletions website/README.md

This file was deleted.

Binary file removed website/app/favicon.ico
Binary file not shown.
20 changes: 0 additions & 20 deletions website/app/globals.css

This file was deleted.

35 changes: 0 additions & 35 deletions website/app/layout.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions website/app/page.tsx

This file was deleted.

Loading

0 comments on commit e7ca135

Please sign in to comment.