-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.
8 changes: 8 additions & 0 deletions
8
javascripts/discourse/api-initializers/normalized-profile-links.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
javascripts/discourse/components/normalized-profile-links.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.