mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
[Glitch] Emoji: Load emoji with hash in URL
Port ff5d745e3d to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { flattenEmojiData } from 'emojibase';
|
import { flattenEmojiData } from 'emojibase';
|
||||||
import type { CompactEmoji, FlatCompactEmoji } from 'emojibase';
|
import type { CompactEmoji, FlatCompactEmoji, Locale } from 'emojibase';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
putEmojiData,
|
putEmojiData,
|
||||||
@@ -43,9 +43,8 @@ async function fetchAndCheckEtag<ResultType extends object[]>(
|
|||||||
if (locale === 'custom') {
|
if (locale === 'custom') {
|
||||||
url.pathname = '/api/v1/custom_emojis';
|
url.pathname = '/api/v1/custom_emojis';
|
||||||
} else {
|
} else {
|
||||||
// This doesn't use isDevelopment() as that module loads initial state
|
const modulePath = await localeToPath(locale);
|
||||||
// which breaks workers, as they cannot access the DOM.
|
url.pathname = modulePath;
|
||||||
url.pathname = `/packs${import.meta.env.DEV ? '-dev' : ''}/emoji/${locale}.json`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldEtag = await loadLatestEtag(locale);
|
const oldEtag = await loadLatestEtag(locale);
|
||||||
@@ -80,3 +79,18 @@ async function fetchAndCheckEtag<ResultType extends object[]>(
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const modules = import.meta.glob(
|
||||||
|
'../../../../../../node_modules/emojibase-data/**/compact.json',
|
||||||
|
{
|
||||||
|
as: 'url',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function localeToPath(locale: Locale) {
|
||||||
|
const key = `../../../../../../node_modules/emojibase-data/${locale}/compact.json`;
|
||||||
|
if (!modules[key] || typeof modules[key] !== 'function') {
|
||||||
|
throw new Error(`Unsupported locale: ${locale}`);
|
||||||
|
}
|
||||||
|
return modules[key]();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user