Browse Source

gluon-core: add domain aliases and pretty name

Based-on-patch-by: lemoer <git@irrelefant.net>
Matthias Schiffer 2 years ago
parent
commit
6ae067cb37
3 changed files with 25 additions and 0 deletions
  1. 6 0
      package/gluon-core/check_site.lua
  2. 6 0
      package/gluon-site/Makefile
  3. 13 0
      scripts/domain_aliases.lua

+ 6 - 0
package/gluon-core/check_site.lua

@@ -13,6 +13,12 @@ if this_domain() then
 		end, nil, 'be a valid domain name')
 	end
 	need_domain_name(in_site({'default_domain'}))
+
+	need_table(in_domain({'domain_names'}), function(domain)
+		need_alphanumeric_key(domain)
+		need_string(domain)
+	end)
+	need_string(in_domain({'domain_names', this_domain()}))
 end
 
 need_string_match(in_domain({'domain_seed'}), '^' .. ('%x'):rep(64) .. '$')

+ 6 - 0
package/gluon-site/Makefile

@@ -53,9 +53,15 @@ define Build/Compile
 	$(call GenerateJSON,site)
 
   ifdef CONFIG_GLUON_MULTIDOMAIN
+	rm -rf $(PKG_BUILD_DIR)/domains
 	mkdir -p $(PKG_BUILD_DIR)/domains
 	$(foreach domain,$(patsubst $(GLUON_SITEDIR)/domains/%.conf,%,$(wildcard $(GLUON_SITEDIR)/domains/*.conf)),
+		[ ! -e '$(PKG_BUILD_DIR)/domains/$(domain).json' ]
 		$(call GenerateJSON,domains/$(domain))
+		lua ../../scripts/domain_aliases.lua '$(PKG_BUILD_DIR)/domains/$(domain).json' | while read alias; do \
+			[ "$$$${alias}" != '$(domain)' ] || continue; \
+			ln -s '$(domain).json' $(PKG_BUILD_DIR)/domains/$$$${alias}.json || exit 1; \
+		done
 	)
   endif
 

+ 13 - 0
scripts/domain_aliases.lua

@@ -0,0 +1,13 @@
+local cjson = require 'cjson'
+
+local function load_json(filename)
+	local f = assert(io.open(filename))
+	local json = cjson.decode(f:read('*a'))
+	f:close()
+	return json
+end
+
+local domain = load_json(arg[1])
+for k, _ in pairs(domain.domain_names) do
+	print(k)
+end