From 145495961052b5a29f663b007d93e38c4858c4b1 Mon Sep 17 00:00:00 2001 From: wayword Date: Sat, 13 Jul 2024 09:21:04 -0500 Subject: [PATCH 1/3] Allow specifying preview file --- lib/neocities/cli.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/neocities/cli.rb b/lib/neocities/cli.rb index 7c07efa..ebbb5cc 100644 --- a/lib/neocities/cli.rb +++ b/lib/neocities/cli.rb @@ -189,12 +189,14 @@ def push @excluded_files = [] @dry_run = false @prune = false + @preview_file = nil loop do case @subargs[0] when '--no-gitignore' then @subargs.shift; @no_gitignore = true when '-e' then @subargs.shift; @excluded_files.push(@subargs.shift) when '--dry-run' then @subargs.shift; @dry_run = true when '--prune' then @subargs.shift; @prune = true + when '--preview-file' then @subargs.shift; @preview_file = @subargs.shift when /^-/ then puts(@pastel.red.bold("Unknown option: #{@subargs[0].inspect}")); display_push_help_and_exit else break end @@ -212,7 +214,7 @@ def push end if !root_path.directory? - display_response result: 'error', message: 'provided path is not a directory' + display_response result: 'error', message: "provided path #{root_path} is not a directory" display_push_help_and_exit end @@ -267,6 +269,22 @@ def push paths.collect! { |path| Pathname path } + if @preview_file + preview_file_path = Pathname @preview_file + if !preview_file_path.file? + display_response result: 'error', message: "preview file #{@preview_file} does not exist or is not a regular file" + display_push_help_and_exit + elsif !paths.any? { |path| Pathname(path).cleanpath == preview_file_path.cleanpath } + display_response result: 'error', message: "preview file #{@preview_file} is ignored" + display_push_help_and_exit + end + + # The file used for preview is the first file that is uploaded in a SiteChange + # Ensure the preview file is uploaded first to make sure it is the preview + paths.reject! { |p| p.cleanpath == preview_file_path.cleanpath } + paths.unshift(preview_file_path) + end + paths.each do |path| next if path.directory? print @pastel.bold("Uploading #{path} ... ") From c7139375d18e177145957f2a660320bcaf331484 Mon Sep 17 00:00:00 2001 From: wayword Date: Sat, 13 Jul 2024 21:04:03 -0500 Subject: [PATCH 2/3] Update command help with example usage --- lib/neocities/cli.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/neocities/cli.rb b/lib/neocities/cli.rb index ebbb5cc..ecae6ca 100644 --- a/lib/neocities/cli.rb +++ b/lib/neocities/cli.rb @@ -453,6 +453,8 @@ def display_push_help_and_exit #{@pastel.green '$ neocities push --prune .'} Delete site files not in dir (be careful!) + #{@pastel.green '$ neocities push --preview-file index.html'} Use index.html as the main preview image in activity feed entries + HERE exit end From d84f09c936b338828488366531951104c47f1d39 Mon Sep 17 00:00:00 2001 From: wayword Date: Sat, 13 Jul 2024 21:10:12 -0500 Subject: [PATCH 3/3] add path to help page example --- lib/neocities/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neocities/cli.rb b/lib/neocities/cli.rb index ecae6ca..79f5877 100644 --- a/lib/neocities/cli.rb +++ b/lib/neocities/cli.rb @@ -453,7 +453,7 @@ def display_push_help_and_exit #{@pastel.green '$ neocities push --prune .'} Delete site files not in dir (be careful!) - #{@pastel.green '$ neocities push --preview-file index.html'} Use index.html as the main preview image in activity feed entries + #{@pastel.green '$ neocities push --preview-file index.html .'} Use index.html as the main preview image in activity feed entries HERE exit