Skip to content

Commit 2b1cf7f

Browse files
committed
Warn when page.date hasn't been updated (except for index and special pages).
1 parent 3adc18f commit 2b1cf7f

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

examples/apache/content/404.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{
2-
page.title = "Error 404: Not Found"
2+
page.title = "Error 404: Not Found"
3+
page.isSpecial = true
34
}}
45

56
# {{ page.title }}

src/app.lua2p

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ local function buildWebsite()
13751375

13761376
assertFunc(v, ...)
13771377

1378-
tLast[kLast] = nil -- Helps us find extra/unknown fields.
1378+
tLast[kLast] = nil -- Helps us find extra/unknown fields later.
13791379
return v
13801380
end
13811381

@@ -1440,10 +1440,10 @@ local function buildWebsite()
14401440
site._redirectionLayout = getV("redirectionLayout", site._redirectionLayout, "string")
14411441

14421442
for k in pairs(config) do
1443-
timestampPrintWarning("Unknown config field '%s'.", k)
1443+
timestampPrintWarning("%s: Unknown config field '%s'.", maybeFullPath"config.lua", k)
14441444
end
14451445
for k in pairs(htaccess or {}) do
1446-
timestampPrintWarning("Unknown config.htaccess field '%s'.", k)
1446+
timestampPrintWarning("%s: Unknown config.htaccess field '%s'.", maybeFullPath"config.lua", k)
14471447
end
14481448

14491449
if not isAny(type(site._outputPathFormat), "string","function") then
@@ -1491,7 +1491,7 @@ local function buildWebsite()
14911491

14921492
-- Final config handling.
14931493
for ext, customDataParser in pairs(customDataTextParsers) do
1494-
-- ext = ext:lower() -- Actually a bad idea! (Until we have a version of isFile() that is case insensitive, that is.)
1494+
-- ext = ext:lower() -- Actually a bad idea! (Until we have a version of isFile() that is case insensitive, that is. Also, we should probably raise an error if it's not lowercase.)
14951495

14961496
dataParsers[ext] = customDataParser
14971497
dataParserIsBinary[ext] = false
@@ -1502,7 +1502,7 @@ local function buildWebsite()
15021502
end
15031503

15041504
for ext, customDataParser in pairs(customDataBinaryParsers) do
1505-
-- ext = ext:lower() -- Actually a bad idea! (Until we have a version of isFile() that is case insensitive, that is.)
1505+
-- ext = ext:lower() -- Actually a bad idea! (Until we have a version of isFile() that is case insensitive, that is. Also, we should probably raise an error if it's not lowercase.)
15061506

15071507
dataParsers[ext] = customDataParser
15081508
dataParserIsBinary[ext] = true

src/functions.lua2p

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,12 @@ end
10751075
-- timestampLog( formatString, ... )
10761076
function _G.timestampLog(s, ...)
10771077
if select("#", ...) > 0 then s = F(s, ...) end
1078-
log("[%s] %s", os.date"%H:%M:%S", s)
1078+
1079+
if s == "" then
1080+
log("")
1081+
else
1082+
log("[%s] %s", os.date"%H:%M:%S", s)
1083+
end
10791084
end
10801085

10811086
-- timestampPrint( message )
@@ -1085,7 +1090,11 @@ end
10851090
function _G.timestampPrint(s, ...)
10861091
if select("#", ...) > 0 then s = F(s, ...) end
10871092

1088-
printf("[%s] %s", os.date"%H:%M:%S", s)
1093+
if s == "" then
1094+
print()
1095+
else
1096+
printf("[%s] %s", os.date"%H:%M:%S", s)
1097+
end
10891098
end
10901099
function _G.timestampPrintOnce(s, ...)
10911100
if select("#", ...) > 0 then s = F(s, ...) end
@@ -1128,7 +1137,7 @@ function _G.timestampPrintWarning(s, ...)
11281137
_G.warningCount = warningCount + 1
11291138
s = F("[%s] WARNING(%d): %s", os.date"%H:%M:%S", warningCount, s)
11301139

1131-
io.stderr:write(s, "\n")
1140+
io.stderr:write(s, "\n\n")
11321141
log(s)
11331142
end
11341143
function _G.timestampPrintWarningOnce(s, ...)
@@ -1140,7 +1149,7 @@ function _G.timestampPrintWarningOnce(s, ...)
11401149
_G.warningCount = warningCount + 1
11411150
s = F("[%s] WARNING(%d): %s", os.date"%H:%M:%S", warningCount, s)
11421151

1143-
io.stderr:write(s, "\n")
1152+
io.stderr:write(s, "\n\n")
11441153
log(s)
11451154
end
11461155

@@ -1777,6 +1786,11 @@ function _G.generateFromTemplateString(page, template, modTime, onPageInit)
17771786
return
17781787
end
17791788

1789+
if not (page.isIndex.v or page.isSpecial.v) and not page._dateHasBeenUpdated then
1790+
-- @UX: Should there be an option to disable this? Maybe an option for suppressing all warnings?
1791+
timestampPrintWarning("%s did not update page.date.", maybeFullPath(page._path))
1792+
end
1793+
17801794
page.content.v = pageContent
17811795
page._contentIsAvailable = true
17821796

@@ -2341,6 +2355,7 @@ do
23412355
_isSkipped = false,
23422356
_isLocked = false, -- @Cleanup: Is this always synced with _readonly? If so, just remove _isLocked.
23432357
_contentIsAvailable = false,
2358+
_dateHasBeenUpdated = false,
23442359
_path = pathRel,
23452360
_pathOut = pathRelOut,
23462361
_pathForError = maybeFullPath(F("%s/%s", DIR_CONTENT, pathRel)),
@@ -2390,7 +2405,7 @@ do
23902405
date = {
23912406
v = getDatetime(0),
23922407
g = function(field) return field.v end,
2393-
s = function(field, datetime) field.v = datetime end,
2408+
s = function(field, datetime) field.v = datetime ; page._dateHasBeenUpdated = true end,
23942409
},
23952410
dateModified = { -- This field currently isn't used anywhere internally - it just exists for the user's convenience. 2021-05-19
23962411
v = "",

0 commit comments

Comments
 (0)