Skip to content
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

Add sanity blog #224

Merged
merged 9 commits into from
Sep 4, 2024
Merged

Add sanity blog #224

merged 9 commits into from
Sep 4, 2024

Conversation

elie222
Copy link
Owner

@elie222 elie222 commented Sep 3, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced blog functionality with dynamic content fetching from a Sanity backend.
    • Introduced a structured layout for individual blog posts, improving presentation.
    • Added support for optimized image rendering and rich text formatting.
    • Integrated new queries for fetching blog post data from Sanity.
    • Implemented static generation for blog post pages with revalidation for fresh content.
  • Bug Fixes

    • Improved error handling for environment variable management.
  • Documentation

    • Added instructions for deploying Sanity Studio for blog management, including necessary environment variables.
  • Chores

    • Updated package dependencies to support new functionalities.
    • Enhanced configuration options for integrating with Sanity.

Copy link

vercel bot commented Sep 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Sep 4, 2024 2:57pm

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes introduce enhanced blog functionality with integration to a Sanity backend, allowing for dynamic data fetching and improved content management. New type definitions for posts and authors are established, along with utility functions for image handling and API interaction. Additionally, configurations for Sanity Studio are implemented, facilitating a streamlined authoring environment within the Next.js application.

Changes

Files Change Summary
apps/web/app/blog/page.tsx Updated BlogPage to fetch posts from Sanity, introduced Post type, modified Posts and PostCard components for dynamic content rendering.
apps/web/app/blog/post/[slug]/Post.tsx Introduced Post component for rendering individual blog posts with rich text and optimized images.
apps/web/app/blog/post/[slug]/page.tsx Created dynamic page for individual posts, implementing static generation with revalidation and fetching post data from Sanity.
apps/web/app/blog/types.ts Added new type definition for Post entity to represent blog posts in a type-safe manner.
apps/web/next.config.mjs Added cdn.sanity.io to the list of allowed image domains for optimized image serving.
apps/web/package.json Added dependencies for Sanity integration and styling, including @sanity/client, next-sanity, and styled-components.
apps/web/.env.example Introduced new environment variables for Sanity integration, including NEXT_PUBLIC_SANITY_PROJECT_ID and NEXT_PUBLIC_SANITY_DATASET.
apps/web/tsconfig.json Added "target": "ES2017" and updated module resolution paths for better compatibility with Sanity.
.gitignore Added .sanity to ignore files related to Sanity.
README.md Updated to include instructions for deploying Sanity Studio and necessary environment variables.
packages/eslint-config/package.json Updated devDependencies for ESLint configuration, including version upgrades for eslint-config-turbo and TypeScript ESLint packages.
packages/loops/package.json Updated the version of loops dependency and @types/node.
packages/resend/package.json Upgraded versions for @react-email/components, react-email, and type definitions for Node.js and React.
packages/tinybird-ai-analytics/package.json Updated @types/node version.
packages/tinybird/package.json Updated @types/node version.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BlogPage
    participant SanityAPI
    participant Posts
    participant PostCard

    User->>BlogPage: Request blog page
    BlogPage->>SanityAPI: Fetch posts
    SanityAPI-->>BlogPage: Return posts
    BlogPage->>Posts: Pass fetched posts
    Posts->>PostCard: Render each post
    PostCard-->>Posts: Display post content
    Posts-->>BlogPage: Return rendered posts
    BlogPage-->>User: Display blog page
Loading

🐰 In the meadow, I hop with glee,
New changes bloom like flowers, you see!
With posts fetching from afar,
My blog shines bright, a guiding star.
Sanity's magic, oh what a delight,
Hopping through code, everything feels right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Outside diff range, codebase verification and nitpick comments (7)
apps/web/sanity/lib/fetch.ts (1)

12-42: Refactor the sanityFetch function to improve performance and readability.

