Skip to content

Parameterise Sanity config #1158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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