Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- /page_editor.lua
- -- Script to allow creation of "websites" in game with CC:tweaked
- -- Should only be used on a "webserver"
- -- Make sure advanced raid is attached and has disks in it
- -- Intended to be used in conjunction with other scripts at links below
- -- Webserver: https://pastebin.com/WNtwKkmM
- -- Web Browser: https://pastebin.com/6Qt1U5RF
- ----------------------------
- local function prompt(label)
- term.write(label .. ": ")
- return read()
- end
- local function editPage()
- term.clear()
- term.setCursorPos(1, 1)
- print("== Web Page Editor ==")
- local filename = prompt("Page name (no extension)")
- local title = prompt("Page title")
- print("Enter page body (end with a blank line):")
- local bodyLines = {}
- while true do
- local line = read()
- if line == "" then break end
- table.insert(bodyLines, line)
- end
- local body = table.concat(bodyLines, "\n")
- local links = {}
- while true do
- local linkText = prompt("Link text (blank to stop)")
- if linkText == "" then break end
- local linkTarget = prompt("Target page name")
- table.insert(links, { text = linkText, page = linkTarget })
- end
- local data = {
- title = title,
- body = body,
- links = links
- }
- local savePath = "/pages/" .. filename .. ".page"
- if not fs.exists("/pages") then fs.makeDir("/pages") end
- local file = fs.open(savePath, "w")
- file.write(textutils.serialize(data))
- file.close()
- print("\nSaved to " .. savePath)
- end
- editPage()
Advertisement
Add Comment
Please, Sign In to add comment