Consider applying the following improvements:

  1. Move the DEFAULT_PARAMS and DEFAULT_TAGS constants outside the function to avoid creating them on every function call.
  2. Move the isDevelopment constant outside the function to avoid creating it on every function call.
  3. Move the token constant outside the function to avoid creating it on every function call.
  4. Move the isDraftMode constant outside the function to avoid creating it on every function call.
  5. Improve the error message to provide more context.

Here's the refactored code:

import "server-only";

import type { QueryParams } from "@sanity/client";
import { draftMode } from "next/headers";
import { client } from "./client";

+const DEFAULT_PARAMS = {} as QueryParams;
+const DEFAULT_TAGS = [] as string[];
+
+const token = process.env.SANITY_API_READ_TOKEN;
+const isDevelopment = process.env.NODE_ENV === "development";
+const isDraftMode = draftMode().isEnabled;

export async function sanityFetch<QueryResponse>({
  query,
  params = DEFAULT_PARAMS,
  tags = DEFAULT_TAGS,
}: {
  query: string;
  params?: QueryParams;
  tags?: string[];
}): Promise<QueryResponse> {
-  const isDraftMode = draftMode().isEnabled;
  if (isDraftMode && !token) {
    throw new Error(
-      "The `SANITY_API_READ_TOKEN` environment variable is required.",
+      "The `SANITY_API_READ_TOKEN` environment variable is required to fetch data in draft mode.",
    );
  }
-  const isDevelopment = process.env.NODE_ENV === "development";

  return client
    .withConfig({ useCdn: true })
    .fetch<QueryResponse>(query, params, {
      cache: isDevelopment || isDraftMode ? undefined : "force-cache",
      ...(isDraftMode && {
        token: token,
        perspective: "previewDrafts",
      }),
      next: {
        ...(isDraftMode && { revalidate: 30 }),
        tags,
      },
    });
}
apps/web/sanity/schemaTypes/postType.ts (1)

4-65: LGTM!

The code changes are approved. The schema type is well-defined and covers the essential fields for a blog post.

Consider adding a field for SEO metadata (title, description, keywords) to optimize the blog post for search engines. You can define a new object type for SEO metadata and reference it in the post type. For example:

const seoMetadata = defineType({
  name: 'seoMetadata',
  type: 'object',
  fields: [
    defineField({
      name: 'title',
      type: 'string',
    }),
    defineField({
      name: 'description',
      type: 'text',
    }),
    defineField({
      name: 'keywords',
      type: 'array',
      of: [{ type: 'string' }],
    }),
  ],
});

// In the post type
defineField({
  name: 'seo',
  type: 'seoMetadata',
}),
apps/web/package.json (5)

49-49: Use a version constraint that allows patch and minor updates.

Consider using a version constraint like ^1.0.0 instead of 1 for the @sanity/image-url dependency. This allows patch and minor updates while ensuring the major version remains the same, reducing the risk of breakage due to major version changes.

-    "@sanity/image-url": "1",
+    "@sanity/image-url": "^1.0.0",

50-50: Use a version constraint that allows patch and minor updates.

Consider using a version constraint like ^3.0.0 instead of 3 for the @sanity/vision dependency. This allows patch and minor updates while ensuring the major version remains the same, reducing the risk of breakage due to major version changes.

-    "@sanity/vision": "3",
+    "@sanity/vision": "^3.0.0",

88-88: Use a version constraint that allows patch and minor updates.

Consider using a version constraint like ^9.0.0 instead of 9 for the next-sanity dependency. This allows patch and minor updates while ensuring the major version remains the same, reducing the risk of breakage due to major version changes.

-    "next-sanity": "9",
+    "next-sanity": "^9.0.0",

105-105: Use a version constraint that allows patch and minor updates.

Consider using a version constraint like ^3.0.0 instead of 3 for the sanity dependency. This allows patch and minor updates while ensuring the major version remains the same, reducing the risk of breakage due to major version changes.

-    "sanity": "3",
+    "sanity": "^3.0.0",

108-108: Use a version constraint that allows patch and minor updates.

