ccraftersanonmoose

Editor.lua

Apr 5th, 2025 (edited)
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. -- /page_editor.lua
  2. -- Script to allow creation of "websites" in game with CC:tweaked
  3. -- Should only be used on a "webserver"
  4. -- Make sure advanced raid is attached and has disks in it
  5. -- Intended to be used in conjunction with other scripts at links below
  6. -- Webserver: https://pastebin.com/WNtwKkmM
  7. -- Web Browser: https://pastebin.com/6Qt1U5RF
  8.  
  9. ----------------------------
  10. local function prompt(label)
  11.   term.write(label .. ": ")
  12.   return read()
  13. end
  14.  
  15. local function editPage()
  16.   term.clear()
  17.   term.setCursorPos(1, 1)
  18.  
  19.   print("== Web Page Editor ==")
  20.   local filename = prompt("Page name (no extension)")
  21.   local title = prompt("Page title")
  22.  
  23.   print("Enter page body (end with a blank line):")
  24.   local bodyLines = {}
  25.   while true do
  26.     local line = read()
  27.     if line == "" then break end
  28.     table.insert(bodyLines, line)
  29.   end
  30.   local body = table.concat(bodyLines, "\n")
  31.  
  32.   local links = {}
  33.   while true do
  34.     local linkText = prompt("Link text (blank to stop)")
  35.     if linkText == "" then break end
  36.     local linkTarget = prompt("Target page name")
  37.     table.insert(links, { text = linkText, page = linkTarget })
  38.   end
  39.  
  40.   local data = {
  41.     title = title,
  42.     body = body,
  43.     links = links
  44.   }
  45.  
  46.   local savePath = "/pages/" .. filename .. ".page"
  47.   if not fs.exists("/pages") then fs.makeDir("/pages") end
  48.   local file = fs.open(savePath, "w")
  49.   file.write(textutils.serialize(data))
  50.   file.close()
  51.  
  52.   print("\nSaved to " .. savePath)
  53. end
  54.  
  55. editPage()
Advertisement
Add Comment
Please, Sign In to add comment