diff --git a/lib/neocities/cli.rb b/lib/neocities/cli.rb index 7c07efa..79f5877 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} ... ") @@ -435,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