fix: get assets_json from boot
This commit is contained in:
parent
45e7e92ffa
commit
799cc62515
3 changed files with 15 additions and 14 deletions
|
|
@ -5,6 +5,6 @@ if (frappe.require) {
|
|||
frappe.require("file_uploader.bundle.js");
|
||||
} else {
|
||||
frappe.ready(function () {
|
||||
frappe.require("file_uploader.bundle.js", null, true);
|
||||
frappe.require("file_uploader.bundle.js");
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,26 +13,26 @@ $.extend(frappe, {
|
|||
lang: "en",
|
||||
},
|
||||
_assets_loaded: [],
|
||||
require: async function (links, callback, from_assets_json = false) {
|
||||
require: async function (links, callback) {
|
||||
if (typeof links === "string") {
|
||||
links = [links];
|
||||
}
|
||||
links = links.map((link) => frappe.bundled_asset(link));
|
||||
for (let link of links) {
|
||||
if (from_assets_json) {
|
||||
if (frappe.boot.assets_json) {
|
||||
link = frappe.boot.assets_json[link];
|
||||
} else {
|
||||
let r = await frappe.call("frappe.sessions.get_boot_assets_json");
|
||||
if (r.message) {
|
||||
frappe.boot.assets_json = r.message;
|
||||
link = frappe.boot.assets_json[link];
|
||||
}
|
||||
}
|
||||
}
|
||||
await this.add_asset_to_head(link);
|
||||
}
|
||||
callback && callback();
|
||||
},
|
||||
bundled_asset(path, is_rtl = null) {
|
||||
if (!path.startsWith("/assets") && path.includes(".bundle.")) {
|
||||
if (path.endsWith(".css") && is_rtl) {
|
||||
path = `rtl_${path}`;
|
||||
}
|
||||
path = frappe.boot.assets_json[path] || path;
|
||||
return path;
|
||||
}
|
||||
return path;
|
||||
},
|
||||
add_asset_to_head(link) {
|
||||
return new Promise((resolve) => {
|
||||
if (frappe._assets_loaded.includes(link)) return resolve();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from werkzeug.wrappers import Response
|
|||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import cint, get_time_zone, md_to_html
|
||||
from frappe.utils import cint, get_assets_json, get_time_zone, md_to_html
|
||||
|
||||
FRONTMATTER_PATTERN = re.compile(r"^\s*(?:---|\+\+\+)(.*?)(?:---|\+\+\+)\s*(.+)$", re.S | re.M)
|
||||
H1_TAG_PATTERN = re.compile("<h1>([^<]*)")
|
||||
|
|
@ -169,6 +169,7 @@ def get_boot_data():
|
|||
"system": get_time_zone(),
|
||||
"user": frappe.db.get_value("User", frappe.session.user, "time_zone") or get_time_zone(),
|
||||
},
|
||||
"assets_json": get_assets_json(),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue