commit 5b9008408682895bab1e8e5d4fa914c41eeb1798
parent fe5a95a12e1eab0ce5a11ec2c193e107a99aaf81
Author: Hugo Soucy <hs0ucy@h50ucy.local>
Date: Wed, 3 Oct 2018 06:43:23 -0400
Allow a site to be pass directly with arg
Diffstat:
M | ferron/site.lua | | | 120 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
1 file changed, 60 insertions(+), 60 deletions(-)
diff --git a/ferron/site.lua b/ferron/site.lua
@@ -8,87 +8,87 @@ local site = {}
Ferron.sites = path.currentdir() .. "/" .. config.paths.sites
function site.listsites()
- -- Create a simple array with the directory name of the sites
- local sites_list = {}
+ -- Create a simple array with the directory name of the sites
+ local sites_list = {}
- for s in path.each(Ferron.sites .. "*", "f", {delay = true; reverse = true;}) do
- if path.isdir(s) then
- sites_list[#sites_list+1] = s:match("^.+/(.+)$")
- end
- end
+ for s in path.each(Ferron.sites .. "*", "f", {delay = true; reverse = true;}) do
+ if path.isdir(s) then
+ sites_list[#sites_list+1] = s:match("^.+/(.+)$")
+ end
+ end
- return sites_list
+ return sites_list
end
function site.getsiteinfos(sitename)
- package.path = package.path .. ";sites/".. sitename .."/?.lua"
+ package.path = package.path .. ";sites/".. sitename .."/?.lua"
- local site_config = require "site-config"
- -- Create a table with the basic infos of the site
- local site_infos = {
- path = Ferron.sites .. sitename,
- siteconfig = site_config,
- pagestable = {},
- }
+ local site_config = require "site-config"
+ -- Create a table with the basic infos of the site
+ local site_infos = {
+ path = Ferron.sites .. sitename,
+ siteconfig = site_config,
+ pagestable = {},
+ }
- return site_infos
+ return site_infos
end
-function site.setsite()
- local sites_list = site.listsites()
- local whichsite = nil
+function site.setsite(name)
+ local sites_list = site.listsites()
+ local whichsite = nil
- if #sites_list > 1 then
- repeat
- io.write("For which website do you want to proceed? \n")
+ if #sites_list > 1 and not name then
+ repeat
+ io.write("For which website do you want to proceed? \n")
- for k, v in ipairs(sites_list) do
- io.write(k .. ") " .. v .. "\n")
- end
+ for k, v in ipairs(sites_list) do
+ io.write(k .. ") " .. v .. "\n")
+ end
- io.write("Please enter the number... \n")
- io.flush()
+ io.write("Please enter the number... \n")
+ io.flush()
- whichsite=io.read()
- until (tableutils.haskey(sites_list, tonumber(whichsite))) == true
- else
- whichsite = 1
- end
+ whichsite=io.read()
+ until (tableutils.haskey(sites_list, tonumber(whichsite))) == true
+ elseif not name then
+ whichsite = 1
+ end
- Ferron.site = site.getsiteinfos(sites_list[tonumber(whichsite)])
- Ferron.site.siteconfig.baseurl = (Ferron.devmode == true and Ferron.site.siteconfig.urldev or Ferron.site.siteconfig.url)
+ Ferron.site = site.getsiteinfos((name ~= nil and name or sites_list[tonumber(whichsite)]))
+ Ferron.site.siteconfig.baseurl = (Ferron.devmode == true and Ferron.site.siteconfig.urldev or Ferron.site.siteconfig.url)
- return Ferron.site
+ return Ferron.site
end
function site.makesite()
- local newsite = {
- domain = nil,
- name = nil,
- location = nil,
- config = nil,
- sample = Ferron.sites .. "ferron-ssg.tld",
- }
-
- io.write("How do you want names your new website? \n")
- io.write("Please enter that name below... \n")
- io.flush()
-
- newsite.name = io.read()
- newsite.location = Ferron.sites .. newsite.name
-
- path.copy(newsite.sample .. "/*", path.mkdir(newsite.location), {delay = true; recurse = true})
-
- if path.isdir(newsite.location) then
- return print("Your new website is ready to be cutomize here '" .. newsite.location .. "'!")
- else
- return print("!! Error, something went wrong !")
- end
+ local newsite = {
+ domain = nil,
+ name = nil,
+ location = nil,
+ config = nil,
+ sample = Ferron.sites .. "ferron-ssg.tld",
+ }
+
+ io.write("How do you want names your new website? \n")
+ io.write("Please enter that name below... \n")
+ io.flush()
+
+ newsite.name = io.read()
+ newsite.location = Ferron.sites .. newsite.name
+
+ path.copy(newsite.sample .. "/*", path.mkdir(newsite.location), {delay = true; recurse = true})
+
+ if path.isdir(newsite.location) then
+ return print("Your new website is ready to be cutomize here '" .. newsite.location .. "'!")
+ else
+ return print("!! Error, something went wrong !")
+ end
end
function site.reset()
- -- Reset the `public_html/` folder of the selected site
- return fileutils.emptydirectory(Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "/")
+ -- Reset the `public_html/` folder of the selected site
+ return fileutils.emptydirectory(Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "/")
end
return site