Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pfaffman committed Jan 3, 2025
1 parent 792c801 commit cc6c55c
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 2 deletions.
Empty file added assets/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions common/common.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.normalized-user-fields {
display: flex;
flex-direction: column;
a {
margin-right: 5px;
}
.fa {
font-size: 1.2em;
}
.fa.d-icon.svg-icon.svg-string {
margin-left: 0px;
}
}
Empty file added desktop/desktop.scss
Empty file.
Empty file added javascripts/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { apiInitializer } from "discourse/lib/api";
import NormalizedProfileLinks from "../components/normalized-profile-links";

export default apiInitializer("1.8.0", (api) => {
// console.log("hello world from api initializer!");
api.renderInOutlet("user-post-names", NormalizedProfileLinks);
api.renderInOutlet("user-card-post-names", NormalizedProfileLinks);
});
40 changes: 40 additions & 0 deletions javascripts/discourse/components/normalized-profile-links.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import icon from "discourse-common/helpers/d-icon"; // Assuming this helper is valid.

export default class NormalizedProfileLinks extends Component {
@service linksSettings;

get userModel() {
// Safely fetch the user model from the outlet arguments.
return this.args.outletArgs?.user || this.args.outletArgs?.model;
}

get list() {
// Get field options and fallback to an empty array if null or undefined.
return this.linksSettings.fieldOptions(this.userModel) || [];
}

<template>
<div class="normalized-user-fields">
{{#each this.list as |field|}}
{{#if field.href}}
<div>
{{#unless field.icon}}{{field.name}}:{{/unless}}
<a
href={{field.href}}
rel="noopener noreferrer"
target="_blank"
title={{field.handle}}
>
{{#if field.icon}}
{{icon field.icon}}
{{/if}}
{{field.handle}}
</a>
</div>
{{/if}}
{{/each}}
</div>
</template>
}
74 changes: 74 additions & 0 deletions javascripts/discourse/services/links-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Service from "@ember/service";

export default class NormalizedProfileLinks extends Service {
normalizeUsername(input) {
if (!input) {
return null;
}

// Get the last segment after / or @
const match = input.match(/[/@]([^/@\s]+)$/);
return match ? match[1] : input.trim();
}

normalizeUserLink(input, baseUrl) {
const username = this.normalizeUsername(input);
if (!username || !baseUrl) {
return null;
}

const normalizedBase = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
return `${normalizedBase}${username}`;
}

fieldOptions(model) {
const userFields = model?.user_fields;
const profileLinks = settings.profile_links;
const siteUserFields = model.site?.user_fields;
if (userFields === undefined) {
return null;
}

return profileLinks
.map((field) => {
// console.log("doing this userField icon", field.icon);
const fieldName = field.custom_field_name;
const url = field.url;
// console.log("fieldName/url", fieldName, url);

// const siteUserField = model.site?.user_fields.filterBy(
// "custom_field_name",
// field.link.value
// )[0];

const fieldId = siteUserFields.filterBy("name", fieldName)[0]?.id;
const handle = userFields[fieldId];

// console.log("field", field, handle);

if (fieldName) {
field.name = fieldName;
}

if (handle) {
field.href = this.normalizeUserLink(handle, url);
field.handle = this.normalizeUsername(handle);
} else {
return null;
}

// if (siteUserField && userFields[siteUserField.id]) {
// const socialLinkValue = userFields[siteUserField.id];
// field.href =
// (RegExp(baseregex).test(socialLinkValue)
// ? socialLinkValue
// : base + socialLinkValue) || "";
// } else {
// return null;
// }

return field;
})
.compact();
}
}
Empty file added mobile/mobile.scss
Empty file.
Empty file added scss/.gitkeep
Empty file.
74 changes: 72 additions & 2 deletions settings.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,72 @@
example_setting:
default: true
svg_icons:
type: "list"
default: "question-circle|wallet|fab-x-twitter|fab-twitter|square-x-twitter|cloud|fab-github|fab-linkedin|fab-youtube|fab-vimeo|fab-instagram|fab-tiktok|fab-facebook|fab-threads|fab-mastodon|fab-strava"
list_type: "compact"

profile_links:
type: objects
default:
- custom_field_name: X
icon: fab-x-twitter
url: https://x.com/
title: X
- custom_field_name: X (Twitter)
icon: x-twitter
url: https://x.com/
title: X
- custom_field_name: BlueSky
icon: cloud
url: https://bsky.app/profile
title: BlueSky
- custom_field_name: GitHub
icon: fab-github
url: https://github.com
title: GitHub
- custom_field_name: LinkedIn
icon: fab-linkedin
url: https://linkedin.com
title: LinkedIn
- custom_field_name: youtube
icon: fab-youtube
url: https://youtube.com
title: YouTube
- custom_field_name: Vimeo
icon: fab-vimeo
url: https://vimeo.com
title: Vimeo
- custom_field_name: Instagram
icon: fab-instagram
url: https://instagram.com
title: Instagram
- custom_field_name: TikTok
icon: fab-tiktok
url: https://tiktok.com
title: TikTok
- custom_field_name: Facebook
icon: fab-facebook
url: https://facebook.com
title: Facebook
- custom_field_name: Threads
icon: fab-threads
url: https://threads.net
title: Threads
- custom_field_name: Mastodon
icon: fab-mastodon
url: https://mastodon.social
title: Mastodon
- custom_field_name: Strava
icon: fab-strava
url: https://strava.com/athletes/
title: Strava

schema:
name: site
properties:
custom_field_name:
type: string
icon:
type: string
url:
type: string
title:
type: string
Empty file added spec/system/.gitkeep
Empty file.
Empty file added test/acceptance/.gitkeep
Empty file.

0 comments on commit cc6c55c

Please sign in to comment.