Skip to content

Commit d5a84b6

Browse files
committed
compare-screenshots: support page paths in worktree arguments
Allow specifying a specific page to navigate to when using a worktree by appending a colon and the page path, e.g. /path/to/worktree:/docs/git-config Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent fa8e6bc commit d5a84b6

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

script/compare-screenshots.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Usage:
88
99
Arguments can be URLs or paths to git-scm.com worktrees. When a worktree
1010
path is given, Hugo is run to build the site and a local server is started.
11+
Use worktree:/path/to/page to navigate to a specific page.
1112
1213
Options:
1314
--dark Emulate dark mode (prefers-color-scheme: dark)
@@ -17,6 +18,7 @@ Options:
1718
Examples:
1819
node script/compare-screenshots.js https://git-scm.com http://localhost:5000
1920
node script/compare-screenshots.js https://git-scm.com /path/to/worktree
21+
node script/compare-screenshots.js https://git-scm.com/docs/git-config /path/to/worktree:/docs/git-config
2022
node script/compare-screenshots.js --dark https://git-scm.com http://localhost:5000
2123
node script/compare-screenshots.js --clip=1280x720+0+0 https://git-scm.com http://localhost:5000`;
2224

@@ -25,13 +27,18 @@ const { spawn, execSync } = require('child_process');
2527
const fs = require('fs');
2628
const path = require('path');
2729

28-
function isWorktree(arg) {
30+
function getWorktreeInfo(arg) {
2931
if (arg.startsWith('http://') || arg.startsWith('https://')) return false;
32+
const colonIndex = arg.indexOf(':');
33+
const worktreePath = colonIndex === -1 ? arg : arg.slice(0, colonIndex);
34+
const pagePath = colonIndex === -1 ? '' : arg.slice(colonIndex + 1).replace(/^\/+/, '');
3035
try {
31-
return fs.statSync(path.join(arg, 'hugo.yml')).isFile();
36+
if (fs.statSync(path.join(worktreePath, 'hugo.yml')).isFile()) {
37+
return { worktreePath, pagePath };
38+
}
3239
} catch {
33-
return false;
3440
}
41+
return false;
3542
}
3643

3744
async function startServer(worktreePath, port) {
@@ -128,9 +135,10 @@ async function main() {
128135
let server;
129136
let url = urlOrWorktree;
130137

131-
if (isWorktree(urlOrWorktree)) {
132-
server = await startServer(urlOrWorktree, 5000);
133-
url = 'http://localhost:5000/';
138+
const worktreeInfo = getWorktreeInfo(urlOrWorktree);
139+
if (worktreeInfo) {
140+
server = await startServer(worktreeInfo.worktreePath, 5000);
141+
url = `http://localhost:5000/${worktreeInfo.pagePath}`;
134142
}
135143

136144
try {

0 commit comments

Comments
 (0)