fix(frontend): encode pronoun links

This commit is contained in:
Sam 2023-04-17 16:16:32 +02:00
parent 30c086f0f3
commit 3ef4c715e7
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
2 changed files with 16 additions and 6 deletions

View File

@ -11,18 +11,28 @@
return pronouns.display_text;
} else {
const split = pronouns.pronouns.split("/");
if (split.length < 2) return split.join("/");
else return split.slice(0, 2).join("/");
if (split.length === 5) return split.splice(0, 2).join("/");
return pronouns.pronouns;
}
};
let link: string;
let shouldLink: boolean;
$: link = pronouns.display_text
? `${pronouns.pronouns},${pronouns.display_text}`
: pronouns.pronouns;
$: link = linkPronouns(pronouns);
$: shouldLink = pronouns.pronouns.split("/").length === 5;
const linkPronouns = (pronouns: Pronoun) => {
const linkBase = pronouns.pronouns
.split("/")
.map((snippet) => encodeURIComponent(snippet))
.join("/");
if (pronouns.display_text) {
return `${linkBase},${encodeURIComponent(pronouns.display_text)}`;
}
return linkBase;
};
</script>
{#if shouldLink}

View File

@ -6,7 +6,7 @@ import pronounsRaw from "$lib/pronouns.json";
const pronouns = pronounsRaw as PronounsJson;
export const load = (async ({ params }) => {
const [param, displayText] = params.pronouns.split(",");
const [param, displayText] = decodeURIComponent(params.pronouns).split(",");
const arr = param.split("/");
if (arr.length === 0 || params.pronouns === "") {