-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bskyogcard: support emoji, more languages, long starter pack names (#…
- Loading branch information
Showing
12 changed files
with
413 additions
and
163 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -115,3 +115,6 @@ src/locale/locales/**/*.js | |
*.apk | ||
*.aab | ||
*.ipa | ||
|
||
# ogcard assets | ||
bskyogcard/src/assets/fonts/noto-* |
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
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
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 {writeFile} from 'node:fs/promises' | ||
import * as path from 'node:path' | ||
import {fileURLToPath} from 'node:url' | ||
|
||
const __DIRNAME = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
const FONTS = [ | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/japanese-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/chinese-traditional-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/chinese-simplified-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/chinese-hongkong-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/korean-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/thai-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/arabic-700-normal.ttf', | ||
'https://cdn.jsdelivr.net/fontsource/fonts/[email protected]/hebrew-700-normal.ttf', | ||
] | ||
|
||
async function main() { | ||
await Promise.all( | ||
FONTS.map(async urlStr => { | ||
const url = new URL(urlStr) | ||
const res = await fetch(url) | ||
const font = await res.arrayBuffer() | ||
const filename = url.pathname | ||
.split('/') | ||
.slice(-2) | ||
.join('/') | ||
.replace(/@[\d.]+\//, '-') | ||
if (!res.ok) { | ||
throw new Error(`HTTP ${res.status}: fetching failed for ${filename}`) | ||
} | ||
await writeFile( | ||
path.join(__DIRNAME, '..', 'src', 'assets', 'fonts', filename), | ||
Buffer.from(font), | ||
) | ||
}), | ||
) | ||
} | ||
|
||
main() |
File renamed without changes.
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
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
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,3 +1,4 @@ | ||
import {subsystemLogger} from '@atproto/common' | ||
|
||
export const httpLogger = subsystemLogger('bskyogcard') | ||
export const renderLogger = subsystemLogger('bskyogcard:render') |
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
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,37 @@ | ||
import twemoji from 'twemoji' | ||
|
||
import {renderLogger} from './logger.js' | ||
|
||
const U200D = String.fromCharCode(0x200d) | ||
const UFE0F_REGEXP = /\uFE0F/g | ||
|
||
export async function loadEmojiAsSvg(chars: string) { | ||
const cached = emojiCache.get(chars) | ||
if (cached) return cached | ||
const iconCode = twemoji.convert.toCodePoint( | ||
chars.indexOf(U200D) < 0 ? chars.replace(UFE0F_REGEXP, '') : chars, | ||
) | ||
const res = await fetch(getEmojiUrl(iconCode)) | ||
const body = await res.arrayBuffer() | ||
if (!res.ok) { | ||
renderLogger.warn( | ||
{status: res.status, err: Buffer.from(body).toString()}, | ||
'could not fetch emoji', | ||
) | ||
return | ||
} | ||
const svg = | ||
'data:image/svg+xml;base64,' + Buffer.from(body).toString('base64') | ||
emojiCache.set(chars, svg) | ||
return svg | ||
} | ||
|
||
const emojiCache = new Map<string, string>() | ||
|
||
function getEmojiUrl(code: string) { | ||
return ( | ||
'https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/' + | ||
code.toLowerCase() + | ||
'.svg' | ||
) | ||
} |
Oops, something went wrong.