mirror of
https://github.com/colanode/colanode.git
synced 2025-12-25 07:59:35 +01:00
Update emojis and icons (#195)
This commit is contained in:
@@ -101,7 +101,7 @@ const EMOJI_MART_DATA_FILE_PATH = path.join(
|
||||
);
|
||||
|
||||
const TWEEMOJI_REPO = 'jdecked/twemoji';
|
||||
const TWEEMOJI_TAG = '15.1.0';
|
||||
const TWEEMOJI_TAG = '16.0.1';
|
||||
const TWEEMOJI_DIR_PATH = path.join(WORK_DIR_PATH, `twemoji-${TWEEMOJI_TAG}`);
|
||||
const TWEEMOJI_SVG_DIR_PATH = path.join(TWEEMOJI_DIR_PATH, 'assets', 'svg');
|
||||
|
||||
@@ -250,6 +250,7 @@ const initDatabase = () => {
|
||||
|
||||
database.exec(CREATE_CATEGORIES_TABLE_SQL);
|
||||
database.exec(CREATE_EMOJITS_TABLE_SQL);
|
||||
database.exec(CREATE_EMOJI_SKINS_TABLE_SQL);
|
||||
database.exec(CREATE_EMOJI_SVGS_TABLE_SQL);
|
||||
database.exec(CREATE_EMOJI_SEARCH_TABLE_SQL);
|
||||
database.exec(CREATE_EMOJI_CATEGORY_INDEX_SQL);
|
||||
@@ -331,8 +332,10 @@ const processEmojis = (
|
||||
const insertSearch = database.prepare(INSERT_SEARCH_SQL);
|
||||
const insertSearchMin = minDatabase.prepare(INSERT_SEARCH_SQL);
|
||||
|
||||
const upsertEmojiSkin = database.prepare(UPSERT_EMOJI_SKIN_SQL);
|
||||
const upsertEmojiSkinMin = minDatabase.prepare(UPSERT_EMOJI_SKIN_SQL);
|
||||
|
||||
const upsertSvg = database.prepare(UPSERT_SVG_SQL);
|
||||
const upsertEmojiSkin = minDatabase.prepare(UPSERT_EMOJI_SKIN_SQL);
|
||||
|
||||
const existingMetadata = readExistingMetadata(database);
|
||||
|
||||
@@ -481,11 +484,17 @@ const processEmojis = (
|
||||
emoji_id: newEmoji.id,
|
||||
svg: svgBuffer,
|
||||
});
|
||||
|
||||
upsertEmojiSkin.run({
|
||||
skin_id: skin.id,
|
||||
emoji_id: newEmoji.id,
|
||||
});
|
||||
|
||||
upsertEmojiSkinMin.run({
|
||||
skin_id: skin.id,
|
||||
emoji_id: newEmoji.id,
|
||||
});
|
||||
|
||||
sprite.add(skin.id, null, svgBuffer.toString('utf-8'));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import AdmZip from 'adm-zip';
|
||||
import SQLite from 'better-sqlite3';
|
||||
import ky from 'ky';
|
||||
import SvgSprite from 'svg-sprite';
|
||||
import { optimize } from 'svgo';
|
||||
|
||||
import { generateId, IdType } from '@colanode/core';
|
||||
|
||||
@@ -89,7 +90,7 @@ const REMIX_ICON_TAGS_FILE_PATH = path.join(REMIX_ICON_DIR_PATH, 'tags.json');
|
||||
const REMIX_ICON_ICONS_DIR_PATH = path.join(REMIX_ICON_DIR_PATH, 'icons');
|
||||
|
||||
const SIMPLE_ICONS_REPO = 'simple-icons/simple-icons';
|
||||
const SIMPLE_ICONS_TAG = '14.13.0';
|
||||
const SIMPLE_ICONS_TAG = '15.12.0';
|
||||
const SIMPLE_ICONS_DIR_PATH = path.join(
|
||||
WORK_DIR_PATH,
|
||||
`simple-icons-${SIMPLE_ICONS_TAG}`
|
||||
@@ -180,6 +181,37 @@ const downloadZipAndExtract = async (url: string, dir: string) => {
|
||||
zip.extractAllTo(dir, true);
|
||||
};
|
||||
|
||||
const processSvgContent = (svgContent: string): string => {
|
||||
try {
|
||||
const { data } = optimize(svgContent, {
|
||||
multipass: true,
|
||||
plugins: [
|
||||
{
|
||||
name: 'addAttributesToSVGElement',
|
||||
params: {
|
||||
attributes: [
|
||||
{
|
||||
fill: 'currentColor',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'removeTitle',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'Failed to process SVG with SVGO, falling back to original:',
|
||||
error
|
||||
);
|
||||
return svgContent;
|
||||
}
|
||||
};
|
||||
|
||||
const downloadRemixIconRepo = async () => {
|
||||
console.log('Downloading remix icon repo...');
|
||||
const url = `${GITHUB_DOMAIN}/${REMIX_ICON_REPO}/archive/refs/tags/v${REMIX_ICON_TAG}.zip`;
|
||||
@@ -378,13 +410,15 @@ const processIcons = (
|
||||
const svgPath = path.join(REMIX_ICON_ICONS_DIR_PATH, category, file);
|
||||
if (fs.existsSync(svgPath)) {
|
||||
const svgBuffer = fs.readFileSync(svgPath);
|
||||
const svgContent = svgBuffer.toString('utf-8');
|
||||
const processedSvg = processSvgContent(svgContent);
|
||||
|
||||
upsertSvg.run({
|
||||
id: newIcon.id,
|
||||
svg: svgBuffer,
|
||||
svg: Buffer.from(processedSvg),
|
||||
});
|
||||
|
||||
sprite.add(newIcon.id, null, svgBuffer.toString('utf-8'));
|
||||
sprite.add(newIcon.id, null, processedSvg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,10 +506,12 @@ const processIcons = (
|
||||
|
||||
if (fs.existsSync(svgFile)) {
|
||||
const svgBuffer = fs.readFileSync(svgFile);
|
||||
const svgContent = svgBuffer.toString('utf-8');
|
||||
const processedSvg = processSvgContent(svgContent);
|
||||
|
||||
upsertSvg.run({ id: logo.id, svg: svgBuffer });
|
||||
upsertSvg.run({ id: logo.id, svg: Buffer.from(processedSvg) });
|
||||
|
||||
sprite.add(logo.id, null, svgBuffer.toString('utf-8'));
|
||||
sprite.add(logo.id, null, processedSvg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user