gluon-core: add domain aliases and pretty name
This commit is contained in:
parent
bf3446598b
commit
88a9a974ff
@ -4,6 +4,17 @@ need_string_match(in_domain('domain_seed'), '^' .. ('%x'):rep(64) .. '$')
|
||||
|
||||
need_string(in_site('default_domain_code'))
|
||||
|
||||
need_string(in_domain('domain_name'))
|
||||
|
||||
function check_alias(k, conf_name)
|
||||
assert_uci_name(k, conf_name)
|
||||
|
||||
local path = string.format('domain_aliases[%q]', k)
|
||||
need_string(in_domain(path))
|
||||
end
|
||||
|
||||
need_table(in_domain('domain_aliases'), check_alias, false)
|
||||
|
||||
if need_table('opkg', nil, false) then
|
||||
need_string('opkg.lede', false)
|
||||
|
||||
|
@ -29,7 +29,11 @@ local domain = (function(site)
|
||||
dc = site['default_domain_code']
|
||||
end
|
||||
|
||||
return read_json('/lib/gluon/domains/'..dc..'.json')
|
||||
local domain = read_json('/lib/gluon/domains/'..dc..'.json')
|
||||
if domain['domain_aliases'] and domain['domain_aliases'][dc] then
|
||||
domain['domain_name'] = domain['domain_aliases'][dc]
|
||||
end
|
||||
return domain
|
||||
end)(site)
|
||||
|
||||
|
||||
|
@ -49,7 +49,15 @@ define Build/Compile
|
||||
ls $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/*.conf > /dev/null # at least one domain cfg has to exist
|
||||
GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(assert(dofile("../../scripts/site_config.lua")).default_domain_code)' > $(PKG_BUILD_DIR)/default_domain_code
|
||||
ls '$(call qstrip,$(CONFIG_GLUON_SITEDIR))'/domains/$$$$(cat $(PKG_BUILD_DIR)/default_domain_code).conf # ensure default_domain_code exists
|
||||
for domain_cfg in `find $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/ -iname \*.conf -printf "%f\n"`; do dc=$$$${domain_cfg%.conf}; GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(require("cjson").encode(assert(dofile("../../scripts/domain_config.lua")("'$$$${dc}'"))))' > $(PKG_BUILD_DIR)/domains/$$$${dc}.json; done
|
||||
rm -f $(PKG_BUILD_DIR)/domains/*.json
|
||||
for domain_cfg in `find $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/ -iname \*.conf -printf "%f\n"`; do \
|
||||
dc=$$$${domain_cfg%.conf}; \
|
||||
GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(require("cjson").encode(assert(dofile("../../scripts/domain_config.lua")("'$$$${dc}'"))))' > $(PKG_BUILD_DIR)/domains/$$$${dc}.json; \
|
||||
aliases=$$$$(GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'for alias_name, _ in pairs(dofile("../../scripts/domain_config.lua")("'$$$${dc}'")["domain_aliases"] or {}) do print(alias_name.." ") end'); \
|
||||
for alias in $$$${aliases}; do \
|
||||
ln -s $$$${dc}.json $(PKG_BUILD_DIR)/domains/$$$${alias}.json; \
|
||||
done; \
|
||||
done
|
||||
$(call GluonBuildI18N,gluon-site,$(GLUON_SITEDIR)/i18n)
|
||||
endef
|
||||
|
||||
|
@ -281,7 +281,6 @@ struct json_object * gluonutil_load_site_config(void) {
|
||||
|
||||
snprintf(domain_path, sizeof domain_path, domain_path_fmt, domain_code);
|
||||
|
||||
free(domain_code);
|
||||
|
||||
struct json_object * domain = json_object_from_file(domain_path);
|
||||
|
||||
@ -290,6 +289,24 @@ struct json_object * gluonutil_load_site_config(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
json_object * aliases;
|
||||
|
||||
// it's okay to pass base == NULL to json_object_object_get_ex()
|
||||
if (!json_object_object_get_ex(domain, "domain_aliases", &aliases))
|
||||
goto skip_name_replacement;
|
||||
|
||||
json_object * aliased_domain_name;
|
||||
|
||||
if (!json_object_object_get_ex(aliases, domain_code, &aliased_domain_name))
|
||||
goto skip_name_replacement;
|
||||
|
||||
// freeing of old value is done inside json_object_object_add()
|
||||
json_object_object_add(domain, "domain_name", json_object_get(aliased_domain_name));
|
||||
|
||||
skip_name_replacement:
|
||||
|
||||
free(domain_code);
|
||||
|
||||
// finally merge them
|
||||
return merge_json(domain, base);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user