Skip to content

Commit

Permalink
Parameterise Sanity config (#1158)
Browse files Browse the repository at this point in the history
Retain the current default. The intent is to allow folks to provide alternative content.

See #1148
  • Loading branch information
microbit-grace authored Mar 26, 2024
1 parent a6346c4 commit 985b735
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
VITE_VERSION=$npm_package_version
VITE_NAME=$npm_package_name
VITE_FULL_URL=/
VITE_SANITY_PROJECT=ajwvhvgo
VITE_SANITY_DATASET=apps
VITE_SANITY_PREVIEW_DATASET=apps-preview
6 changes: 4 additions & 2 deletions src/common/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export const sanityLanguageId = (locale: string): string => {
return `${parts[0]}-${parts[1].toUpperCase()}`;
};

export const project = "ajwvhvgo";
export const dataset = flags.cmsPreview ? "apps-preview" : "apps";
export const project = import.meta.env.VITE_SANITY_PROJECT;
export const dataset = flags.cmsPreview
? import.meta.env.VITE_SANITY_PREVIEW_DATASET
: import.meta.env.VITE_SANITY_DATASET;

const queryUrl = (query: string): string => {
return `https://${project}.apicdn.sanity.io/v1/data/query/${dataset}?query=${encodeURIComponent(
Expand Down
2 changes: 1 addition & 1 deletion src/documentation/common/DocumentationContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("DocumentationContent", () => {
const view = render(<DocumentationContent content={content} />);
// This relies on the mock above because Chakra UI's images have the src added later.
expect(view.container.innerHTML).toMatchInlineSnapshot(
`"<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>"`
`"<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>"`
);
});
});
9 changes: 1 addition & 8 deletions src/documentation/ideas/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,5 @@ const ideasQuery = (languageId: string): string => {
};

const adaptContent = (result: any): Idea[] | undefined => {
const ideas = result?.pythonIdeasOrder as Idea[];
if (!ideas) {
return undefined;
}
if (ideas.length === 0) {
return undefined;
}
return ideas;
return result?.pythonIdeasOrder ?? [];
};
3 changes: 3 additions & 0 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ afterEach(() => {
cleanup();
});

vi.stubEnv("VITE_SANITY_PROJECT", "project");
vi.stubEnv("VITE_SANITY_DATASET", "dataset");

global.matchMedia =
global.matchMedia ||
function () {
Expand Down
3 changes: 3 additions & 0 deletions src/vite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
interface ImportMetaEnv {
readonly VITE_VERSION: string;
readonly VITE_STAGE: string;
readonly VITE_SANITY_PROJECT: string;
readonly VITE_SANITY_DATASET: string;
readonly VITE_SANITY_PREVIEW_DATASET: string;
}

interface ImportMeta {
Expand Down

0 comments on commit 985b735

Please sign in to comment.