2525local dt = require " darktable"
2626local df = require " lib/dtutils.file"
2727
28+ local PS <const> = dt .configuration .running_os == " windows" and " \\ " or " /"
29+
2830local temp = dt .preferences .read (' web_gallery' , ' title' , ' string' )
2931if temp == nil then temp = ' Darktable gallery' end
3032
@@ -59,7 +61,7 @@ local gallery_widget = dt.new_widget("box")
5961}
6062
6163local function get_file_name (file )
62- return file :match (" [^/ ]*.$" )
64+ return file :match (" [^" .. PS .. " ]*.$" )
6365end
6466
6567function escape_js_string (str )
@@ -86,8 +88,8 @@ local function export_thumbnail(image, filename)
8688end
8789
8890local function write_image (image , dest_dir , filename )
89- df .file_move (filename , dest_dir .. " / images/ " .. get_file_name (filename ))
90- export_thumbnail (image , dest_dir .. " / thumbnails/ thumb_" .. get_file_name (filename ))
91+ df .file_move (filename , dest_dir .. PS .. " images" .. PS .. get_file_name (filename ))
92+ export_thumbnail (image , dest_dir .. PS .. " thumbnails" .. PS .. " thumb_" .. get_file_name (filename ))
9193end
9294
9395function exiftool_get_image_dimensions (filename )
@@ -123,18 +125,18 @@ local function fill_gallery_table(images_ordered, images_table, title, dest_dir,
123125 local job = dt .gui .create_job (_ (" exporting thumbnail images" ), true , stop_job )
124126
125127 for i , image in pairs (images_ordered ) do
126- local filename = images_table [image ]
127- dt .print (_ (" exporting thumbnail image " ).. index .. " /" .. #images_ordered )
128+ local filename = df . sanitize_filename ( images_table [image ])
129+ dt .print (_ (" export thumbnail image " ) .. index .. " /" .. # images_ordered )
128130 write_image (image , dest_dir , filename )
129131
130132 if exiftool then
131- width , height = exiftool_get_image_dimensions (dest_dir .. " / images/ " .. get_file_name (filename ))
133+ width , height = exiftool_get_image_dimensions (df . sanitize_filename ( dest_dir .. PS .. " images" .. PS .. get_file_name (filename ) ))
132134 else
133135 width = sizes [index ].width
134136 height = sizes [index ].height
135137 end
136138
137- local entry = { filename = " images/ " .. get_file_name (escape_js_string ( filename ) ),
139+ local entry = { filename = " images" .. PS .. get_file_name (filename ),
138140 width = width , height = height }
139141
140142 images [index ] = entry
@@ -170,7 +172,7 @@ local function write_javascript_file(gallery_table, dest_dir)
170172 dt .print (_ (" write JavaScript file" ))
171173 javascript_object = generate_javascript_gallery_object (gallery_table )
172174
173- local fileOut , errr = io.open (dest_dir .. " /js/ images.js" , ' w+' )
175+ local fileOut , errr = io.open (dest_dir .. PS .. " js " .. PS .. " images.js" , ' w+' )
174176 if fileOut then
175177 fileOut :write (javascript_object )
176178 else
@@ -180,29 +182,31 @@ local function write_javascript_file(gallery_table, dest_dir)
180182end
181183
182184local function copy_static_files (dest_dir )
183- gfsrc = dt .configuration .config_dir .. " /lua/data/website_gallery"
185+
186+ gfsrc = dt .configuration .config_dir .. PS .. " lua" .. PS .. " data" .. PS .. " website_gallery"
184187 local gfiles = {
185188 " index.html" ,
186- " css/gallery.css" ,
187- " css/modal.css" ,
188- " js/gallery.js" ,
189- " js/modal.js" ,
190- " js/fullscreen.js"
189+ " css" .. PS .. " gallery.css" ,
190+ " css" .. PS .. " modal.css" ,
191+ " css" .. PS .. " style.css" ,
192+ " js" .. PS .. " gallery.js" ,
193+ " js" .. PS .. " modal.js" ,
194+ " js" .. PS .. " fullscreen.js"
191195 }
192196
193197 dt .print (_ (" copy static gallery files" ))
194198 for _ , file in ipairs (gfiles ) do
195- df .file_copy (gfsrc .. " / " .. file , dest_dir .. " / " .. file )
199+ df .file_copy (gfsrc .. PS .. file , dest_dir .. PS .. file )
196200 end
197201end
198202
199203local function build_gallery (storage , images_table , extra_data )
200204 local dest_dir = dest_dir_widget .value
201- df .mkdir (dest_dir )
202- df .mkdir (dest_dir .. " / images" )
203- df .mkdir (dest_dir .. " / thumbnails" )
204- df .mkdir (dest_dir .. " / css" )
205- df .mkdir (dest_dir .. " / js" )
205+ df .mkdir (df . sanitize_filename ( dest_dir ) )
206+ df .mkdir (df . sanitize_filename ( dest_dir .. PS .. " images" ) )
207+ df .mkdir (df . sanitize_filename ( dest_dir .. PS .. " thumbnails" ) )
208+ df .mkdir (df . sanitize_filename ( dest_dir .. PS .. " css" ) )
209+ df .mkdir (df . sanitize_filename ( dest_dir .. PS .. " js" ) )
206210
207211 local images_ordered = extra_data [" images" ] -- process images in the correct order
208212 local sizes = extra_data [" sizes" ]
@@ -237,7 +241,7 @@ script_data.destroy = destroy
237241
238242local function show_status (storage , image , format , filename ,
239243 number , total , high_quality , extra_data )
240- dt .print (string.format (_ (" export image" ).. " %i/%i" , number , total ))
244+ dt .print (string.format (_ (" export image " ).. " %i/%i" , number , total ))
241245 aspect = image .aspect_ratio
242246 -- calculate the size of the exported image and store it in extra_data
243247 -- to make it available in the finalize function
0 commit comments