Skip to content

Commit

Permalink
add two suggestions for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
christinaroise committed Aug 30, 2024
1 parent faf4a79 commit 7de0c12
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 10 deletions.
12 changes: 12 additions & 0 deletions languages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const languages = [
{ id: "en", title: "English", isDefault: true },
{ id: "se", title: "Swedish" },
{ id: "no", title: "Norwegian" },
];

const i18n = {
languages,
base: "en",
};

export { i18n };
197 changes: 196 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@google-cloud/pubsub": "^4.5.0",
"@sanity/document-internationalization": "^3.0.1",
"@sanity/image-url": "^1.0.2",
"@sanity/preview-url-secret": "^1.6.11",
"@sanity/react-loader": "^1.9.15",
Expand All @@ -24,6 +25,7 @@
"react-dom": "^18",
"react-focus-on": "^3.9.3",
"sanity": "^3.50.0",
"sanity-plugin-documents-pane": "^2.3.0",
"styled-components": "^6.1.8"
},
"devDependencies": {
Expand Down
66 changes: 66 additions & 0 deletions studioShared/deskStructure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { i18n } from "languages";
import {
StructureResolver,
DefaultDocumentNodeResolver,
} from "sanity/structure";
import { blogPostsID } from "studioShared/schemas/documents/blogPosts";

export const deskStructure: StructureResolver = (S) =>
S.list()
.title("Content")
.items([
S.listItem()
.title("Blogposts sorted by base language")
.child(
S.documentTypeList(blogPostsID)
.title("List of Blogposts")
.filter("_type == $type && language == $lang")
.params({ type: blogPostsID, lang: i18n.base })
),
S.listItem()
.title("Blogposts sorted into language folders")
.child(
S.list()
.title("Blogposts")
.items([
S.listItem()
.title("Blogposts (EN)")
.child(
S.documentTypeList(blogPostsID)
.title("List of Blogposts (EN)")
.filter("_type == $type && language == $lang")
.params({ type: blogPostsID, lang: "en" })
),
S.listItem()
.title("Blogposts (NO)")
.child(
S.documentTypeList(blogPostsID)
.title("List of Blogposts (NO)")
.filter("_type == $type && language == $lang")
.params({ type: blogPostsID, lang: "no" })
),
S.listItem()
.title("Blogposts (SE)")
.child(
S.documentTypeList(blogPostsID)
.title("List of Blogposts (SE)")
.filter("_type == $type && language == $lang")
.params({ type: blogPostsID, lang: "se" })
),
// Add more languages as needed
])
),
// Other items can be added here if needed
]);

export const defaultDocumentNode: DefaultDocumentNodeResolver = (
S,
{ schemaType }
) => {
switch (schemaType) {
case blogPostsID:
return S.document().views([S.view.form()]);
default:
return S.document();
}
};
22 changes: 20 additions & 2 deletions studioShared/sanity.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { defineConfig } from "sanity";
import { structureTool } from "sanity/structure";
import { dataset, projectId } from "./env";
import { visionTool } from "@sanity/vision";
import { apiVersion, dataset, projectId } from "./env";
import { schema } from "./schema";
import { documentInternationalization } from "@sanity/document-internationalization";
import { i18n } from "languages";
import { blogPostsID } from "./schemas/documents/blogPosts";
import { deskStructure } from "./deskStructure";
import { titleSlug } from "studio/schemas/schemaTypes/slug";

/**
* This configuration is used for the Sanity Studio that’s mounted on the `/app/shared/[[...index]]/page.tsx` route
Expand All @@ -12,5 +18,17 @@ export default defineConfig({
projectId,
dataset,
schema,
plugins: [structureTool()],
plugins: [
structureTool({
structure: deskStructure,
}),
visionTool({ defaultApiVersion: apiVersion }),
documentInternationalization({
supportedLanguages: i18n.languages,
schemaTypes: [blogPostsID],
languageField: `language`,
metadataFields: [titleSlug],
apiVersion,
}),
],
});
Loading

0 comments on commit 7de0c12

Please sign in to comment.