From dd4161254f192f8ea4e9cca7c6674ea13c0b4616 Mon Sep 17 00:00:00 2001 From: Satoshi Ebisawa Date: Mon, 21 Oct 2024 15:50:49 +0900 Subject: [PATCH 1/4] Remove dummy font files --- app/fonts/Rosart-Bold.woff2 | 0 app/fonts/Rosart-Medium.woff2 | 0 app/fonts/Rosart-Regular.woff2 | 0 app/fonts/Rosart-RegularItalic.woff2 | 0 app/fonts/Rosart-SemiBold.woff2 | 0 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/fonts/Rosart-Bold.woff2 delete mode 100644 app/fonts/Rosart-Medium.woff2 delete mode 100644 app/fonts/Rosart-Regular.woff2 delete mode 100644 app/fonts/Rosart-RegularItalic.woff2 delete mode 100644 app/fonts/Rosart-SemiBold.woff2 diff --git a/app/fonts/Rosart-Bold.woff2 b/app/fonts/Rosart-Bold.woff2 deleted file mode 100644 index e69de29b..00000000 diff --git a/app/fonts/Rosart-Medium.woff2 b/app/fonts/Rosart-Medium.woff2 deleted file mode 100644 index e69de29b..00000000 diff --git a/app/fonts/Rosart-Regular.woff2 b/app/fonts/Rosart-Regular.woff2 deleted file mode 100644 index e69de29b..00000000 diff --git a/app/fonts/Rosart-RegularItalic.woff2 b/app/fonts/Rosart-RegularItalic.woff2 deleted file mode 100644 index e69de29b..00000000 diff --git a/app/fonts/Rosart-SemiBold.woff2 b/app/fonts/Rosart-SemiBold.woff2 deleted file mode 100644 index e69de29b..00000000 From 88967f7ff9e75962c0af3baf06924f609a67b54b Mon Sep 17 00:00:00 2001 From: Satoshi Ebisawa Date: Mon, 21 Oct 2024 16:09:46 +0900 Subject: [PATCH 2/4] Use altenate font on develop & preview env --- app/fonts/index.ts | 35 ++++----------------------- package.json | 3 ++- download-assets.js => prepare-font.js | 4 ++- vendor/fonts/alternative.ts | 7 ++++++ vendor/fonts/rosart.ts | 32 ++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 32 deletions(-) rename download-assets.js => prepare-font.js (84%) create mode 100644 vendor/fonts/alternative.ts create mode 100644 vendor/fonts/rosart.ts diff --git a/app/fonts/index.ts b/app/fonts/index.ts index 437e5cc4..97a75876 100644 --- a/app/fonts/index.ts +++ b/app/fonts/index.ts @@ -1,32 +1,7 @@ -import localFont from "next/font/local"; - -export const rosart = localFont({ - src: [ - { - path: "./Rosart-Regular.woff2", - weight: "400", - style: "normal", - }, - { - path: "./Rosart-RegularItalic.woff2", - weight: "400", - style: "italic", - }, - { - path: "./Rosart-Medium.woff2", - weight: "500", - style: "normal", - }, - { - path: "./Rosart-SemiBold.woff2", - weight: "600", - style: "normal", - }, - { - path: "./Rosart-Bold.woff2", - weight: "700", - style: "normal", - }, - ], +import { Roboto_Serif } from "next/font/google"; +/** + * Since the Rosart font is a proprietary font, use an alternative font during OSS development. + */ +export const rosart = Roboto_Serif({ variable: "--font-rosart", }); diff --git a/package.json b/package.json index 21336230..03ae41a0 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "version": "0.1.0", "private": true, "scripts": { + "predev": "node prepare-font.js", "dev": "SENTRY_SUPPRESS_TURBOPACK_WARNING=1 next dev --turbo", - "prebuild": "node download-assets.js", + "prebuild": "node prepare-font.js", "build": "next build", "start": "next start", "lint": "next lint" diff --git a/download-assets.js b/prepare-font.js similarity index 84% rename from download-assets.js rename to prepare-font.js index 7573b67e..ed7d70ff 100644 --- a/download-assets.js +++ b/prepare-font.js @@ -35,6 +35,7 @@ const downloadFile = async (url, destination) => { url: `${BLOB_URL}/fonts/${fileName}.woff2`, destination: `./app/fonts/${fileName}.woff2`, })); + fs.copyFile("./vendor/fonts/rosert.ts", "./app/fonts/index.ts"); for (const file of filesToDownload) { try { @@ -45,6 +46,7 @@ const downloadFile = async (url, destination) => { } } } else { - console.log("Skipping download in non-production environment"); + fs.copyFile("./vendor/fonts/alternative.ts", "./app/fonts/index.ts"); + console.log("Using an alternative font file in development mode."); } })(); diff --git a/vendor/fonts/alternative.ts b/vendor/fonts/alternative.ts new file mode 100644 index 00000000..97a75876 --- /dev/null +++ b/vendor/fonts/alternative.ts @@ -0,0 +1,7 @@ +import { Roboto_Serif } from "next/font/google"; +/** + * Since the Rosart font is a proprietary font, use an alternative font during OSS development. + */ +export const rosart = Roboto_Serif({ + variable: "--font-rosart", +}); diff --git a/vendor/fonts/rosart.ts b/vendor/fonts/rosart.ts new file mode 100644 index 00000000..437e5cc4 --- /dev/null +++ b/vendor/fonts/rosart.ts @@ -0,0 +1,32 @@ +import localFont from "next/font/local"; + +export const rosart = localFont({ + src: [ + { + path: "./Rosart-Regular.woff2", + weight: "400", + style: "normal", + }, + { + path: "./Rosart-RegularItalic.woff2", + weight: "400", + style: "italic", + }, + { + path: "./Rosart-Medium.woff2", + weight: "500", + style: "normal", + }, + { + path: "./Rosart-SemiBold.woff2", + weight: "600", + style: "normal", + }, + { + path: "./Rosart-Bold.woff2", + weight: "700", + style: "normal", + }, + ], + variable: "--font-rosart", +}); From 04097e939a895b760049bfe54ed83ef63485516f Mon Sep 17 00:00:00 2001 From: Satoshi Ebisawa Date: Mon, 21 Oct 2024 16:13:51 +0900 Subject: [PATCH 3/4] Specify subsets Got this warning. ``` Preload is enabled but no subsets were specified for font `Roboto Serif`. Please specify subsets or disable preloading if your intended subset can't be preloaded. Available subsets: `cyrillic`, `cyrillic-ext`, `latin`, `latin-ext`, `vietnamese` ``` --- vendor/fonts/alternative.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/vendor/fonts/alternative.ts b/vendor/fonts/alternative.ts index 97a75876..a3bc9ad6 100644 --- a/vendor/fonts/alternative.ts +++ b/vendor/fonts/alternative.ts @@ -4,4 +4,5 @@ import { Roboto_Serif } from "next/font/google"; */ export const rosart = Roboto_Serif({ variable: "--font-rosart", + subsets: ["latin"], }); From 710b4639391c45ea8dad4d3d1aced27b9ff9171f Mon Sep 17 00:00:00 2001 From: Satoshi Ebisawa Date: Mon, 21 Oct 2024 16:22:36 +0900 Subject: [PATCH 4/4] .gitignore app/fonts/index.ts --- .gitignore | 3 +++ app/fonts/.gitkeep | 0 app/fonts/index.ts | 7 ------- 3 files changed, 3 insertions(+), 7 deletions(-) create mode 100644 app/fonts/.gitkeep delete mode 100644 app/fonts/index.ts diff --git a/.gitignore b/.gitignore index 97b62797..a974b91e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ next-env.d.ts # Sentry Config File .env.sentry-build-plugin + +# prepare fonts programmatically +app/fonts/index.ts diff --git a/app/fonts/.gitkeep b/app/fonts/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/fonts/index.ts b/app/fonts/index.ts deleted file mode 100644 index 97a75876..00000000 --- a/app/fonts/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Roboto_Serif } from "next/font/google"; -/** - * Since the Rosart font is a proprietary font, use an alternative font during OSS development. - */ -export const rosart = Roboto_Serif({ - variable: "--font-rosart", -});