pothi.love/0144-new_comment_id

13 lines
461 B
Plaintext

new_comment_id = function(id)
local corename = id:gsub('%.md$', '')
-- there'll be a collision on avarage every #Random_string_chars^(n/2) = 1296 comments
local n = 4
local result = ('%s-%s.md'):format(corename, random_string(4))
if file_exists(comment_path(result)) then
-- retry
-- This will infinite loop every #Random_string_chars^n = 1.6M, but it'll start taking a long time by halfway as long.
return new_comment_id(id)
end
return result
end