Consider using a version constraint like ^6.0.0 instead of 6 for the styled-components dependency. This allows patch and minor updates while ensuring the major version remains the same, reducing the risk of breakage due to major version changes.

-    "styled-components": "6",
+    "styled-components": "^6.0.0",
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9825ee3 and c65bacc.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (17)
  • apps/web/app/blog/page.tsx (3 hunks)
  • apps/web/app/studio/[[...tool]]/page.tsx (1 hunks)
  • apps/web/package.json (3 hunks)
  • apps/web/sanity.cli.ts (1 hunks)
  • apps/web/sanity.config.ts (1 hunks)
  • apps/web/sanity/env.ts (1 hunks)
  • apps/web/sanity/lib/client.ts (1 hunks)
  • apps/web/sanity/lib/fetch.ts (1 hunks)
  • apps/web/sanity/lib/image.ts (1 hunks)
  • apps/web/sanity/lib/queries.ts (1 hunks)
  • apps/web/sanity/schemaTypes/authorType.ts (1 hunks)
  • apps/web/sanity/schemaTypes/blockContentType.ts (1 hunks)
  • apps/web/sanity/schemaTypes/categoryType.ts (1 hunks)
  • apps/web/sanity/schemaTypes/index.ts (1 hunks)
  • apps/web/sanity/schemaTypes/postType.ts (1 hunks)
  • apps/web/sanity/structure.ts (1 hunks)
  • apps/web/tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/web/sanity.cli.ts
Additional context used
Biome
apps/web/sanity/schemaTypes/index.ts

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

apps/web/sanity/lib/image.ts

[error] 1-2: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

apps/web/sanity/structure.ts

[error] 15-15: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

Additional comments not posted (30)
apps/web/sanity/lib/client.ts (1)

1-10: LGTM!

The code changes are approved for the following reasons:

  • The file is correctly creating and exporting a Sanity client using the createClient function from the next-sanity library.
  • The client is configured using the projectId, dataset, and apiVersion variables imported from ../env, which is a good practice to keep the configuration separate from the code.
  • The useCdn option is set to true, which is appropriate for most use cases. The comment provides clear guidance on when to set it to false.
  • The file is small and focused, following the Single Responsibility Principle.
apps/web/sanity/schemaTypes/index.ts (1)

8-10: LGTM!

The schema object is correctly defined and exported.

apps/web/sanity/lib/image.ts (1)

1-11: LGTM!

The code changes are approved.

Tools
Biome

[error] 1-2: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

apps/web/tsconfig.json (1)

10-10: LGTM!

The code change is approved.

apps/web/sanity/schemaTypes/categoryType.ts (4)

1-2: LGTM!

The import statements are correct and necessary for defining the schema type.


4-8: LGTM!

The categoryType constant is correctly defined using the defineType function from Sanity. The name, title, type, and icon are appropriately set for a category schema type.


10-20: LGTM!

The title and slug fields are correctly defined using the defineField function from Sanity. The slug field is appropriately configured to generate the slug from the title field.


21-24: LGTM!

The description field is correctly defined using the defineField function from Sanity.

apps/web/sanity/env.ts (3)

1-2: Verify the default value for apiVersion.

The default value for apiVersion is set to "2024-09-03", which seems to be a future date. Please ensure that this is the intended default value.


4-7: LGTM!

The code changes are approved.


9-20: LGTM!

The code changes are approved.

apps/web/sanity/lib/queries.ts (3)

4-11: LGTM!

The postsQuery looks good and is fetching relevant fields for displaying a list of posts. The computed fields imageURL and authorName are correctly fetching fields from the referenced documents.


14-16: LGTM!

The postQuery looks good and is fetching relevant fields for displaying a single post. The [0] at the end of the query is correctly ensuring that only the first matching document is returned.


19-21: LGTM!

The postPathsQuery looks good and is correctly fetching the slug.current field for generating dynamic paths for post pages. The defined() function is ensuring that only documents with a defined slug.current field are returned.

apps/web/sanity/structure.ts (1)

1-17: LGTM!

