commit 9d2d1693f8cf4f796641827c22f9f196e7e2a3d5
parent 1bd26424c49c1f6d9da400dcc9094b6157540d52
Author: Hugo Soucy <hugo@soucy.cc>
Date: Sun, 27 Nov 2022 08:04:39 -0500
Rename sitemap to sitedata and meta to pagedata
It will be less confusing like that
Diffstat:
M | satelito/init.lua | | | 111 | +++++++++++++++++++++++++++++++------------------------------------------------ |
1 file changed, 44 insertions(+), 67 deletions(-)
diff --git a/satelito/init.lua b/satelito/init.lua
@@ -71,6 +71,10 @@ _G.Satelito.publicdir = lfs.currentdir()..'/'.._G.Satelito.config.paths.public_h
print('=> Fetching the templates ...')
_G.Satelito.templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. _G.Satelito.config.paths.templates))
+-- Get the arguments
+_G.Satelito.args = args
+
+--print(inspect(_G.Satelito))
----------
-- EXEC --
@@ -106,9 +110,6 @@ if args['init'] then
return
end
-print(inspect(Satelito))
-print(lfs.currentdir())
-
----------
-- PIPE --
----------
@@ -116,55 +117,50 @@ print(lfs.currentdir())
-- Pipe stdout into satelito
-- Example: '$ find site/content/ | satelito pipe'
if args['pipe'] then
- local config = _G.Satelito.config;
local contentdir = _G.Satelito.contentdir
- local sitemap = {}
- local templates = _G.Satelito.templates
- local timestart = os.time()
+ local sitedata = {}
for filepath in (io.lines()) do
if file.is_content(filepath) then
- -- Get the meta of the file
- local meta = model.set(filepath, lume.extend(config, {templates = templates}), contentdir)
+ -- Get the pagedata of the file
+ local pagedata = model.set(filepath)
-- Collection
-- Get the files of a collection (only for the pipe command)
- if meta.collection and type(meta.collection) == 'table' then
- for i = 1, #meta.collection do
- if lfs.attributes(contentdir..meta.collection[i]).mode == 'directory' then
- for collectable in dirtree.get(contentdir..meta.collection[i]) do
+ if pagedata.collection and type(pagedata.collection) == 'table' then
+ for i = 1, #pagedata.collection do
+ if lfs.attributes(contentdir..pagedata.collection[i]).mode == 'directory' then
+ for collectable in dirtree.get(contentdir..pagedata.collection[i]) do
if file.is_content(collectable) and file.get_metafile(collectable) then
- sitemap[#sitemap+1] = model.set(collectable, lume.extend(config, {templates = templates}), contentdir)
+ sitedata[#sitedata+1] = model.set(collectable)
end
end
else
- if file.is_content(contentdir..meta.collection[i])
- and file.get_metafile(contentdir..meta.collection[i])
+ if file.is_content(contentdir..pagedata.collection[i])
+ and file.get_metafile(contentdir..pagedata.collection[i])
then
- sitemap[#sitemap+1] = model.set(contentdir..meta.collection[i], lume.extend(config, {templates = templates}), contentdir)
+ sitedata[#sitedata+1] = model.set(contentdir..pagedata.collection[i])
end
end
end
end
- -- Add the meta of the file into the sitemap table
- if lume.count(sitemap) == 0 then
+ -- Add the pagedata of the file into the sitedata table
+ if lume.count(sitedata) == 0 then
print('=> Fetching the markdown and HTML content ...')
end
- sitemap[#sitemap+1] = meta
-
+ sitedata[#sitedata+1] = pagedata
end
end
- print('=> '..lume.count(sitemap)..' content found')
-
+ print('=> '..lume.count(sitedata)..' content found')
print('=> Making the web site ...')
-- Sorting by alphanum
- table.sort(lume.unique(sitemap), function(a, b) return a.idorder > b.idorder end)
+ table.sort(lume.unique(sitedata), function(a, b) return a.idorder > b.idorder end)
- return site.make(sitemap, args['export'], timestart)
+ return site.make(sitedata)
end
----------
@@ -174,56 +170,37 @@ end
-- Make command
-- Example: '$ satelito make --export'
if args['make'] then
- local config
- local templates
- local timestart = os.time()
- local sitemap = {}
-
- print('=> Satelito is on ...')
-
- if file.exists('config.lua') then
- -- Add the currentdir to the package.path
- package.path = package.path .. ';'.. lfs.currentdir() ..'/?.lua'
-
- -- Set config.lua in a table
- print('=> Fetching the configuration file content ...')
- config = require 'config'
-
- -- Absolute path to the 'content/' directory
- local contentdir = lfs.currentdir() .. '/' .. config.paths.content
-
- print('=> Fetching the templates ...')
- templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates))
+ local config = _G.Satelito.config;
+ local contentdir = _G.Satelito.contentdir
+ local templates = _G.Satelito.templates
+ local sitedata = {}
- print('=> Fetching the markdown and HTML content ...')
+ print('=> Fetching the markdown and HTML content ...')
- for filepath in dirtree.get(contentdir) do
- if file.is_markdown(filepath) or file.is_html(filepath) then
- local meta = model.set(filepath, lume.extend(config, {templates = templates}), contentdir)
+ for filepath in dirtree.get(contentdir) do
+ if file.is_content(filepath) then
+ local pagedata = model.set(filepath)
- sitemap[#sitemap+1] = meta
- end
+ sitedata[#sitedata+1] = pagedata
end
+ end
- print('=> '..lume.count(sitemap)..' content found')
- print('=> Making the web site ...')
+ print('=> '..lume.count(sitedata)..' content found')
+ print('=> Making the web site ...')
- -- Sort before make the website
- table.sort(lume.unique(sitemap), function(a, b) return a.idorder > b.idorder end)
+ -- Sort before make the website
+ table.sort(lume.unique(sitedata), function(a, b) return a.idorder > b.idorder end)
- site.make(sitemap, args['export'], timestart)
+ site.make(sitedata, args['export'])
- -- Make and export the sitemap.xml
- if config.sitemapxml and args['export'] then
- local sitemapxml_xml, sitemapxml_xml_path = sitemapxml.make(
- sitemap, templates, config.paths.public_html
- )
- file.export(sitemapxml_xml_path, sitemapxml_xml)
- end
+ -- Make and export the sitemap.xml
+ if config.sitemapxml and args['export'] then
+ local sitemapxml_xml, sitemapxml_xml_path = sitemapxml.make(
+ sitedata, templates, config.paths.public_html
+ )
- return
- else
- print('There is no "config.lua" here.')
- os.exit()
+ file.export(sitemapxml_xml_path, sitemapxml_xml)
end
+
+ return
end