DEV: Introduce `home-logo-image-url` value transformer (#28189)
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
parent
5357f0175e
commit
492a45da37
|
@ -55,23 +55,27 @@ export default class HomeLogo extends Component {
|
|||
}
|
||||
|
||||
logoResolver(name, opts = {}) {
|
||||
// get alternative logos for browser dark dark mode switching
|
||||
if (opts.dark) {
|
||||
return this.siteSettings[`site_${name}_dark_url`];
|
||||
}
|
||||
let url;
|
||||
|
||||
// try dark logos first when color scheme is dark
|
||||
// this is independent of browser dark mode
|
||||
// hence the fallback to normal logos
|
||||
if (this.session.defaultColorSchemeIsDark) {
|
||||
return (
|
||||
if (opts.dark) {
|
||||
// get alternative logos for browser dark dark mode switching
|
||||
url = this.siteSettings[`site_${name}_dark_url`];
|
||||
} else if (this.session.defaultColorSchemeIsDark) {
|
||||
// try dark logos first when color scheme is dark
|
||||
// this is independent of browser dark mode
|
||||
// hence the fallback to normal logos
|
||||
url =
|
||||
this.siteSettings[`site_${name}_dark_url`] ||
|
||||
this.siteSettings[`site_${name}_url`] ||
|
||||
""
|
||||
);
|
||||
"";
|
||||
} else {
|
||||
url = this.siteSettings[`site_${name}_url`] || "";
|
||||
}
|
||||
|
||||
return this.siteSettings[`site_${name}_url`] || "";
|
||||
return applyValueTransformer("home-logo-image-url", url, {
|
||||
name,
|
||||
dark: opts.dark,
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
@ -7,4 +7,5 @@ export const VALUE_TRANSFORMERS = Object.freeze([
|
|||
// use only lowercase names
|
||||
"header-notifications-avatar-size",
|
||||
"home-logo-href",
|
||||
"home-logo-image-url",
|
||||
]);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import { visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
acceptance("home-logo-image-url transformer", function () {
|
||||
test("applying a value transformation", async function (assert) {
|
||||
withPluginApi("1.34.0", (api) => {
|
||||
api.registerValueTransformer(
|
||||
"home-logo-image-url",
|
||||
({ value }) => "/transformed" + value
|
||||
);
|
||||
});
|
||||
|
||||
await visit("/");
|
||||
|
||||
assert
|
||||
.dom("#site-logo")
|
||||
.hasAttribute(
|
||||
"src",
|
||||
"/transformed/assets/logo.png",
|
||||
"it transforms the logo url"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue