Skip to content

Commit e866f9a

Browse files
committed
Fixed non-pages not generating before pages.
Printing more verbose info.
1 parent a11c582 commit e866f9a

File tree

3 files changed

+65
-30
lines changed

3 files changed

+65
-30
lines changed

build/Changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LuaWebGen
44
v1.3 (2021-05-24)
55
- Added JSON as a supported data format.
66
- Added "xml" as a new template file type (for e.g. RSS feeds and sitemaps).
7-
- Added commands 'new feed' and 'new sitemap'
7+
- Added commands 'new feed' and 'new sitemap'.
88
- Added site.description .
99
- Added page.description and page.dateModified .
1010
- Added global 'utf8' module.

src/app.lua2p

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,9 @@ local function setup()
10751075
errorf(2, "Could not read file '%s': %s", path, err)
10761076
end
10771077

1078+
-- timestampPrintVerbose("--> Processing(start): %s", path)
10781079
local html = parseAndRunTemplate(getContext().page, path, template, "html", true, nil)
1080+
-- timestampPrintVerbose("--> Processing(finish): %s", path)
10791081
return html
10801082
end,
10811083

@@ -1147,6 +1149,8 @@ local function setup()
11471149
allowCurrentPage = pathPrefixOrAllowCurrentPage
11481150
end
11491151

1152+
generateNonPages() -- Make sure as many non-pages as possible finish generating before any actual page begins.
1153+
11501154
for _, page in ipairs(site._pages) do
11511155
if (page ~= pageCurrent or allowCurrentPage) and (
11521156
pathPrefix == ""
@@ -1522,15 +1526,15 @@ local function buildWebsite()
15221526
if onBefore then
15231527
!PUSH_CONTEXT "config"
15241528
local before = onBefore -- :BetterTraceback
1529+
timestampPrintVerbose("--> config.before(start)")
15251530
before()
1531+
timestampPrintVerbose("--> config.before(finish)")
15261532
!POP_CONTEXT()
15271533
end
15281534

15291535
--
15301536
-- Generate output
15311537
--
1532-
local nonPagePages = {}
1533-
15341538
traverseFiles(DIR_CONTENT, site._ignoreFolders, function(path, pathRel, filename, extLower)
15351539
-- Ignored.
15361540
if
@@ -1543,7 +1547,7 @@ local function buildWebsite()
15431547
elseif site._fileTypes[extLower] then
15441548
-- Generate these later so e.g. urlExists() works better.
15451549
local page = newPage(pathRel, false)
1546-
local pagesArray = (page.isPage and site._pages or nonPagePages)
1550+
local pagesArray = (page.isPage.v and site._pages or site._nonPagePages)
15471551
table.insert(pagesArray, page)
15481552

15491553
-- Special.
@@ -1571,20 +1575,24 @@ local function buildWebsite()
15711575
end
15721576
end)
15731577

1574-
for _, page in ipairs(nonPagePages) do
1575-
generateFromTemplateFile(page) -- Note that this template may trigger generation of actual pages (e.g. by calling subpages()).
1576-
end
1578+
timestampPrintVerbose("--> RegularGeneration(start)")
1579+
1580+
generateNonPages()
15771581

15781582
for _, page in ipairs(site._pages) do
1579-
if not (page._isGenerated or page._isSkipped) then
1583+
if not page._isGenerated then
15801584
generateFromTemplateFile(page)
15811585
end
15821586
end
15831587

1588+
timestampPrintVerbose("--> RegularGeneration(finish)")
1589+
15841590
if onAfter then
15851591
!PUSH_CONTEXT "config"
15861592
local after = onAfter -- :BetterTraceback
1593+
timestampPrintVerbose("--> config.after(start)")
15871594
after()
1595+
timestampPrintVerbose("--> config.after(finish)")
15881596
!POP_CONTEXT()
15891597
end
15901598

@@ -1843,7 +1851,9 @@ local function buildWebsite()
18431851
if onValidate then
18441852
!PUSH_CONTEXT "validation"
18451853
local validate = onValidate -- :BetterTraceback
1854+
timestampPrintVerbose("--> config.validate(start)")
18461855
validate()
1856+
timestampPrintVerbose("--> config.validate(finish)")
18471857
!POP_CONTEXT()
18481858
end
18491859

src/functions.lua2p

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
error, errorf, fileError, errorNoPos
2222
F, formatBytes, formatTemplate
2323
generateFromTemplateString, generateFromTemplateFile, generateRedirection
24+
generateNonPages
2425
generatorMeta
2526
getCwd
2627
getDirectory, getFilename, getExtension, getBasename
@@ -735,35 +736,41 @@ do
735736
-- stringResult = parseAndRunTemplate( page, path, template, fileType=fromPage, useCache, onPageInit=nil )
736737
-- onPageInit = function( wrappedPage )
737738
function _G.parseAndRunTemplate(page, path, template, fileType, useCache, onPageInit)
738-
if template == "" and not onPageInit then return "" end
739+
-- timestampPrintVerbose("--> Template(start): %s", path)
740+
local result
739741

740-
fileType = (fileType or site._fileTypes[page._extension])
742+
if template == "" and not onPageInit then
743+
result = ""
741744

742-
!local PRINT_RESULT = DEV and 1==0
743-
local result
745+
else
746+
fileType = (fileType or site._fileTypes[page._extension])
744747

745-
if fileType == "markdown" then
746-
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, true)
747-
result = markdownToHtml(result)
748-
result = trimNewlines(result).."\n" -- :Beautify
749-
!if PRINT_RESULT then __LUA` print"-- HTML --" print(result) print"-- /HTML --" ` end
748+
!local PRINT_RESULT = DEV and 1==0
750749