The file is well-structured and follows the Sanity Studio structure builder cheat sheet. The code changes are approved with the minor change to remove the non-null assertion operator.

Tools
Biome

[error] 15-15: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

apps/web/app/studio/[[...tool]]/page.tsx (1)

1-19: LGTM!

The code changes are approved. The file is well-structured, follows best practices, and has no apparent issues. The code is clean, easy to understand, and the comments provide a clear explanation of the file's purpose and functionality. The imports and exports are used correctly, and the NextStudio component is used with the correct configuration.

apps/web/sanity.config.ts (2)

7-14: LGTM!

The imports are correctly used in the file to configure Sanity Studio.


16-28: LGTM!

The configuration object for Sanity Studio is correctly defined with the following properties:

  • basePath: The base path for the Sanity Studio.
  • projectId: The project ID for the Sanity project.
  • dataset: The dataset to use for the Sanity project.
  • schema: The schema definition for the Sanity project.
  • plugins: An array of plugins to use in the Sanity Studio.

The configuration object is using good practices such as:

  • Keeping the configuration separate from the code by importing the projectId and dataset from ./sanity/env.
  • Keeping the schema definition separate from the configuration by importing the schema from ./sanity/schemaTypes.
  • Using the structureTool plugin to configure the structure of the Sanity Studio.
  • Using the visionTool plugin to query the data using GROQ from inside the Sanity Studio.
apps/web/sanity/schemaTypes/authorType.ts (1)

4-46: LGTM!

The schema definition for the author type is well-structured and follows the Sanity schema definition conventions. The field types are appropriately chosen for their respective purposes, and the preview configuration provides a meaningful preview of the author document in the Sanity Studio.

apps/web/sanity/schemaTypes/postType.ts (1)

1-3: LGTM!

The code changes are approved.

apps/web/sanity/schemaTypes/blockContentType.ts (3)

1-2: LGTM!

The code changes are approved.


4-13: LGTM!

The code changes are approved.


15-76: LGTM!

The code changes are approved.

apps/web/package.json (2)

47-47: LGTM!

The @sanity/client dependency is required for interacting with the Sanity APIs. The version constraint looks good.


48-48: LGTM!

The @sanity/icons dependency is useful for integrating Sanity's icons into the project. The version constraint looks good.

apps/web/app/blog/page.tsx (5)

3-8: LGTM!

The code changes are approved.


10-17: LGTM!

The code changes are approved.


191-195: LGTM!

The code changes are approved.


Line range hint 200-230: LGTM!

The code changes are approved.


239-287: LGTM!

The code changes are approved.

Comment on lines +1 to +6
import { type SchemaTypeDefinition } from "sanity";

import { blockContentType } from "./blockContentType";
import { categoryType } from "./categoryType";
import { postType } from "./postType";
import { authorType } from "./authorType";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use import type for type-only imports.

The imports are only used as types. Using import type ensures that the imports are removed by the transpilers and avoids loading unnecessary modules.

Apply this diff to use import type:

-import { type SchemaTypeDefinition } from "sanity";
+import type { SchemaTypeDefinition } from "sanity";
 
-import { blockContentType } from "./blockContentType";
-import { categoryType } from "./categoryType";
-import { postType } from "./postType";
-import { authorType } from "./authorType";
+import type { blockContentType } from "./blockContentType";
+import type { categoryType } from "./categoryType";
+import type { postType } from "./postType";
+import type { authorType } from "./authorType";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { type SchemaTypeDefinition } from "sanity";
import { blockContentType } from "./blockContentType";
import { categoryType } from "./categoryType";
import { postType } from "./postType";
import { authorType } from "./authorType";
import type { SchemaTypeDefinition } from "sanity";
import type { blockContentType } from "./blockContentType";
import type { categoryType } from "./categoryType";
import type { postType } from "./postType";
import type { authorType } from "./authorType";
Tools
Biome

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

