DEV: migrate CdnImg to gjs (#27797)

This commit is contained in:
Joffrey JAFFEUX 2024-07-09 19:05:30 +02:00 committed by GitHub
parent c080ac0094
commit a60e1b35ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 30 deletions

View File

@ -0,0 +1,28 @@
import Component from "@glimmer/component";
import { htmlSafe } from "@ember/template";
import { getURLWithCDN } from "discourse-common/lib/get-url";
export default class CdnImg extends Component {
get cdnSrc() {
return getURLWithCDN(this.args.src);
}
get style() {
if (this.args.width && this.args.height) {
return htmlSafe(`--aspect-ratio: ${this.args.width / this.args.height};`);
}
}
<template>
{{#if @src}}
<img
...attributes
src={{this.cdnSrc}}
width={{@width}}
height={{@height}}
style={{this.style}}
alt=""
/>
{{/if}}
</template>
}

View File

@ -1,10 +0,0 @@
{{#if this.src}}
<img
...attributes
src={{this.cdnSrc}}
width={{this.width}}
height={{this.height}}
style={{this.style}}
alt=""
/>
{{/if}}

View File

@ -1,20 +0,0 @@
import Component from "@ember/component";
import { htmlSafe } from "@ember/template";
import { getURLWithCDN } from "discourse-common/lib/get-url";
import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({
tagName: "",
@discourseComputed("src")
cdnSrc(src) {
return getURLWithCDN(src);
},
@discourseComputed("width", "height")
style(width, height) {
if (width && height) {
return htmlSafe(`--aspect-ratio: ${width / height};`);
}
},
});