commit 75fa66454d981a7379c9b8b0945854e3473a83fa
parent 990263470916bb4a1223aa31617130314a2aa9f1
Author: Hugo Soucy <hugo@soucy.cc>
Date: Mon, 3 Apr 2023 12:26:05 -0400
Set reset command only for HTML/XML files to preserve assets
Diffstat:
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/satelito/dirtree.lua b/satelito/dirtree.lua
@@ -35,6 +35,7 @@ end
-- Reset the public_html/ directory
-- Recursive function
function dirtree.reset(dir)
+ local mimetypes = require 'mimetypes'
local publicdir = _G.Satelito.publicdir
local _dir = dir
@@ -52,7 +53,9 @@ function dirtree.reset(dir)
entry = _dir..'/'..entry
type = lfs.attributes(entry).mode
- if type == 'file' then
+ if type == 'file'
+ and (mimetypes.guess(entry) == 'text/html' or mimetypes.guess(entry) == 'text/xml')
+ then
os.remove(entry)
print('❌ '.. entry)
elseif type == 'directory' then
diff --git a/satelito/init.lua b/satelito/init.lua
@@ -38,7 +38,7 @@ make:flag('-v --verbose', 'Displays in the terminal the source and destination o
exec = parser:command('exec', 'Execute a script from the site\'s bin directory.')
exec:argument 'bin name'
-- Set the reset command
-reset = parser:command('reset', 'Delete everything in the public_html directory.')
+reset = parser:command('reset', 'Delete HTML and XML files in the public_html directory.')
args = parser:parse()
@@ -185,8 +185,8 @@ if args['reset'] then
repeat
print('=> Reset ...')
- print('=> Are you sure you want to delete the contents of the "'..publicdir..'" directory?')
- print('=> Please answer with yes or no ...')
+ print('=> Are you sure you want to delete HTML and XML files in the "'..publicdir..'" folder?')
+ print('=> Please answer with "Yes" or "No" ...')
io.flush()
yes_or_no = string.lower(tostring(io.read()))