Comment on lines +1 to +2
import createImageUrlBuilder from "@sanity/image-url";
import { SanityImageSource } from "@sanity/image-url/lib/types/types";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use import type for the imports that are only used as types.

The imports createImageUrlBuilder and SanityImageSource are only used as types in this file.

Apply this diff to use import type for these imports:

-import createImageUrlBuilder from "@sanity/image-url";
-import { SanityImageSource } from "@sanity/image-url/lib/types/types";
+import type { SanityImageSource } from "@sanity/image-url/lib/types/types";
+import type createImageUrlBuilder from "@sanity/image-url";

Using import type ensures that the imports are removed by the transpilers and avoids loading unnecessary modules.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import createImageUrlBuilder from "@sanity/image-url";
import { SanityImageSource } from "@sanity/image-url/lib/types/types";
import type { SanityImageSource } from "@sanity/image-url/lib/types/types";
import type createImageUrlBuilder from "@sanity/image-url";
Tools
Biome

[error] 1-2: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

...S.documentTypeListItems().filter(
(item) =>
item.getId() &&
!["post", "category", "author"].includes(item.getId()!),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the non-null assertion operator.

The non-null assertion operator (!) is unnecessary and can be removed.

Apply this diff to remove the non-null assertion operator:

-         !["post", "category", "author"].includes(item.getId()!),
+         !["post", "category", "author"].includes(item.getId()),
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
!["post", "category", "author"].includes(item.getId()!),
!["post", "category", "author"].includes(item.getId()),
Tools
Biome

[error] 15-15: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

@@ -0,0 +1,28 @@
"use client";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the "use client" directive.

The "use client" directive is used in Next.js 13 to mark a file as a Client Component. However, this file is a configuration file for Sanity Studio and not a React component. Therefore, the directive is not needed and should be removed.

-"use client";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"use client";

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
apps/web/app/blog/page.tsx (1)

4-6: Use import type for type-only imports.

The static analysis tool suggests using import type for the following imports:

-import { sanityFetch } from "@/sanity/lib/fetch";
-import { postsQuery } from "@/sanity/lib/queries";
-import { Post as PostType } from "@/app/blog/types";
+import type { Post as PostType } from "@/app/blog/types";
+import { sanityFetch } from "@/sanity/lib/fetch";
+import { postsQuery } from "@/sanity/lib/queries";

Using import type ensures that the types are removed by the transpilers and avoids loading unnecessary modules.

Tools
Biome

[error] 5-6: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c65bacc and 16ffad2.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (9)
  • apps/web/app/blog/components/Prose.tsx (1 hunks)
  • apps/web/app/blog/page.tsx (3 hunks)
  • apps/web/app/blog/post/[slug]/Post.tsx (1 hunks)
  • apps/web/app/blog/post/[slug]/page.tsx (1 hunks)
  • apps/web/app/blog/types.ts (1 hunks)
  • apps/web/next.config.mjs (1 hunks)
  • apps/web/package.json (4 hunks)
  • apps/web/sanity/lib/queries.ts (1 hunks)
  • apps/web/sanity/schemaTypes/postType.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/web/app/blog/components/Prose.tsx
Files skipped from review as they are similar to previous changes (3)
  • apps/web/package.json
  • apps/web/sanity/lib/queries.ts
  • apps/web/sanity/schemaTypes/postType.ts
Additional context used
Biome
apps/web/app/blog/types.ts

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

apps/web/app/blog/post/[slug]/page.tsx

[error] 16-16: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

apps/web/app/blog/page.tsx

[error] 5-6: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

Additional comments not posted (14)
apps/web/app/blog/types.ts (1)

3-15: LGTM!

The Post type definition clearly defines the structure of a blog post with appropriate types for each property. The optional properties are correctly marked with | null.

apps/web/app/blog/post/[slug]/page.tsx (3)

1-5: LGTM!

The code changes are approved.


7-7: LGTM!

The code changes are approved.


9-12: LGTM!

The code changes are approved.

apps/web/app/blog/post/[slug]/Post.tsx (5)

1-10: LGTM!

The imports and type definitions are good:

  • The "use client" directive is used correctly for a client component.
  • The necessary dependencies are imported, including Next.js Image component, Sanity client, and custom components.
  • The custom Post type improves type safety.

11-11: LGTM!

The builder constant is correctly set up using the imageUrlBuilder function from the Sanity library. It will be used later in the component to generate image URLs.


13-35: LGTM!

The Post component is well-structured and properly renders the blog post:

  • It takes a post prop of type PostType to receive the post data.
  • It uses the BasicLayout component for consistent layout.
  • The post title, description, and body are rendered within the Prose component.

21-28: LGTM!

The image rendering logic is implemented correctly:

  • It conditionally renders the image only if post.mainImage exists.
  • The builder is used to generate the image URL with the specified width and height.
  • The alt text is set using post.mainImage.alt for accessibility.

29-29: LGTM!

The portable text rendering is implemented correctly:

  • It conditionally renders the post.body only if it exists.
  • The PortableText component from the @portabletext/react library is used to render the rich text content from Sanity.
apps/web/next.config.mjs (1)

38-41: LGTM!

The code changes are approved.

Adding the "cdn.sanity.io" domain to the images.domains array allows images to be served from Sanity, a headless CMS. This change aligns with the PR objective of adding a Sanity blog and enables the application to fetch and display images stored in Sanity.

By specifying the protocol as "https", the configuration ensures that images are securely loaded over HTTPS, which is a best practice for web applications.

Overall, this is a necessary configuration change to support the integration with Sanity for the blog functionality.

apps/web/app/blog/page.tsx (4)

8-15: LGTM!

The Post type definition looks good. It provides a clear structure for the blog post data with fields for title, file, description, date, datetime, and author.


195-199: LGTM!

The changes in the BlogPage component look good:

  • Making it an async function allows for data fetching from Sanity.
  • The sanityFetch function and postsQuery are used correctly to fetch the posts.
  • Passing the fetched posts to the Posts component ensures dynamic rendering of the blog posts.

204-220: LGTM!

The changes in the Posts component look good:

  • Accepting the posts prop allows the component to handle both fetched and static posts.
  • Combining the fetched posts and static posts into allPosts ensures all posts are rendered.
  • Mapping allPosts to PostCard components provides a clean and reusable way to render each post.

243-291: LGTM!

The PostCard component looks good:

  • Extracting the post rendering logic into a separate component improves code organization and reusability.
  • The component correctly handles the post prop and renders the necessary post information.
  • The link to the full post is correctly generated using the post.file field.

@@ -0,0 +1,15 @@
import { PortableTextBlock } from "next-sanity";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use import type for type-only imports.

The PortableTextBlock import is only used as a type.

Use import type to ensure that the import is removed by the transpilers and avoids loading unnecessary modules:

-import { PortableTextBlock } from "next-sanity";
+import type { PortableTextBlock } from "next-sanity";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { PortableTextBlock } from "next-sanity";
import type { PortableTextBlock } from "next-sanity";
Tools
Biome

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

Comment on lines 16 to 19
export default async function Page({ params }: { params: any }) {
const post = await sanityFetch<PostType>({ query: postQuery, params });

return <Post post={post} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the any type for the params prop.

The static analysis tool Biome has flagged an error for using any type for the params prop.

any disables many type checking rules. Its use should be avoided.

You can fix this by specifying a more specific type for the params prop.

For example, you can define a type for the params prop like this:

type PageParams = {
  slug: string;
};

Then, update the Page component to use the PageParams type:

-export default async function Page({ params }: { params: any }) {
+export default async function Page({ params }: { params: PageParams }) {
Tools
Biome

[error] 16-16: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16ffad2 and 0c558f5.

Files selected for processing (1)
  • apps/web/app/blog/post/[slug]/page.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/blog/post/[slug]/page.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
apps/web/.env.example (1)

88-90: LGTM!

The code changes are approved. The commented-out environment variables are correctly defined and follow the naming convention for environment variables.

Consider adding a comment above the commented-out variables to provide more context about their intended purpose and usage. For example:

+# Environment variables for configuring Sanity Studio (uncomment and set values when needed)
# SANITY_STUDIO_PROJECT_ID=
# SANITY_STUDIO_DATASET=production
# SANITY_STUDIO_HOST=
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0c558f5 and 1cdfcf1.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (11)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • apps/web/.env.example (1 hunks)
  • apps/web/package.json (4 hunks)
  • apps/web/tsconfig.json (1 hunks)
  • package.json (1 hunks)
  • packages/eslint-config/package.json (1 hunks)
  • packages/loops/package.json (1 hunks)
  • packages/resend/package.json (1 hunks)
  • packages/tinybird-ai-analytics/package.json (1 hunks)
  • packages/tinybird/package.json (1 hunks)
Files skipped from review due to trivial changes (4)
  • .gitignore
  • packages/eslint-config/package.json
  • packages/tinybird-ai-analytics/package.json
  • packages/tinybird/package.json
Files skipped from review as they are similar to previous changes (1)
  • apps/web/package.json
Additional context used
LanguageTool
README.md

[grammar] ~174-~174: The word ‘deploy’ is a verb. Did you mean the noun “deployment” (= release, placement)?
Context: ...`` Set the following .env vars for the deploy to work: ```sh SANITY_STUDIO_PROJECT_I...

(PREPOSITION_VERB)

Additional comments not posted (17)
packages/loops/package.json (2)

9-9: LGTM!

The update to the @types/node dependency looks good.


6-6: Verify the impact of the loops dependency version update.

Ensure that the version update from ^3.1.1 to ^3.2.0 is compatible with the existing codebase and does not introduce any breaking changes.

Run the following script to verify the usage of the loops package:

packages/resend/package.json (4)

9-9: LGTM!

The minor version update for @react-email/components dependency is approved.


17-17: LGTM!

The patch version update for @types/node dev dependency is approved.


18-18: LGTM!

The patch version update for @types/react dev dependency is approved.


13-13: Verify the impact of the major version update.

Ensure that the codebase is compatible with the breaking changes introduced in react-email version 3.0.1.

Run the following script to verify the usage of react-email in the codebase:

apps/web/tsconfig.json (2)

8-12: LGTM!

The code changes are approved.


13-13: LGTM!

The code changes are approved.

package.json (7)

16-16: LGTM!

The minor version update to @biomejs/biome is approved.


20-20: LGTM!

The major version update to husky is approved.


21-21: LGTM!

The patch version update to lint-staged is approved.


23-23: LGTM!

The minor version update to turbo is approved.


25-25: LGTM!

The minor version update to the package manager pnpm is approved.


17-17: Verify the impact of the major version update to @turbo/gen.

Ensure that the update does not introduce any breaking changes that affect the application.

Run the following script to verify the dependency usage:


18-18: Verify the impact of the major version update to eslint and ensure linting compliance.

  1. Ensure that the update does not introduce any breaking changes that affect the application.
  2. Run the linter to ensure that the codebase complies with the updated linting rules.

Run the following script to verify the dependency usage and linting compliance:

apps/web/.env.example (1)

85-86: LGTM!

The code changes are approved. The new environment variables are correctly defined and follow the naming convention for public environment variables in Next.js.

README.md (1)

166-179: LGTM!

The new "Blog" section in the README provides clear instructions for deploying Sanity Studio and specifies the required environment variables. This is a valuable addition to the documentation.

Tools
LanguageTool

[grammar] ~174-~174: The word ‘deploy’ is a verb. Did you mean the noun “deployment” (= release, placement)?
Context: ...`` Set the following .env vars for the deploy to work: ```sh SANITY_STUDIO_PROJECT_I...

(PREPOSITION_VERB)

@elie222 elie222 merged commit 8c0b69d into main Sep 4, 2024
2 checks passed
@elie222 elie222 deleted the sanity-blog branch September 4, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant