Custom Profile Link

This solution is great and I hope we can help improve it. Our profile link is of the form “https://www.domain.com/user/[USER-ID]/”. The trailing slash wrecks the solution for us. I can add a URL rewrite but a better solution would be to make the code more adaptive. I want working real links back to the site!

I tried to convert the plugin to a theme so I could improve the javascript but that CONVERT Discourse function doesn’t seem to be working.

Can you make the update so that it adds functionality?


import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { service } from "@ember/service";

export default class ProfileCustomLink extends Component {
  @service site;
  @tracked customLinkUrl;
  @tracked customLinkFieldId;
  @tracked showCustomLink = false;
  @tracked user = this.args.model.username;
  @tracked userFields = this.args.model.user_fields;

  constructor() {
    super(...arguments);

    if (settings.profile_custom_link_field) {
      const siteUserFields = this.site.user_fields;

      if (!siteUserFields) {
        return;
      }

      const customLinkField = siteUserFields.filterBy(
        "name",
        settings.profile_custom_link_field
      )[0];

      if (!customLinkField) {
        return;
      }

      this.customLinkFieldId = this.userFields[customLinkField.id];
      if (!this.customLinkFieldId) {
        return;
      } else {
        this.showCustomLink = true;
        if (settings.profile_custom_link_prefix.includes("[CUSTOM-LINK-FIELD-ID]")) {
          const url = settings.profile_custom_link_prefix.replace("[CUSTOM-LINK-FIELD-ID]", this.customLinkFieldId);
          this.customLinkUrl = url;
        } else {
          const url = settings.profile_custom_link_prefix + this.customLinkFieldId;
          this.customLinkUrl = url;
        }
      }
    } else {
      const url = settings.profile_custom_link_prefix + this.user;
      this.customLinkUrl = url;
      this.showCustomLink = true;
    }
  }
}