Skip to content

Commit 985b735

Browse files
Parameterise Sanity config (#1158)
Retain the current default. The intent is to allow folks to provide alternative content. See #1148
1 parent a6346c4 commit 985b735

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
VITE_VERSION=$npm_package_version
22
VITE_NAME=$npm_package_name
33
VITE_FULL_URL=/
4+
VITE_SANITY_PROJECT=ajwvhvgo
5+
VITE_SANITY_DATASET=apps
6+
VITE_SANITY_PREVIEW_DATASET=apps-preview

src/common/sanity.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ export const sanityLanguageId = (locale: string): string => {
8787
return `${parts[0]}-${parts[1].toUpperCase()}`;
8888
};
8989

90-
export const project = "ajwvhvgo";
91-
export const dataset = flags.cmsPreview ? "apps-preview" : "apps";
90+
export const project = import.meta.env.VITE_SANITY_PROJECT;
91+
export const dataset = flags.cmsPreview
92+
? import.meta.env.VITE_SANITY_PREVIEW_DATASET
93+
: import.meta.env.VITE_SANITY_DATASET;
9294

9395
const queryUrl = (query: string): string => {
9496
return `https://${project}.apicdn.sanity.io/v1/data/query/${dataset}?query=${encodeURIComponent(

src/documentation/common/DocumentationContent.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe("DocumentationContent", () => {
6767
const view = render(<DocumentationContent content={content} />);
6868
// This relies on the mock above because Chakra UI's images have the src added later.
6969
expect(view.container.innerHTML).toMatchInlineSnapshot(
70-
`"<div class="chakra-stack css-iewcov"><img src="https://cdn.sanity.io/images/ajwvhvgo/apps/9fccaf51a164fedc98662188593de19bfb9be8ad-435x512.png?w=300&amp;q=80&amp;fit=max&amp;auto=format"></div>"`
70+
`"<div class="chakra-stack css-iewcov"><img src="https://cdn.sanity.io/images/project/dataset/9fccaf51a164fedc98662188593de19bfb9be8ad-435x512.png?w=300&amp;q=80&amp;fit=max&amp;auto=format"></div>"`
7171
);
7272
});
7373
});

src/documentation/ideas/content.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,5 @@ const ideasQuery = (languageId: string): string => {
2929
};
3030

3131
const adaptContent = (result: any): Idea[] | undefined => {
32-
const ideas = result?.pythonIdeasOrder as Idea[];
33-
if (!ideas) {
34-
return undefined;
35-
}
36-
if (ideas.length === 0) {
37-
return undefined;
38-
}
39-
return ideas;
32+
return result?.pythonIdeasOrder ?? [];
4033
};

src/setupTests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ afterEach(() => {
1313
cleanup();
1414
});
1515

16+
vi.stubEnv("VITE_SANITY_PROJECT", "project");
17+
vi.stubEnv("VITE_SANITY_DATASET", "dataset");
18+
1619
global.matchMedia =
1720
global.matchMedia ||
1821
function () {

src/vite.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
interface ImportMetaEnv {
55
readonly VITE_VERSION: string;
66
readonly VITE_STAGE: string;
7+
readonly VITE_SANITY_PROJECT: string;
8+
readonly VITE_SANITY_DATASET: string;
9+
readonly VITE_SANITY_PREVIEW_DATASET: string;
710
}
811

912
interface ImportMeta {

0 commit comments

Comments
 (0)