Skip to content

Commit

Permalink
refactor: loadGoogleFont
Browse files Browse the repository at this point in the history
  • Loading branch information
aaharu committed Jan 10, 2023
1 parent c44113c commit 7f19432
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ const languageFontMap = {
unknown: "Noto+Sans",
};

async function loadGoogleFont(font: string, text: string) {
async function loadGoogleFont(fonts: string | string[], text: string) {
// @TODO: Support multiple fonts.
const font = Array.isArray(fonts) ? fonts.at(-1) : fonts;
if (!font || !text) return;

const API = `https://fonts.googleapis.com/css2?family=${font}&text=${
Expand Down Expand Up @@ -155,7 +157,7 @@ const loadDynamicAsset = ({ emoji }: { emoji?: EmojiType }) => {
if (!languageFontMap[code]) code = "unknown";

try {
const data = await loadGoogleFont(Array.isArray(languageFontMap[code]) ? languageFontMap[code].at(-1) : languageFontMap[code], text);
const data = await loadGoogleFont(languageFontMap[code], text);

if (data) {
return {
Expand Down

0 comments on commit 7f19432

Please sign in to comment.