" : canonical(v));
+ return `${path}: js=${show(a)} py=${show(b)}`;
+}
+
+/** A one-line description of how a port's result differs from the JS one. */
+export function describeDiff(port, j, p) {
+ if (!p) return `${port.name} produced no output`;
+ if (j.error || p.error) return `js ${j.error ?? "ok"} | ${port.key} ${p.error ?? "ok"}`;
+ return firstDiff(j.ok, p.ok).replace(" py=", ` ${port.key}=`);
+}
diff --git a/site/astro.config.mjs b/site/astro.config.mjs
index db8cf65..ed4b4c2 100644
--- a/site/astro.config.mjs
+++ b/site/astro.config.mjs
@@ -20,7 +20,7 @@ export default defineConfig({
title: "trackparse",
disable404Route: true,
description:
- "Turn messy track names into structured data: artists, features, remixes, versions and the noise around them. JavaScript, Python and Rust, one spec.",
+ "Turn messy track names into structured data: artists, features, remixes, versions and the noise around them. JavaScript, Python, Rust and Go, one spec.",
logo: { light: "./src/assets/logo-light.svg", dark: "./src/assets/logo-dark.svg", replacesTitle: false },
favicon: "/favicon.svg",
social: [
@@ -31,6 +31,14 @@ export default defineConfig({
customCss: ["./src/styles/custom.css"],
components: { SocialIcons: "./src/components/SocialIcons.astro" },
head: [
+ // With site data blocked, reading localStorage or sessionStorage throws, and Starlight's
+ // theme, tabs and sidebar scripts stop there. An in-memory store keeps them working for
+ // the visit. It runs before Starlight's own head scripts.
+ {
+ tag: "script",
+ content:
+ 'for(const n of["localStorage","sessionStorage"]){try{window[n].getItem("tp")}catch{const m=new Map();const s={getItem:k=>m.has(String(k))?m.get(String(k)):null,setItem:(k,v)=>{m.set(String(k),String(v))},removeItem:k=>{m.delete(String(k))},clear:()=>m.clear(),key:i=>[...m.keys()][i]??null,get length(){return m.size}};try{Object.defineProperty(window,n,{value:s,configurable:true})}catch{}}}',
+ },
{ tag: "meta", attrs: { property: "og:image", content: "https://4matic.github.io/trackparse/og.png" } },
{ tag: "meta", attrs: { property: "og:image:width", content: "1200" } },
{ tag: "meta", attrs: { property: "og:image:height", content: "630" } },
diff --git a/site/src/components/Features.astro b/site/src/components/Features.astro
index 4c661ce..f49f5fd 100644
--- a/site/src/components/Features.astro
+++ b/site/src/components/Features.astro
@@ -55,6 +55,16 @@ const { items } = Astro.props as { items: Item[] };
line-height: 1.6;
color: var(--sl-color-gray-3);
}
+ p :global(a) {
+ color: var(--sl-color-gray-2);
+ text-decoration: underline;
+ text-decoration-color: var(--tp-border-strong);
+ text-underline-offset: 0.2em;
+ }
+ p :global(a:hover) {
+ color: var(--sl-color-white);
+ text-decoration-color: var(--sl-color-accent);
+ }
p :global(code) {
font: 0.86em var(--sl-font-mono);
color: var(--sl-color-gray-2);
diff --git a/site/src/components/HeroDemo.astro b/site/src/components/HeroDemo.astro
index 365805f..b9d3e37 100644
--- a/site/src/components/HeroDemo.astro
+++ b/site/src/components/HeroDemo.astro
@@ -48,7 +48,7 @@ const playground = `${base}/playground/`;
diff --git a/site/src/components/Install.astro b/site/src/components/Install.astro
index 20540ba..d4c6920 100644
--- a/site/src/components/Install.astro
+++ b/site/src/components/Install.astro
@@ -1,5 +1,5 @@
---
-// One install line under the hero, switchable between npm, pip and cargo, with a copy button.
+// One install line under the hero, switchable between npm, pip, cargo and go, with a copy button.
// The switch shares its choice with the docs' language tabs and the playground (lib/lang.ts).
import Check from "@lucide/astro/icons/check";
import Copy from "@lucide/astro/icons/copy";
@@ -9,6 +9,7 @@ const pms = [
{ lang: "js", label: "npm" },
{ lang: "py", label: "pip" },
{ lang: "rs", label: "cargo" },
+ { lang: "go", label: "go" },
] as const;
---
@@ -27,8 +28,9 @@ const pms = [
- Published on npm, PyPI and{" "}
- crates.io. The Rust API docs are on docs.rs.
+ Published on npm, PyPI,{" "}
+ crates.io and the Go module proxy. The Rust API docs are on{" "}
+ docs.rs, the Go API docs on pkg.go.dev.
@@ -115,7 +117,7 @@ const pms = [
color: var(--sl-color-white);
text-decoration-color: var(--sl-color-accent);
}
- /* Three package managers and a command don't fit one row on a phone: the switch gets its own. */
+ /* Four package managers and a command don't fit one row on a phone: the switch gets its own. */
@media (max-width: 26rem) {
.install {
flex-wrap: wrap;
diff --git a/site/src/components/Playground.astro b/site/src/components/Playground.astro
index 4ad857a..2b5832d 100644
--- a/site/src/components/Playground.astro
+++ b/site/src/components/Playground.astro
@@ -189,6 +189,7 @@ const listExamples: { label: string; title: string; text: string }[] = [
+
@@ -277,6 +278,7 @@ const listExamples: { label: string; title: string; text: string }[] = [
+
@@ -407,6 +409,10 @@ const listExamples: { label: string; title: string; text: string }[] = [
.pg-doc {
font-size: 0.78rem;
}
+ /* Generated Go is indented with tabs, as gofmt writes it. */
+ .tp-code {
+ tab-size: 4;
+ }
.pg-foot {
display: flex;
flex-wrap: wrap;
@@ -419,7 +425,8 @@ const listExamples: { label: string; title: string; text: string }[] = [
background: var(--tp-code-bg);
padding: 0.1em 0.35em;
border-radius: 4px;
- white-space: nowrap;
+ /* The go get line is longer than a phone is wide: it may break anywhere. */
+ overflow-wrap: anywhere;
}
.pg-install {
display: flex;
@@ -750,6 +757,31 @@ const listExamples: { label: string; title: string; text: string }[] = [
}
// ---- Rust literals for the generated code -------------------------------------------------
+ /** Control, invisible and bidi characters, written as escapes in the generated literals. */
+ function invisible(cp: number): boolean {
+ return (
+ cp < 0x20 ||
+ (cp >= 0x7f && cp <= 0x9f) ||
+ cp === 0xad ||
+ cp === 0x34f ||
+ cp === 0x61c ||
+ cp === 0x180e ||
+ (cp >= 0x200b && cp <= 0x200f) ||
+ (cp >= 0x2028 && cp <= 0x202e) ||
+ (cp >= 0x2060 && cp <= 0x206f) ||
+ cp === 0xfeff ||
+ (cp >= 0xfff9 && cp <= 0xfffb)
+ );
+ }
+ /** A JavaScript or Python string literal: JSON, plus `\uXXXX` for invisible characters. */
+ function jsStr(s: string): string {
+ let out = "";
+ for (const ch of JSON.stringify(s)) {
+ const cp = ch.codePointAt(0)!;
+ out += cp >= 0x7f && invisible(cp) ? `\\u${cp.toString(16).padStart(4, "0")}` : ch;
+ }
+ return out;
+ }
/** A Rust string literal. Control, invisible and bidi characters are written as `\u{…}`. */
function rsStr(s: string): string {
let out = '"';
@@ -761,7 +793,7 @@ const listExamples: { label: string; title: string; text: string }[] = [
else if (ch === "\t") out += "\\t";
// A lone surrogate cannot be in a Rust string: U+FFFD, as a lossy conversion would give.
else if (cp >= 0xd800 && cp <= 0xdfff) out += "\\u{fffd}";
- else if (cp < 0x20 || (cp >= 0x7f && cp <= 0x9f) || (cp >= 0x200b && cp <= 0x200f) || (cp >= 0x2028 && cp <= 0x202e) || (cp >= 0x2066 && cp <= 0x2069) || cp === 0xfeff)
+ else if (invisible(cp))
out += `\\u{${cp.toString(16)}}`;
else out += ch;
}
@@ -779,7 +811,85 @@ const listExamples: { label: string; title: string; text: string }[] = [
function rsUse(path: string, names: string[]): string {
const lower = (n: string) => n[0] === n[0].toLowerCase();
const sorted = [...names.filter(lower).sort(), ...names.filter((n) => !lower(n)).sort()];
- return `use ${path}::${sorted.length === 1 ? sorted[0] : `{${sorted.join(", ")}}`};`;
+ const line = `use ${path}::${sorted.length === 1 ? sorted[0] : `{${sorted.join(", ")}}`};`;
+ if (line.length <= 100) return line;
+ // Too long: the names fill lines of at most 100 columns inside braces.
+ const rows: string[] = [];
+ for (const n of sorted) {
+ const last = rows.length - 1;
+ if (last >= 0 && `${rows[last]} ${n},`.length <= 100) rows[last] += ` ${n},`;
+ else rows.push(` ${n},`);
+ }
+ return `use ${path}::{\n${rows.join("\n")}\n};`;
+ }
+ // rustfmt's main width rules, so the common programs come out as `cargo fmt` writes them.
+ /** Columns a line takes: wide characters (emoji, CJK) count two. */
+ function rsWidth(s: string): number {
+ let w = 0;
+ for (const ch of s) {
+ const cp = ch.codePointAt(0)!;
+ w += (cp >= 0x1100 && cp <= 0x115f) || (cp >= 0x2e80 && cp <= 0xa4cf) || (cp >= 0xac00 && cp <= 0xd7a3) || (cp >= 0xf900 && cp <= 0xfaff) || (cp >= 0xfe30 && cp <= 0xfe4f) || (cp >= 0xff00 && cp <= 0xff60) || (cp >= 0xffe0 && cp <= 0xffe6) || (cp >= 0x1f300 && cp <= 0x1faff) || cp >= 0x20000 ? 2 : 1;
+ }
+ return w;
+ }
+ /** `let x = Root::new().a().b();`: a chain wider than 60 columns gets one call per line. */
+ function rsChain(lhs: string, root: string, calls: string[], indent = " "): string {
+ const chain = root + calls.join("");
+ if (calls.length < 2 || rsWidth(chain) <= 60) return `${lhs}${chain};`;
+ return `${lhs}${root}\n${calls.map((c) => `${indent} ${c}`).join("\n")};`;
+ }
+ /** `let x = f(a, b);`: arguments wider than 60 columns go one per line, if each then fits. */
+ function rsCall(lhs: string, fn: string, args: string[], indent = " "): string {
+ const flat = `${lhs}${fn}(${args.join(", ")});`;
+ const fits = args.every((a) => indent.length + 4 + rsWidth(a) + 1 <= 100);
+ if (rsWidth(args.join(", ")) <= 60 || !fits) return flat;
+ return `${lhs}${fn}(\n${args.map((a) => `${indent} ${a},`).join("\n")}\n${indent});`;
+ }
+
+ // ---- Go literals for the generated code ---------------------------------------------------
+ /** A Go string literal. Control, invisible and bidi characters are written as escapes. */
+ function goStr(s: string): string {
+ let out = '"';
+ for (const ch of s) {
+ const cp = ch.codePointAt(0)!;
+ if (ch === '"' || ch === "\\") out += `\\${ch}`;
+ else if (ch === "\n") out += "\\n";
+ else if (ch === "\r") out += "\\r";
+ else if (ch === "\t") out += "\\t";
+ // A Go string cannot spell a lone surrogate: U+FFFD, as the module reads invalid UTF-8.
+ else if (cp >= 0xd800 && cp <= 0xdfff) out += "\\ufffd";
+ else if (invisible(cp))
+ out += `\\u${cp.toString(16).padStart(4, "0")}`;
+ else out += ch;
+ }
+ return `${out}"`;
+ }
+ /** A float64 constant: `45`, `7.5`, `1e+21`; `math.Inf(1)` and `math.NaN()` need the math import. */
+ function goNum(n: number): string {
+ if (!Number.isFinite(n)) return Number.isNaN(n) ? "math.NaN()" : n > 0 ? "math.Inf(1)" : "math.Inf(-1)";
+ return String(n);
+ }
+ /** A float64 value for trackparse.Ptr: `3600.0`, `7.5`, so the type parameter is float64, not int. */
+ function goFloat(n: number): string {
+ const s = goNum(n);
+ return /^-?\d+$/.test(s) ? `${s}.0` : s;
+ }
+ /** The exported constant of an option value: `youtube` → `ModeYouTube`, `never` → `SplitAndNever`. */
+ function goConst(prefix: string, v: unknown): string {
+ const name = String(v) === "youtube" ? "YouTube" : variant(v);
+ return `trackparse.${prefix}${name}`;
+ }
+ /** A struct literal as gofmt writes it: one line for one field, else one aligned field per line. */
+ function goStruct(type: string, fields: [string, string][], indent: string): string {
+ if (fields.length === 0) return `trackparse.${type}{}`;
+ if (fields.length === 1) return `trackparse.${type}{${fields[0][0]}: ${fields[0][1]}}`;
+ const w = Math.max(...fields.map(([k]) => k.length));
+ return `trackparse.${type}{\n${fields.map(([k, v]) => `${indent}\t${`${k}:`.padEnd(w + 2)}${v},`).join("\n")}\n${indent}}`;
+ }
+ /** A Go program around `body` (lines, one tab of indentation added). */
+ function goMain(body: string[], extra: string[] = []): string {
+ const std = ['"fmt"', ...extra].sort();
+ return `package main\n\nimport (\n${std.map((x) => `\t${x}`).join("\n")}\n\n\t"github.com/4matic/trackparse/go"\n)\n\nfunc main() {\n${body.map((l) => (l ? `\t${l}` : "")).join("\n")}\n}`;
}
function options(): ParseOptions {
@@ -793,7 +903,7 @@ const listExamples: { label: string; title: string; text: string }[] = [
}
function code(s: string, o: ParseOptions, f: Record): string {
- const q = (v: string) => JSON.stringify(v);
+ const q = jsStr;
if (lang === "js") {
// JS literal: unquoted keys, spaces after commas and colons.
const js = (v: unknown): string =>
@@ -801,7 +911,9 @@ const listExamples: { label: string; title: string; text: string }[] = [
? `[${v.map(js).join(", ")}]`
: v && typeof v === "object"
? `{ ${Object.entries(v).map(([k, x]) => `${k}: ${js(x)}`).join(", ")} }`
- : JSON.stringify(v);
+ : typeof v === "string"
+ ? jsStr(v)
+ : JSON.stringify(v);
const opts = Object.keys(o).length ? `, ${js(o)}` : "";
const fopts = Object.keys(f).length ? `, ${js(f)}` : "";
return `import { parse, format } from "trackparse";\n\nconst track = parse(${q(s)}${opts});\nformat(track${fopts});`;
@@ -809,40 +921,61 @@ const listExamples: { label: string; title: string; text: string }[] = [
if (lang === "rs") {
// A whole program: options are builders, and the `_with` functions take them by reference.
const names: string[] = [];
- let popts = "";
- if (o.mode) popts += `.mode(ModeOption::${variant(o.mode)})`;
- if (o.knownArtists) popts += `.known_artists([${o.knownArtists.map(rsStr).join(", ")}])`;
- if (o.uploader) popts += `.uploader(${rsStr(o.uploader)})`;
- if (o.splitAnd) popts += `.split_and(SplitAnd::${variant(o.splitAnd)})`;
+ const popts: string[] = [];
+ if (o.mode) popts.push(`.mode(ModeOption::${variant(o.mode)})`);
+ if (o.knownArtists) popts.push(`.known_artists([${o.knownArtists.map(rsStr).join(", ")}])`);
+ if (o.uploader) popts.push(`.uploader(${rsStr(o.uploader)})`);
+ if (o.splitAnd) popts.push(`.split_and(SplitAnd::${variant(o.splitAnd)})`);
if (o.mode) names.push("ModeOption");
if (o.splitAnd) names.push("SplitAnd");
- let fopts = "";
- if (f.feat) fopts += `.feat(FeatPlacement::${variant(f.feat)})`;
- if (f.joiners) fopts += `.joiners(JoinerStyle::${variant(f.joiners)})`;
- if (f.versions) fopts += `.versions(VersionsOption::${variant(f.versions)})`;
+ const fopts: string[] = [];
+ if (f.feat) fopts.push(`.feat(FeatPlacement::${variant(f.feat)})`);
+ if (f.joiners) fopts.push(`.joiners(JoinerStyle::${variant(f.joiners)})`);
+ if (f.versions) fopts.push(`.versions(VersionsOption::${variant(f.versions)})`);
if (f.feat) names.push("FeatPlacement");
if (f.joiners) names.push("JoinerStyle");
if (f.versions) names.push("VersionsOption");
const body: string[] = [];
- if (popts) {
+ if (popts.length) {
names.push("parse_with", "ParseOptions");
- body.push(`let options = ParseOptions::new()${popts};`, `let track = parse_with(${rsStr(s)}, &options);`);
+ body.push(rsChain("let options = ", "ParseOptions::new()", popts), rsCall("let track = ", "parse_with", [rsStr(s), "&options"]));
} else {
names.push("parse");
body.push(`let track = parse(${rsStr(s)});`);
}
- if (fopts) {
+ if (fopts.length) {
names.push("format_track_with", "FormatOptions");
- body.push(`let format = FormatOptions::new()${fopts};`, 'println!("{}", format_track_with(&track, &format));');
+ body.push(rsChain("let format = ", "FormatOptions::new()", fopts), 'println!("{}", format_track_with(&track, &format));');
} else {
names.push("format_track");
body.push('println!("{}", format_track(&track));');
}
return `${rsUse("trackparse", names)}\n\nfn main() {\n${body.map((l) => ` ${l}`).join("\n")}\n}`;
}
+ if (lang === "go") {
+ // A whole program: options are structs whose zero value means the default.
+ const popts: [string, string][] = [];
+ if (o.mode) popts.push(["Mode", goConst("Mode", o.mode)]);
+ if (o.uploader) popts.push(["Uploader", goStr(o.uploader)]);
+ if (o.knownArtists) popts.push(["KnownArtists", `[]string{${o.knownArtists.map(goStr).join(", ")}}`]);
+ if (o.splitAnd) popts.push(["SplitAnd", goConst("SplitAnd", o.splitAnd)]);
+ const fopts: [string, string][] = [];
+ if (f.feat) fopts.push(["Feat", goConst("Feat", f.feat)]);
+ if (f.joiners) fopts.push(["Joiners", goConst("Joiners", f.joiners)]);
+ if (f.versions) fopts.push(["Versions", goConst("Versions", f.versions)]);
+ const body = [
+ popts.length
+ ? `track := trackparse.ParseWith(${goStr(s)}, ${goStruct("ParseOptions", popts, "\t")})`
+ : `track := trackparse.Parse(${goStr(s)})`,
+ fopts.length
+ ? `fmt.Println(trackparse.FormatWith(track, ${goStruct("FormatOptions", fopts, "\t")}))`
+ : "fmt.Println(trackparse.Format(track))",
+ ];
+ return goMain(body);
+ }
const snake = (k: string) => k.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
const py = (v: unknown): string =>
- Array.isArray(v) ? `[${v.map(py).join(", ")}]` : typeof v === "boolean" ? (v ? "True" : "False") : JSON.stringify(v);
+ Array.isArray(v) ? `[${v.map(py).join(", ")}]` : typeof v === "boolean" ? (v ? "True" : "False") : typeof v === "string" ? jsStr(v) : JSON.stringify(v);
const kw = (obj: Record) =>
Object.entries(obj).map(([k, v]) => `, ${snake(k)}=${py(v)}`).join("");
return `from trackparse import format_track, parse\n\ntrack = parse(${q(s)}${kw(o as Record)})\nformat_track(track${kw(f)})`;
@@ -992,6 +1125,8 @@ const listExamples: { label: string; title: string; text: string }[] = [
return `${h ? `${h}:` : ""}${String(m).padStart(h ? 2 : 1, "0")}:${String(sec).padStart(2, "0")}`;
}
+ /** "Shift by": an empty or unreadable box is 0, in the button and in the generated code. */
+ const shiftSeconds = () => Number(($("tl-shift") as HTMLInputElement).value) || 0;
const lineCount = () => tl.value.split(/\r\n|\r|\n/).length;
/** "from line", kept between 1 and the last line. */
function shiftFrom(): number {
@@ -1003,9 +1138,9 @@ const listExamples: { label: string; title: string; text: string }[] = [
type View = "table" | "json" | "code";
let view: View = "table";
- /** JS / Python / Rust for the current text, options and edit inputs. */
+ /** JS / Python / Rust / Go for the current text, options and edit inputs. */
function listCode(text: string, list: Tracklist): string {
- const q = (v: string) => JSON.stringify(v);
+ const q = jsStr;
const lines = text.split("\n");
// Lists without CR line endings are written one line per row; anything else as one string.
const literal = (indent: string, open: string, close: string) =>
@@ -1014,7 +1149,7 @@ const listExamples: { label: string; title: string; text: string }[] = [
: `${open}\n${lines.map((l) => `${indent}${q(l)},`).join("\n")}\n${close}`;
const { audioSeconds, knownArtists } = listOptions();
const hasOptions = audioSeconds !== undefined || knownArtists !== undefined;
- const seconds = Number(($("tl-shift") as HTMLInputElement).value) || 0;
+ const seconds = shiftSeconds();
const from = shiftFrom();
const fix = list.warnings.find((w) => w.suggestion)?.suggestion;
if (lang === "js") {
@@ -1042,25 +1177,62 @@ const listExamples: { label: string; title: string; text: string }[] = [
const t = joined ? "&text" : "text";
const names = ["apply_edits", "Edit", hasOptions ? "parse_tracklist_with" : "parse_tracklist"];
if (hasOptions) names.push("TracklistOptions");
- let rsOpts = "";
- if (audioSeconds !== undefined) rsOpts += `.audio_seconds(${rsNum(audioSeconds)})`;
- if (knownArtists) rsOpts += `.known_artists([${knownArtists.map(rsStr).join(", ")}])`;
+ const rsOpts: string[] = [];
+ if (audioSeconds !== undefined) rsOpts.push(`.audio_seconds(${rsNum(audioSeconds)})`);
+ if (knownArtists) rsOpts.push(`.known_artists([${knownArtists.map(rsStr).join(", ")}])`);
+ // rustfmt keeps an array on one line when it is at most 60 columns wide.
+ const items = lines.map(rsStr);
+ const array = `[${items.join(", ")}]`;
const body = [
- joined ? `let text = [\n${lines.map((l) => ` ${rsStr(l)},`).join("\n")}\n ]\n .join("\\n");` : `let text = ${rsStr(text)};`,
+ !joined
+ ? `let text = ${rsStr(text)};`
+ : rsWidth(array) <= 60
+ ? `let text = ${array}.join("\\n");`
+ : `let text = [\n${items.map((l) => ` ${l},`).join("\n")}\n ]\n .join("\\n");`,
"",
hasOptions
- ? `let options = TracklistOptions::new()${rsOpts};\n let list = parse_tracklist_with(${t}, &options);`
+ ? `${rsChain("let options = ", "TracklistOptions::new()", rsOpts)}\n let list = parse_tracklist_with(${t}, &options);`
: `let list = parse_tracklist(${t});`,
- 'println!("{:#?}", list.entries); // one entry per line',
- 'println!("{:#?}", list.warnings); // the checks, with line numbers',
+ 'println!("{:#?}", list.entries); // one entry per line',
+ 'println!("{:#?}", list.warnings); // the checks, with line numbers',
"",
`let shifted = apply_edits(${t}, &[Edit::shift_from(${rsNum(seconds)}, ${from})]);`,
`let sorted = apply_edits(${t}, &[Edit::sort_by_time()]);`,
];
- if (fix) body.push(`let fixed = apply_edits(${t}, &[Edit::set_time(${fix.line}, ${rsNum(fix.seconds)})]); // the suggested fix`);
+ if (fix) body.push(`let fixed = apply_edits(${t}, &[Edit::set_time(${fix.line}, ${rsNum(fix.seconds)})]); // the suggested fix`);
body.push(`println!("{}\\n\\n{}${fix ? "\\n\\n{}" : ""}", shifted.text, sorted.text${fix ? ", fixed.text" : ""});`);
return `${rsUse("trackparse::tracklist", names)}\n\nfn main() {\n${body.map((l) => (l ? ` ${l}` : "")).join("\n")}\n}`;
}
+ if (lang === "go") {
+ // A whole program. A list without CR line endings is a slice of lines joined with "\n".
+ const joined = !(text.includes("\r") || lines.length < 2);
+ const opts: [string, string][] = [];
+ // AudioSeconds is a *float64: nil is unknown, a pointer to 0 an audio of length 0.
+ if (audioSeconds !== undefined) opts.push(["AudioSeconds", `trackparse.Ptr(${goFloat(audioSeconds)})`]);
+ if (knownArtists) opts.push(["KnownArtists", `[]string{${knownArtists.map(goStr).join(", ")}}`]);
+ const nums = [audioSeconds ?? 0, seconds, fix?.seconds ?? 0];
+ const extra = ['"encoding/json"', '"os"'];
+ if (joined) extra.push('"strings"');
+ if (nums.some((n) => !Number.isFinite(n))) extra.push('"math"');
+ const body = [
+ joined ? `text := strings.Join([]string{\n${lines.map((l) => `\t${goStr(l)},`).join("\n")}\n}, "\\n")` : `text := ${goStr(text)}`,
+ "",
+ hasOptions
+ ? `list := trackparse.ParseTracklistWith(text, ${goStruct("TracklistOptions", opts, "")})`
+ : "list := trackparse.ParseTracklist(text)",
+ "enc := json.NewEncoder(os.Stdout)",
+ 'enc.SetIndent("", " ")',
+ "enc.SetEscapeHTML(false) // & < > as written, as JSON.stringify does",
+ "enc.Encode(list.Entries) // one entry per line",
+ "enc.Encode(list.Warnings) // the checks, with line numbers",
+ "",
+ `shifted := trackparse.ApplyEdits(text, []trackparse.Edit{trackparse.ShiftFrom(${goNum(seconds)}, ${from})})`,
+ "sorted := trackparse.ApplyEdits(text, []trackparse.Edit{trackparse.SortByTime()})",
+ ];
+ if (fix) body.push(`fixed := trackparse.ApplyEdits(text, []trackparse.Edit{trackparse.SetTime(${fix.line}, ${goNum(fix.seconds)})}) // the suggested fix`);
+ body.push(`fmt.Print(shifted.Text, "\\n\\n", sorted.Text${fix ? ', "\\n\\n", fixed.Text' : ""}, "\\n")`);
+ return goMain(body.flatMap((l) => l.split("\n")), extra);
+ }
const pyOpts =
(audioSeconds !== undefined ? `, audio_seconds=${audioSeconds}` : "") +
(knownArtists ? `, known_artists=[${knownArtists.map(q).join(", ")}]` : "");
@@ -1184,7 +1356,7 @@ const listExamples: { label: string; title: string; text: string }[] = [
audio.addEventListener("input", renderList);
tlKnown.addEventListener("input", renderList);
$("tl-do-shift").addEventListener("click", () => {
- const seconds = Number(($("tl-shift") as HTMLInputElement).value);
+ const seconds = shiftSeconds();
const from = shiftFrom();
edit([{ op: "shift", seconds, from }], `Shift ${seconds >= 0 ? "+" : ""}${seconds} s from line ${from}`);
});
diff --git a/site/src/components/SocialIcons.astro b/site/src/components/SocialIcons.astro
index 6083b9d..2f83e00 100644
--- a/site/src/components/SocialIcons.astro
+++ b/site/src/components/SocialIcons.astro
@@ -1,7 +1,7 @@
---
-// Starlight's social links (GitHub, npm) plus the other two registries. PyPI has no built-in
-// Starlight icon: its mark is from Simple Icons (CC0 1.0). crates.io has no mark of its own in
-// either set, so it gets the Rust file icon Starlight ships.
+// Starlight's social links (GitHub, npm) plus the other three registries. PyPI has no built-in
+// Starlight icon: its mark is from Simple Icons (CC0 1.0). crates.io and pkg.go.dev have no mark
+// of their own in either set, so they get the Rust and Go file icons Starlight ships.
import { Icon } from "@astrojs/starlight/components";
import Default from "@astrojs/starlight/components/SocialIcons.astro";
---
@@ -15,6 +15,10 @@ import Default from "@astrojs/starlight/components/SocialIcons.astro";
crates.io