751-
elseif fileType == "html" then
752-
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, true)
753-
result = trimNewlines(result).."\n" -- :Beautify
754-
!if PRINT_RESULT then __LUA` print"-- HTML --" print(result) print"-- /HTML --" ` end
750+
if fileType == "markdown" then
751+
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, true)
752+
result = markdownToHtml(result)
753+
result = trimNewlines(result).."\n" -- :Beautify
754+
!if PRINT_RESULT then __LUA` print"-- HTML --" print(result) print"-- /HTML --" ` end
755755

756-
elseif fileType == "xml" then
757-
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, true)
758-
result = trimNewlines(result).."\n" -- :Beautify
759-
!if PRINT_RESULT then __LUA` print"-- XML --" print(result) print"-- /XML --" ` end
756+
elseif fileType == "html" then
757+
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, true)
758+
result = trimNewlines(result).."\n" -- :Beautify
759+
!if PRINT_RESULT then __LUA` print"-- HTML --" print(result) print"-- /HTML --" ` end
760760

761-
else
762-
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, false)
763-
result = trimNewlines(result).."\n" -- :Beautify
764-
!if PRINT_RESULT then __LUA` print"-- result --" print(result) print"-- /result --" ` end
761+
elseif fileType == "xml" then
762+
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, true)
763+
result = trimNewlines(result).."\n" -- :Beautify
764+
!if PRINT_RESULT then __LUA` print"-- XML --" print(result) print"-- /XML --" ` end
765+
766+
else
767+
result = _parseAndRunTemplate(page, path, template, useCache, onPageInit, false)
768+
result = trimNewlines(result).."\n" -- :Beautify
769+
!if PRINT_RESULT then __LUA` print"-- result --" print(result) print"-- /result --" ` end
770+
end
765771
end
766772

773+
-- timestampPrintVerbose("--> Template(finish): %s", path)
767774
return result
768775
end
769776

@@ -1750,6 +1757,7 @@ function _G.generateFromTemplateString(page, template, modTime, onPageInit)
17501757
local ext = getExtension(filename)
17511758
local extLower = ext:lower()
17521759

1760+
timestampPrintVerbose("--> Processing(start): %s", page._path)
17531761
local result
17541762

17551763
if page.isPage.v then
@@ -1762,6 +1770,8 @@ function _G.generateFromTemplateString(page, template, modTime, onPageInit)
17621770
(page.isDraft.v and not includeDrafts ) or -- Is draft?
17631771
(datetimeToTime(page.publishDate:g()) > nowTime) -- Is in future?
17641772
then
1773+
timestampPrintVerbose("--> Processing(abort): %s", page._path)
1774+
17651775
page._isSkipped = true
17661776
site._outputFileSkippedPageCount = site._outputFileSkippedPageCount + 1
17671777

@@ -1787,13 +1797,17 @@ function _G.generateFromTemplateString(page, template, modTime, onPageInit)
17871797
result = parseAndRunTemplate(page, page._pathForError, template, nil, false, onPageInit)
17881798
end
17891799

1800+
timestampPrintVerbose("--> Processing(finish): %s", page._path)
1801+
17901802
writeOutputFile(page._category, page._pathOut, page.url.v, result, modTime, page._path)
17911803
page._isGenerated = true
17921804

17931805
page._isGenerating = false
17941806
site._pagesGenerating[page._pathOut] = nil
17951807
end
17961808

1809+
-- generateFromTemplateFile( page )
1810+
-- Does nothing for skipped pages, or pages that are currently generating but are safely locked.
17971811
function _G.generateFromTemplateFile(page)
17981812
if page._isSkipped then return end
17991813
if page._isGenerating and page._isLocked then return end -- Allowed recursion.
@@ -1892,6 +1906,16 @@ end
18921906

18931907

18941908

1909+
function _G.generateNonPages()
1910+
for _, page in ipairs(site._nonPagePages) do
1911+
if not page._isGenerated then
1912+
generateFromTemplateFile(page) -- Note that this template may trigger generation of actual pages at some point before it finishes (e.g. by calling subpages()).
1913+
end
1914+
end
1915+
end
1916+
1917+
1918+
18951919
function _G.indexOf(t, v)
18961920
for i, item in ipairs(t) do
18971921
if item == v then return i end
@@ -2221,7 +2245,8 @@ function _G.newSite()
22212245

22222246
_scripts = newScriptFolderReader(DIR_SCRIPTS),
22232247

2224-
_pages = {--[[ page1, ... ]]},
2248+
_pages = {--[[ page1, ... ]]}, -- Page with isPage==true.
2249+
_nonPagePages = {--[[ page1, ... ]]}, -- Page with isPage==false.
22252250
_pagesGenerating = {--[[ [pathRelOut1]=true, ... ]]},
22262251

22272252
_writtenOutputEntries = {--[[ { path=pathRel1, pathOut=pathOutputRel1, url=url1 }, ... ]]},

0 commit comments

Comments
 (0)