Assets only available to SCSS not JS

Hello,

For the last week or so I’ve been styling a Discourse setup for a brand which includes fixed fonts, logos and icons.

To begin with I noticed that any assets I imported (place in assets folder and import under the assets object of about.json) became immediately available to use as a SCSS variable but took a minute or two to show up in settings.theme_uploads.

Now however, they don’t show up at all in settings.theme_uploads which means I can’t use them in my JavaScript. If I remove an asset it also stays in the settings object. The SCSS usage stays unaffected.

Help would be greatly appreciated.

إعجاب واحد (1)

نعم، أنا مرتبك قليلاً بشأن هذا أيضًا.

في أي نقطة يكون من الآمن استخدام مرجع مثل return settings.theme_uploads.blah في جافاسكريبت إن كان ذلك ممكنًا؟

أحصل على “غير معرف” لـ settings.theme_uploads في خاصيتي المحسوبة (في البداية على الأقل).

ما هو النمط الصحيح هنا؟

إعجاب واحد (1)

تمت إضافة بيانات settings.theme_uploads إلى جافاسكريبت مؤخرًا نسبيًا (بعد كتابة OP، أعتقد). يجب أن تكون موثوقة - نحن نستخدمها في السمات/المكونات الخاصة بنا. هل يمكنك شرح المشكلات التي تواجهها بمزيد من التفصيل؟

3 إعجابات

آه، لقد كنت أفتقد مجلد الأصول في مساري إلى الأصل، لذلك من المؤكد أن الرابط المعطل قد “أزال” الأصل:

{
  "name": "Cool Theme Component",
  "about_url": "",
  "component": true,
  "assets": {
    "background": "background.png"
  }
}

كان يجب أن يكون:

{
  "name": "Cool Theme Component",
  "about_url": "",
  "component": true,
  "assets": {
    "background": "assets/background.png"
  }
}

يا إلهي!

للعلم، أنا أشير إلى هذا في جافاسكريبت في مكون Ember، على سبيل المثال:

  @computed
  backgroundImage() {
    return settings.theme_uploads.background;
  }

سيؤدي ذلك إلى حدوث خطأ undefined عندما يكون المسار غير صحيح!

شكراً لاستماعك! @david، آسف لإضاعة وقتك.

@hakonbja هل قمت بحل مشكلتك؟

إعجابَين (2)