site.lua 695 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. local json = require 'jsonc'
  2. local site = assert(json.load('/lib/gluon/site.json'))
  3. local wrap
  4. local function index(t, k)
  5. local v = getmetatable(t).value
  6. if v == nil then return wrap(nil) end
  7. return wrap(v[k])
  8. end
  9. local function newindex()
  10. error('attempted to modify site config')
  11. end
  12. local function call(t, def)
  13. local v = getmetatable(t).value
  14. if v == nil then return def end
  15. return v
  16. end
  17. local function _wrap(v, t)
  18. return setmetatable(t or {}, {
  19. __index = index,
  20. __newindex = newindex,
  21. __call = call,
  22. value = v,
  23. })
  24. end
  25. local none = _wrap(nil)
  26. function wrap(v, t)
  27. if v == nil then return none end
  28. return _wrap(v, t)
  29. end
  30. module 'gluon.site'
  31. return wrap(site, _M)