From a64cec850b2a001ca1ef412350771678c95b9a83 Mon Sep 17 00:00:00 2001 From: Rong Mantle Bao Date: Sat, 15 Apr 2023 08:33:31 +0800 Subject: [PATCH 1/2] build: add new prefix strategy --- .github/workflows/deploy.yml | 5 +++-- gatsby-config.ts | 2 +- package.json | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5d06f68..94b917b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,7 +8,8 @@ on: jobs: build: runs-on: ubuntu-20.04 - + env: + - BUILD_ADD_PATH_PREFIX: true steps: - uses: actions/checkout@v3 - name: Use Node.js 18.x @@ -24,7 +25,7 @@ jobs: yarn run check - name: Build run: | - yarn run ci-build-prefixed + yarn run build --prefix-paths - name: Deploy uses: JamesIves/github-pages-deploy-action@v4.4.0 with: diff --git a/gatsby-config.ts b/gatsby-config.ts index b1c5c38..d35a3b9 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -51,7 +51,7 @@ const config: GatsbyConfig = { "Learn the Periodic Table of Elements in a fun way, directly in your browsers.", url: "https://csharpermantle.github.io/periotrisjs/", }, - pathPrefix: "/periotrisjs", + pathPrefix: process.env.BUILD_ADD_PATH_PREFIX ? "/periotrisjs" : undefined, } export default config diff --git a/package.json b/package.json index 6656a77..8728e3e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "2.2.1", "description": "Get familiar with the Periodic Table of Elements in a fun way, directly in your browsers.", "scripts": { - "ci-build-prefixed": "yarn run -B gatsby build --prefix-paths", "clean": "yarn run -B rimraf build coverage public && yarn run -B gatsby clean", "build": "yarn run -B gatsby build", "rebuild": "yarn run clean && yarn run build", From d4a97f0962fab70a486e17f8b8770fbaabe51e0f Mon Sep 17 00:00:00 2001 From: "Rong \"Mantle\" Bao" Date: Thu, 13 Jul 2023 08:38:11 +0800 Subject: [PATCH 2/2] fix: fix inconsistent queryPath accross routes --- src/common/__tests__/queryPath.test.ts | 8 ++++---- src/common/queryPath.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/__tests__/queryPath.test.ts b/src/common/__tests__/queryPath.test.ts index a5b2c8f..540051a 100644 --- a/src/common/__tests__/queryPath.test.ts +++ b/src/common/__tests__/queryPath.test.ts @@ -63,9 +63,9 @@ describe("queryPath", () => { id: 1, }, ] as const - expect(queryPath(null, 1)).toStrictEqual("#") - expect(queryPath(undefined, 1)).toStrictEqual("#") - expect(queryPath([], 1)).toStrictEqual("#") - expect(queryPath(routes, 1)).toStrictEqual("#") + expect(queryPath(null, 1)).toStrictEqual("") + expect(queryPath(undefined, 1)).toStrictEqual("") + expect(queryPath([], 1)).toStrictEqual("") + expect(queryPath(routes, 1)).toStrictEqual("") }) }) diff --git a/src/common/queryPath.ts b/src/common/queryPath.ts index 23781be..304c324 100644 --- a/src/common/queryPath.ts +++ b/src/common/queryPath.ts @@ -26,7 +26,7 @@ export type TRoutes = readonly TRoute[] | null | undefined export const queryPath = memoize( (routes: TRoutes, id: number): string => { - return head(filter(routes, (r) => r?.id === id))?.path ?? "#" + return head(filter(routes, (r) => r?.id === id))?.path ?? "" }, - (_, id) => id + (routes, id) => [routes, id] )