2020-05-06 00:15:03 +08:00
|
|
|
import { getResolverOption } from "discourse-common/resolver";
|
|
|
|
|
|
|
|
export const __DISCOURSE_RAW_TEMPLATES = {};
|
|
|
|
|
2021-05-08 02:41:06 +08:00
|
|
|
export function addRawTemplate(name, template, opts = {}) {
|
|
|
|
// Core templates should never overwrite themes / plugins
|
|
|
|
if (opts.core && __DISCOURSE_RAW_TEMPLATES[name]) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-06 00:15:03 +08:00
|
|
|
__DISCOURSE_RAW_TEMPLATES[name] = template;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function removeRawTemplate(name) {
|
|
|
|
delete __DISCOURSE_RAW_TEMPLATES[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findRawTemplate(name) {
|
|
|
|
if (getResolverOption("mobileView")) {
|
|
|
|
return (
|
|
|
|
__DISCOURSE_RAW_TEMPLATES[`javascripts/mobile/${name}`] ||
|
|
|
|
__DISCOURSE_RAW_TEMPLATES[`javascripts/${name}`] ||
|
|
|
|
__DISCOURSE_RAW_TEMPLATES[`mobile/${name}`] ||
|
|
|
|
__DISCOURSE_RAW_TEMPLATES[name]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
__DISCOURSE_RAW_TEMPLATES[`javascripts/${name}`] ||
|
|
|
|
__DISCOURSE_RAW_TEMPLATES[name]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function buildRawConnectorCache(findOutlets) {
|
|
|
|
let result = {};
|
2022-11-29 18:24:35 +08:00
|
|
|
findOutlets(
|
|
|
|
Object.keys(__DISCOURSE_RAW_TEMPLATES),
|
|
|
|
(outletName, resource) => {
|
|
|
|
result[outletName] ??= [];
|
|
|
|
result[outletName].push({
|
|
|
|
template: __DISCOURSE_RAW_TEMPLATES[resource],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2020-05-06 00:15:03 +08:00
|
|
|
return result;
|
|
|
|
}
|
2022-11-29 18:24:35 +08:00
|
|
|
|
|
|
|
export function eagerLoadRawTemplateModules() {
|
|
|
|
for (const [key, value] of Object.entries(requirejs.entries)) {
|
|
|
|
if (
|
|
|
|
key.includes("/templates/") &&
|
|
|
|
value.deps.includes("discourse-common/lib/raw-templates")
|
|
|
|
) {
|
|
|
|
require(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|