Skip to content

Commit

Permalink
Download all fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 29, 2023
1 parent 81c91bc commit 5e1ec56
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ yarn-error.log*
.vercel

# external fonts
public/fonts/Optimistic_*.woff2
public/fonts/**/Optimistic_*.woff2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"analyze": "ANALYZE=true next build",
"dev": "next-remote-watch ./src/content",
"build": "next build && node ./scripts/downloadFonts.js",
"build": "next build && node --experimental-modules ./scripts/downloadFonts.mjs",
"lint": "next lint",
"lint:fix": "next lint --fix",
"format:source": "prettier --config .prettierrc --write \"{plugins,src}/**/*.{js,ts,jsx,tsx,css}\"",
Expand Down
29 changes: 0 additions & 29 deletions scripts/downloadFonts.js

This file was deleted.

75 changes: 75 additions & 0 deletions scripts/downloadFonts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*/

import { exec } from 'child_process';
import { mkdir, promises as fsPromises } from 'fs';
import { dirname } from 'path';
import { promisify } from 'util';

const execAsync = promisify(exec);

// Taken from Downloads on https://www.facebook.com/brand/meta/typography/.
// To refresh the list, go to the Conf website's public/fonts/ folder and run this:
// printf "\n[\n%s\n]\n" "$(find . -type f ! -path "*/.*" -name "*.woff2" | sed 's|^./||' | sort | awk '{printf " \"%s\",\n", $0}' | sed '$s/,$//')"
const paths = [
"Optimistic_Display_W_Bd.woff2",
"Optimistic_Display_W_BdIt.woff2",
"Optimistic_Display_W_Lt.woff2",
"Optimistic_Display_W_Md.woff2",
"Optimistic_Display_W_MdIt.woff2",
"Optimistic_Display_W_SBd.woff2",
"Optimistic_Display_W_SBdIt.woff2",
"Optimistic_Display_W_XBd.woff2",
"Optimistic_Display_W_XLt.woff2",
"Optimistic_Text_W_Bd.woff2",
"Optimistic_Text_W_BdIt.woff2",
"Optimistic_Text_W_It.woff2",
"Optimistic_Text_W_Md.woff2",
"Optimistic_Text_W_MdIt.woff2",
"Optimistic_Text_W_Rg.woff2",
"Optimistic_Text_W_XBd.woff2",
"Optimistic_Text_W_XBdIt.woff2",
"arabic/Optimistic_Display_Arbc_W_Bd.woff2",
"arabic/Optimistic_Display_Arbc_W_Md.woff2",
"arabic/Optimistic_Display_Arbc_W_SBd.woff2",
"arabic/Optimistic_Text_Arbc_W_Bd.woff2",
"arabic/Optimistic_Text_Arbc_W_Md.woff2",
"arabic/Optimistic_Text_Arbc_W_Rg.woff2",
"arabic/Optimistic_Text_Arbc_W_XBd.woff2",
"cyrillic/Optimistic_Display_Cyrl_W_Bd.woff2",
"cyrillic/Optimistic_Display_Cyrl_W_Md.woff2",
"cyrillic/Optimistic_Display_Cyrl_W_SBd.woff2",
"cyrillic/Optimistic_Text_Cyrl_W_Bd.woff2",
"cyrillic/Optimistic_Text_Cyrl_W_Md.woff2",
"cyrillic/Optimistic_Text_Cyrl_W_Rg.woff2",
"cyrillic/Optimistic_Text_Cyrl_W_XBd.woff2",
"devanagari/Optimistic_Text_Deva_W_Bd.woff2",
"devanagari/Optimistic_Text_Deva_W_Md.woff2",
"devanagari/Optimistic_Text_Deva_W_Rg.woff2",
"devanagari/Optimistic_Text_Deva_W_XBd.woff2",
"vietnamese/Optimistic_Display_Viet_W_Bd.woff2",
"vietnamese/Optimistic_Display_Viet_W_Md.woff2",
"vietnamese/Optimistic_Display_Viet_W_SBd.woff2",
"vietnamese/Optimistic_Text_Viet_W_Bd.woff2",
"vietnamese/Optimistic_Text_Viet_W_Md.woff2",
"vietnamese/Optimistic_Text_Viet_W_Rg.woff2",
"vietnamese/Optimistic_Text_Viet_W_XBd.woff2"
];

const baseURL = "https://conf.reactjs.org/fonts/";
const outputDir = "public/fonts/";

await Promise.all(
paths.map(async (path) => {
const localPath = `${outputDir}${path}`;
const localDir = dirname(localPath);
await fsPromises.mkdir(localDir, { recursive: true });

const command = `curl ${baseURL}${path} --output ${localPath}`;
await execAsync(command);
console.log(`Downloaded ${path}`);
})
);

console.log("All fonts downloaded.");

0 comments on commit 5e1ec56

Please sign in to comment.