forked from mirrors/pronouns.cc
fix(frontend): encode pronoun links
This commit is contained in:
parent
30c086f0f3
commit
3ef4c715e7
2 changed files with 16 additions and 6 deletions
|
@ -11,18 +11,28 @@
|
||||||
return pronouns.display_text;
|
return pronouns.display_text;
|
||||||
} else {
|
} else {
|
||||||
const split = pronouns.pronouns.split("/");
|
const split = pronouns.pronouns.split("/");
|
||||||
if (split.length < 2) return split.join("/");
|
if (split.length === 5) return split.splice(0, 2).join("/");
|
||||||
else return split.slice(0, 2).join("/");
|
return pronouns.pronouns;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let link: string;
|
let link: string;
|
||||||
let shouldLink: boolean;
|
let shouldLink: boolean;
|
||||||
|
|
||||||
$: link = pronouns.display_text
|
$: link = linkPronouns(pronouns);
|
||||||
? `${pronouns.pronouns},${pronouns.display_text}`
|
|
||||||
: pronouns.pronouns;
|
|
||||||
$: shouldLink = pronouns.pronouns.split("/").length === 5;
|
$: 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>
|
</script>
|
||||||
|
|
||||||
{#if shouldLink}
|
{#if shouldLink}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import pronounsRaw from "$lib/pronouns.json";
|
||||||
const pronouns = pronounsRaw as PronounsJson;
|
const pronouns = pronounsRaw as PronounsJson;
|
||||||
|
|
||||||
export const load = (async ({ params }) => {
|
export const load = (async ({ params }) => {
|
||||||
const [param, displayText] = params.pronouns.split(",");
|
const [param, displayText] = decodeURIComponent(params.pronouns).split(",");
|
||||||
|
|
||||||
const arr = param.split("/");
|
const arr = param.split("/");
|
||||||
if (arr.length === 0 || params.pronouns === "") {
|
if (arr.length === 0 || params.pronouns === "") {
|
||||||
|
|
Loading…
Reference in a new issue