From 4f17754f4ca2995a0ec119df8175e328f2ecefd5 Mon Sep 17 00:00:00 2001 From: ewin Date: Thu, 4 Sep 2025 23:05:54 -0400 Subject: [PATCH] allow custom diff header labels --- lib/util/diff.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/util/diff.js b/lib/util/diff.js index d2e2991..c30fa7a 100644 --- a/lib/util/diff.js +++ b/lib/util/diff.js @@ -13,16 +13,25 @@ const toBase64 = str => Buffer.from(str, 'utf-8').toString('base64'); * terrible terrible terrible string diff helper for debugging * @param {string} a * @param {string} b + * @param {object} page Page object from the API, used to generate diff labels */ -export function diff (a, b) { +export function diff (a, b, page) { + let labels = null; + if (page) { // generate diff labels based on + labels = [ + `${page.title} (${page.revid ? `revision ${page.revid}` : 'current revision'}${page.timestamp ? ` from ${page.timestamp}` : ''})`, + `${page.title} (pending edit)`, + ]; + } // base64 input strings before passing to shell to avoid escaping issues // https://stackoverflow.com/a/60221847 - // use tail to cut off useless file info lines - execSync(String.raw`bash <<- EOF + // use tail to cut off file info lines and re-add with fake filenames/dates + // this function is so extra now holy shit + execSync(String.raw`bash <<- 'EOF' diff --color=always -u \ - <(echo "${toBase64(a)}" | base64 -d) \ - <(echo "${toBase64(b)}" | base64 -d) \ - | tail -n +3 + ${labels ? `--label="$(echo '${toBase64(labels[0])}' | base64 -d)" ` : ''}<(echo '${toBase64(a)}' | base64 -d) \ + ${labels ? `--label="$(echo '${toBase64(labels[1])}' | base64 -d)" ` : ''}<(echo '${toBase64(b)}' | base64 -d) \ + ${labels ? `|| true` : `| tail -n +3` /* cut off header if no labels */} EOF`, { // display result directly in terminal stdio: 'inherit',