Skip to content

Commit 966b91f

Browse files
authored
FIX: Use transformer for forcing small logo (#40)
Using a transformer is more reliable and less intrusive than using a plugin outlet to replace a chunk of a core template. The `home-logo-minimized` transformer is a recent addition to core (added in discourse/discourse#30832), however this change is fully backward compatible -- if a site doesn't have the `registerValueTransformer` API or the new transformer, it will fallback to the plugin outlet override.
1 parent 91c3f3f commit 966b91f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

javascripts/discourse/api-initializers/full-width.gjs

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@ export default apiInitializer("0.8", (api) => {
66
document.body.classList.add("full-width-enabled");
77

88
// When the sidebar is visible, force the HomeLogo to be in an 'un-minimized' state.
9-
// Importing and using the HomeLogo component here isn't ideal... it's not really public API.
10-
// But, it is certainly better than monkey-patching inside the component.
9+
const transformerExists = api.registerValueTransformer?.(
10+
"home-logo-minimized",
11+
({ value, context }) => {
12+
if (value && context.showSidebar) {
13+
return false;
14+
}
15+
return value;
16+
}
17+
);
18+
19+
if (transformerExists) {
20+
return;
21+
}
22+
23+
// Remove this fallback once the `home-logo-minimized` transformer is in
24+
// stable
1125
api.renderInOutlet(
1226
"home-logo",
1327
class FullWidthHomeLogo extends Component {

0 commit comments

Comments
 (0)