Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cname.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
return {
export type Entry = { content: string, proxied: boolean }
export type Entries = { [string]: Entry | string }

local cname: Entries = {
-- ["project"] = "user.github.io", (project.luau.page CNAME record for user.github.io/project)
[""] = "nicell.github.io",
["hermes"] = "froststarinteractive.github.io",
Expand All @@ -12,3 +15,5 @@ return {
["typeforge"] = "typeforge-luau.github.io",
["ui-labs"] = "pepeeltoro41.github.io",
}

return cname
8 changes: 4 additions & 4 deletions scripts/cloudflare.luau
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ local function getRecord(name: string): Record?
error(`Failed to get record for {name}: {data.errors[1].message}`)
end

local function addRecord(name: string, content: string)
local function addRecord(name: string, content: string, proxy: boolean)
table.insert(batch.posts, {
type = "CNAME",
name = qualifiedName(name),
content = content,
proxied = true,
proxied = proxy,
})
end

local function updateRecord(name: string, content: string)
local function updateRecord(name: string, content: string, proxy: boolean)
local record = getRecord(name)
if record == nil then
print("Record not found for", name)
Expand All @@ -63,7 +63,7 @@ local function updateRecord(name: string, content: string)
type = "CNAME",
name = qualifiedName(name),
content = content,
proxied = true,
proxied = proxy,
})
end

Expand Down
30 changes: 22 additions & 8 deletions scripts/update.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,51 @@ local cf = require("./cloudflare")

local cname = require("../cname")
local success, oldCname = pcall(function()
return require("../cname-old")
return require("../cname-old") :: cname.Entries?
end)

if not success then
print("No old cname file found, creating a new one.")
oldCname = {}
end

local function intoEntry(content: string | cname.Entry): cname.Entry
if typeof(content) == "string" then
-- unstructured CNAME content, always proxied
return { content = content, proxied = true }
end

-- structured entry
return content
end

local delete = table.clone(oldCname)
local add = {}
local update = {}

for name, content in cname do
local entry = intoEntry(content)

if oldCname[name] == nil then
add[name] = content -- net new
add[name] = entry -- net new
else
delete[name] = nil -- exists in new, not deleted
if oldCname[name] ~= content then
update[name] = content -- content changed

local oldEntry = intoEntry(oldCname[name])
if oldEntry.content ~= entry.content or oldEntry.proxied ~= entry.proxied then
update[name] = entry -- entry changed
end
end
end

for name, content in add do
for name, entry in add do
print("add", name)
cf.addRecord(name, content)
cf.addRecord(name, entry.content, entry.proxied)
end

for name, content in update do
for name, entry in update do
print("update", name)
cf.updateRecord(name, content)
cf.updateRecord(name, entry.content, entry.proxied)
end

for name, _ in delete do
Expand Down