Skip to content

Commit

Permalink
feat: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Dec 19, 2024
1 parent 9642f90 commit d28b2b0
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 434 deletions.
7 changes: 7 additions & 0 deletions .env.test.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
###############################################################################
# The following environment variables are used to run Playwright tests.
# Create a specific account for testing to avoid issues.
###############################################################################

# The email address for your Prismic account.
PLAYWRIGHT_PRISMIC_EMAIL=
# The password to your Prismic account.
PLAYWRIGHT_PRISMIC_PASSWORD=
10 changes: 8 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# custom
dist
example/**/package-lock.json
example/**/.next
examples/**/package-lock.json
*.tgz
CHANGELOG.md
e2e-projects/**/.next

# os
.DS_Store
Expand Down Expand Up @@ -38,3 +39,8 @@ coverage
!.vscode/tasks.json
!.vscode/launch.json
*.code-workspace
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/tests/.storage-state.json
484 changes: 81 additions & 403 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

Helpers to integrate Prismic into Next.js apps.

- 👁️  Easily set up Prismic Preview
- 🖼️  Render optimized images using [`next/image`][next-image] and Prismic's built-in [Imgix][imgix] integration
- 👁️  Easily set up Prismic previews
- 👁️  Render Prismic links with [`next/link`][next-link]
- 🖼️  Optimize Prismic images using [`next/image`][next-image] and Prismic's built-in [Imgix][imgix] integration

## Install

Expand Down Expand Up @@ -58,7 +59,8 @@ For more clarity on this project and its structure you can also check out the de

[prismic]: https://prismic.io
[imgix]: https://imgix.com/
[next-image]: https://nextjs.org/docs/basic-features/image-optimization
[next-link]: https://nextjs.org/docs/app/api-reference/components/link
[next-image]: https://nextjs.org/docs/app/api-reference/components/image

<!-- TODO: Replace link with a more useful one if available -->

Expand Down
8 changes: 2 additions & 6 deletions messages/replace-createLocaleRedirect.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ The function should be removed from Next.js projects to ensure the best possible
"fr-fr": "fr",
};

/**
* Creates a redirect with an auto-detected locale prepended to the URL.
*/
/** Creates a redirect with an auto-detected locale prepended to the URL. */
export function createLocaleRedirect(request: NextRequest): Response {
const headers = {
"accept-language": request.headers.get("accept-language"),
Expand All @@ -49,9 +47,7 @@ The function should be removed from Next.js projects to ensure the best possible
return Response.redirect(request.nextUrl);
}

/**
* Determines if a pathname has a locale as its first segment.
*/
/** Determines if a pathname has a locale as its first segment. */
export function pathnameHasLocale(request: NextRequest): boolean {
const regexp = new RegExp(`^/(${Object.values(LOCALES).join("|")})(\/|$)`);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"release:alpha:dry": "standard-version --release-as minor --prerelease alpha --dry-run",
"release:dry": "standard-version --dry-run",
"size": "size-limit",
"test": "npm run lint && npm run types && npm run build && npm run size && npm run e2e",
"test": "npm run lint && npm run types && npm run build && npm run e2e && npm run size && npm run e2e",
"types": "tsc --noEmit",
"e2e": "playwright test",
"e2e:ui": "npm run e2e -- --ui"
Expand Down
8 changes: 4 additions & 4 deletions src/PrismicNextImage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use client";

import { ReactElement } from "react";
import Image, { ImageProps } from "next/image";
import { buildURL, ImgixURLParams } from "imgix-url-builder";
import * as prismic from "@prismicio/client";
import { ImageFieldImage, isFilled } from "@prismicio/client";
import { DEV } from "esm-env";

import { devMsg } from "./lib/devMsg.js";

import { imgixLoader } from "./imgixLoader.js";
import { ReactElement } from "react";

const castInt = (input: string | number | undefined): number | undefined => {
if (typeof input === "number" || typeof input === "undefined") {
Expand All @@ -29,7 +29,7 @@ export type PrismicNextImageProps = Omit<
"src" | "alt" | "loader"
> & {
/** The Prismic Image field or thumbnail to render. */
field: prismic.ImageFieldImage | null | undefined;
field: ImageFieldImage | null | undefined;

/**
* An object of Imgix URL API parameters to transform the image.
Expand Down Expand Up @@ -110,7 +110,7 @@ export const PrismicNextImage = ({
}
}

if (prismic.isFilled.imageThumbnail(field)) {
if (isFilled.imageThumbnail(field)) {
const resolvedImgixParams = imgixParams;
for (const x in imgixParams) {
if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
Expand Down
28 changes: 17 additions & 11 deletions src/PrismicNextLink.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
import * as React from "react";
import * as prismic from "@prismicio/client";
import { ComponentProps, ReactElement, forwardRef } from "react";
import Link from "next/link";
import {
AsLinkAttrsConfig,
LinkField,
LinkResolverFunction,
PrismicDocument,
asLinkAttrs,
} from "@prismicio/client";

export type PrismicNextLinkProps = Omit<
React.ComponentProps<typeof Link>,
ComponentProps<typeof Link>,
"field" | "document" | "href" | "rel"
> & {
linkResolver?: prismic.LinkResolverFunction;
rel?: string | prismic.AsLinkAttrsConfig["rel"];
linkResolver?: LinkResolverFunction;
rel?: string | AsLinkAttrsConfig["rel"];
} & (
| {
field: prismic.LinkField | null | undefined;
field: LinkField | null | undefined;
document?: never;
href?: never;
}
| {
field?: never;
document: prismic.PrismicDocument | null | undefined;
document: PrismicDocument | null | undefined;
href?: never;
}
| {
field?: never;
document?: never;
href: React.ComponentProps<typeof Link>["href"];
href: ComponentProps<typeof Link>["href"];
}
);

export const PrismicNextLink = React.forwardRef<
export const PrismicNextLink = forwardRef<
HTMLAnchorElement,
PrismicNextLinkProps
>(function PrismicNextLink(props, ref): React.ReactElement | null {
>(function PrismicNextLink(props, ref): ReactElement | null {
const { field, document, linkResolver, children, ...restProps } = props;
const {
href: computedHref,
rel: computedRel,
...attrs
} = prismic.asLinkAttrs(field ?? document, {
} = asLinkAttrs(field ?? document, {
linkResolver,
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
});
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export { imgixLoader } from "./imgixLoader.js";

export type { CreateClientConfig } from "./types.js";

export { createLocaleRedirect } from "./removed.js";
export type { CreateLocaleRedirectConfig } from "./removed.js";
export { createLocaleRedirect } from "./createLocaleRedirect.js";
export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect.js";
4 changes: 2 additions & 2 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export type { SetPreviewDataConfig } from "./setPreviewData.js";

export type { CreateClientConfig } from "./types.js";

export { createLocaleRedirect } from "../removed.js";
export type { CreateLocaleRedirectConfig } from "../removed.js";
export { createLocaleRedirect } from "../createLocaleRedirect.js";
export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect.js";

0 comments on commit d28b2b0

Please sign in to comment.