prefix stringlengths 512 512 | suffix stringlengths 256 256 | middle stringlengths 14 229 | meta dict |
|---|---|---|---|
e: https://www.datocms.com/blog/offer-responsive-progressive-lqip-images-in-2020
const responsiveImageFragment = `
fragment responsiveImageFragment on ResponsiveImage {
srcSet
webpSrcSet
sizes
src
width
height
aspectRatio
alt
title
bgColor
base64
}
`;
async function fetchA... | to fetch API");
}
return json.data;
}
export async function getPreviewPostBySlug(slug) {
const data = await fetchAPI(
`
query PostBySlug($slug: String) {
post(filter: {slug: {eq: $slug}}) {
slug
}
}`,
{
pre | uthorization: `Bearer ${API_TOKEN}`,
},
body: JSON.stringify({
query,
variables,
}),
});
const json = await res.json();
if (json.errors) {
console.error(json.errors);
throw new Error("Failed | {
"filepath": "examples/cms-datocms/lib/api.js",
"language": "javascript",
"file_size": 3154,
"cut_index": 614,
"middle_length": 229
} |
tar from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
export default function PostPreview({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<div>
<div className="mb-5">
<CoverImage
slug={slug}
... | rline">
{title}
</Link>
</h3>
<div className="text-lg mb-4">
<Date dateString={date} />
</div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
<Avatar name={author.name} picture={author.pict | me="hover:unde | {
"filepath": "examples/cms-datocms/components/post-preview.js",
"language": "javascript",
"file_size": 818,
"cut_index": 522,
"middle_length": 14
} |
c function preview(req, res) {
// Check the secret and next parameters
// This secret should only be known to this API route and the CMS
if (
req.query.secret !== process.env.DATOCMS_PREVIEW_SECRET ||
!req.query.slug
) {
return res.status(401).json({ message: "Invalid token" });
}
// Fetch the ... | valid slug" });
}
// Enable Draft Mode by setting the cookie
res.setDraftMode({ enable: true });
// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writ | st) {
return res.status(401).json({ message: "In | {
"filepath": "examples/cms-datocms/pages/api/preview.js",
"language": "javascript",
"file_size": 954,
"cut_index": 582,
"middle_length": 52
} |
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
container: {
screens: {
sm: "640px",
md: "768px",
lg: "1024px",
xl: "1280px",
},
},
colors: {
"accent-1": "#FAFAFA",
"accent-2": "#EAEAEA",
"accent-7": "... | "5xl": "2.5rem",
"6xl": "2.75rem",
"7xl": "4.5rem",
"8xl": "6.25rem",
},
boxShadow: {
small: "0 5px 10px rgba(0, 0, 0, 0.12)",
medium: "0 8px 30px rgba(0, 0, 0, 0.12)",
},
},
},
variant | {
tight: 1.2,
},
fontSize: {
| {
"filepath": "examples/cms-dotcms/tailwind.config.js",
"language": "javascript",
"file_size": 968,
"cut_index": 582,
"middle_length": 52
} |
Container from "./container";
import cn from "classnames";
import { EXAMPLE_PATH } from "@lib/constants";
export default function Alert({ preview }) {
return (
<div
className={cn("border-b", {
"bg-accent-7 border-accent-7 text-white": preview,
"bg-accent-1 border-accent-2": !preview,
... | </>
) : (
<>
The source code for this blog is{" "}
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
className="underline hover:text-success | href="/api/exit-preview"
className="underline hover:text-cyan duration-200 transition-colors"
>
Click here
</a>{" "}
to exit preview mode.
| {
"filepath": "examples/cms-dotcms/components/alert.tsx",
"language": "tsx",
"file_size": 1204,
"cut_index": 518,
"middle_length": 229
} |
mport Avatar from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
export default function HeroPost({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<section>
<div className="mb-8 md:mb-16">
<CoverImage
... | <div className="mb-4 md:mb-0 text-lg">
<Date dateString={date} />
</div>
</div>
<div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
<Avatar name={author.name} picture={author.picture} /> | :mb-28">
<div>
<h3 className="mb-4 text-4xl lg:text-6xl leading-tight">
<Link href={`/posts/${slug}`} className="hover:underline">
{title}
</Link>
</h3>
| {
"filepath": "examples/cms-datocms/components/hero-post.js",
"language": "javascript",
"file_size": 1049,
"cut_index": 513,
"middle_length": 229
} |
vatar";
import Date from "./date";
import CoverImage from "./cover-image";
import PostTitle from "./post-title";
export default function PostHeader({ title, coverImage, date, author }) {
return (
<>
<PostTitle>{title}</PostTitle>
<div className="hidden md:block md:mb-12">
<Avatar name={author... | -2xl mx-auto">
<div className="block md:hidden mb-6">
<Avatar name={author.name} picture={author.picture} />
</div>
<div className="mb-6 text-lg">
<Date dateString={date} />
</div>
</div>
</>
|
/>
</div>
<div className="max-w | {
"filepath": "examples/cms-datocms/components/post-header.js",
"language": "javascript",
"file_size": 848,
"cut_index": 535,
"middle_length": 52
} |
orPage from "next/error";
import Container from "@/components/container";
import PostBody from "@/components/post-body";
import MoreStories from "@/components/more-stories";
import Header from "@/components/header";
import PostHeader from "@/components/post-header";
import SectionSeparator from "@/components/section-se... | ?.slug) {
return <ErrorPage statusCode={404} />;
}
return (
<Layout preview={preview}>
<Container>
<Header />
{router.isFallback ? (
<PostTitle>Loading…</PostTitle>
) : (
<>
<article | t/head";
import { CMS_NAME } from "@/lib/constants";
import markdownToHtml from "@/lib/markdownToHtml";
export default function Post({ post, morePosts, preview }) {
const router = useRouter();
if (!router.isFallback && !post | {
"filepath": "examples/cms-datocms/pages/posts/[slug].js",
"language": "javascript",
"file_size": 2278,
"cut_index": 563,
"middle_length": 229
} |
bject} param1.variables - The variables to pass to the query
* @param {Object} param1.preview - Indicate if the query should be previewed
* @returns {Promise} - A promise that resolves to the result of the query
*/
async function fetchAPI(query, { variables } = { variables: null }) {
const res = await fetch(
p... | tch API");
}
return json.data;
}
/**
* Get the correct type to filter post using preview flag
*
* @param preview
* @returns {string}
*/
const showPreviewPosts = (preview) => {
return preview === true
? "+working:true +deleted:false"
: | TCMS_TOKEN}`,
},
body: JSON.stringify({
query,
variables,
}),
},
);
const json = await res.json();
if (json.errors) {
console.error(json.errors);
throw new Error("Failed to fe | {
"filepath": "examples/cms-dotcms/lib/api.ts",
"language": "typescript",
"file_size": 3816,
"cut_index": 614,
"middle_length": 229
} |
Container from "@/components/container";
import MoreStories from "@/components/more-stories";
import HeroPost from "@/components/hero-post";
import Intro from "@/components/intro";
import Layout from "@/components/layout";
import { getAllPostsForHome } from "@/lib/api";
import Head from "next/head";
import { CMS_NAME ... | ge={heroPost.coverImage}
date={heroPost.date}
author={heroPost.author}
slug={heroPost.slug}
excerpt={heroPost.excerpt}
/>
)}
{morePosts.length > 0 && <MoreStories posts | <title>{`Next.js Blog Example with ${CMS_NAME}`}</title>
</Head>
<Container>
<Intro />
{heroPost && (
<HeroPost
title={heroPost.title}
coverIma | {
"filepath": "examples/cms-datocms/pages/index.js",
"language": "javascript",
"file_size": 1238,
"cut_index": 518,
"middle_length": 229
} |
DotImage,
Heading,
ListItem,
OrderedList,
Paragraph,
TextNode,
} from "./blocks";
/*
dotCMS Block Editor is a new rich content editor that allows you to create your content as building blocks.
More info: https://dotcms.com/docs/latest/block-editor
*/
export const ContentBlocks = ({ content }) => {
r... | .content} />
</Heading>
);
case "bulletList":
return (
<BulletList key={index}>
<ContentBlocks content={data.content} />
</BulletList>
);
ca | ntBlocks content={data.content} />
</Paragraph>
);
case "heading":
return (
<Heading key={index} level={data.attrs.level}>
<ContentBlocks content={data | {
"filepath": "examples/cms-dotcms/components/content-blocks.tsx",
"language": "tsx",
"file_size": 2226,
"cut_index": 563,
"middle_length": 229
} |
Container from "./container";
import { EXAMPLE_PATH } from "@lib/constants";
export default function Footer() {
return (
<footer className="bg-accent-1 border-t border-accent-2">
<Container>
<div className="py-28 flex flex-col lg:flex-row items-center">
<h3 className="text-4xl lg:text-5x... | border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
>
Read Documentation
</a>
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${ | ex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
<a
href="https://nextjs.org/docs/basic-features/pages"
className="mx-3 bg-black hover:bg-white hover:text-black border | {
"filepath": "examples/cms-dotcms/components/footer.tsx",
"language": "tsx",
"file_size": 1208,
"cut_index": 518,
"middle_length": 229
} |
URL } from "@lib/constants";
export default function Intro() {
return (
<section className="flex-col md:flex-row flex items-center md:justify-between mt-16 mb-16 md:mb-12">
<h1 className="text-6xl md:text-8xl font-bold tracking-tighter leading-tight md:pr-8">
Blog.
</h1>
<h4 className="... | Next.js
</a>{" "}
and{" "}
<a
href={CMS_URL}
className="underline hover:text-success duration-200 transition-colors"
>
{CMS_NAME}
</a>
.
</h4>
</section>
);
| -success duration-200 transition-colors"
>
| {
"filepath": "examples/cms-dotcms/components/intro.tsx",
"language": "tsx",
"file_size": 845,
"cut_index": 535,
"middle_length": 52
} |
from "next/head";
import { CMS_NAME, HOME_OG_IMAGE_URL } from "@lib/constants";
export default function Meta() {
return (
<Head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
... | avicon.ico" />
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#000" />
<link rel="alternate" type="application/rs | />
<link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<link rel="shortcut icon" href="/favicon/f | {
"filepath": "examples/cms-dotcms/components/meta.tsx",
"language": "tsx",
"file_size": 1253,
"cut_index": 524,
"middle_length": 229
} |
ort Link from "next/link";
import Avatar from "@components/avatar";
import DateComponent from "@components/date";
import CoverImage from "./cover-image";
export default function PostPreview({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<div>
<div className="mb-5">
<Cov... | assName="mb-4 text-lg">
<DateComponent dateString={date} />
</div>
) : null}
<p className="mb-4 text-lg leading-relaxed">{excerpt}</p>
{author.length ? (
<Avatar
name={`${author[0].firstName} ${author[0 |
/>
</div>
<h3 className="mb-3 text-3xl leading-snug">
<Link href={`/posts/${slug}`} className="hover:underline">
{title}
</Link>
</h3>
{date !== "now" ? (
<div cl | {
"filepath": "examples/cms-dotcms/components/post-preview.tsx",
"language": "tsx",
"file_size": 1102,
"cut_index": 515,
"middle_length": 229
} |
function preview(req, res) {
const { secret, slug } = req.query;
if (secret !== process.env.DOTCMS_PREVIEW_SECRET || !slug) {
return res.status(401).json({ message: "Invalid token" });
}
// Fetch the headless CMS to check if the provided `slug` exists
const post = await getPreviewPostBySlug(slug, true)... | ode({ enable: true });
// Redirect to the path from the fetched post
const url = `/posts/${post.post.urlTitle}`;
res.setHeader("Content-Type", "text/html");
res.write(
`<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; url=${ur | ble Draft Mode by setting the cookie
res.setDraftM | {
"filepath": "examples/cms-dotcms/pages/api/preview.tsx",
"language": "tsx",
"file_size": 996,
"cut_index": 582,
"middle_length": 52
} |
ort { addTodo } from "./actions";
function Submit() {
const { pending } = useFormStatus();
return (
<button type="submit" aria-disabled={pending} className="sr-only">
Add
</button>
);
}
export function Form() {
const formRef = useRef<HTMLFormElement>(null);
formRef.current?.reset();
retur... | escription"
name="description"
placeholder="Insert new todo"
className="w-full text-black outline-none"
required
aria-label="Description of todo"
type="text"
autoFocus
/>
<Submit />
< | ref={formRef}
>
<input
id="d | {
"filepath": "examples/with-turso/app/form.tsx",
"language": "tsx",
"file_size": 928,
"cut_index": 606,
"middle_length": 52
} |
nk";
import Avatar from "@components/avatar";
import DateComponent from "@components/date";
import CoverImage from "@components/cover-image";
import cn from "classnames";
export default function HeroPost({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<section>
<div className="m... | <div className="md:grid md:grid-cols-2 md:gap-16 lg:col-gap-8 mb-20 md:mb-28">
<div>
<h3 className="mb-4 text-4xl leading-tight lg:text-6xl">
<Link
as={`/posts/${slug}`}
href="/posts/[slug]"
| src={coverImage.idPath}
alt={`Cover Image for ${title}`}
className={cn("shadow-small", {
"hover:shadow-medium transition-shadow duration-200": slug,
})}
/>
</div>
| {
"filepath": "examples/cms-dotcms/components/hero-post.tsx",
"language": "tsx",
"file_size": 1591,
"cut_index": 537,
"middle_length": 229
} |
d from "next/head";
import ErrorPage from "next/error";
import Container from "@components/container";
import MoreStories from "@components/more-stories";
import Header from "@components/header";
import PostHeader from "@components/post-header";
import PostBody from "@components/post-body";
import SectionSeparator from... | title = `${
post?.title || "dotcms"
} | Next.js Blog Example with ${CMS_NAME}`;
return (
<Layout preview={preview}>
<Container>
<Header />
{router.isFallback ? (
<PostTitle>Loading…</PostTitle>
) : (
| ug, getPostAndMorePosts } from "@lib/api";
export default function Post({ post, morePosts, preview }) {
const router = useRouter();
if (!router.isFallback && !post) {
return <ErrorPage statusCode={404} />;
}
const | {
"filepath": "examples/cms-dotcms/pages/posts/[slug].tsx",
"language": "tsx",
"file_size": 2169,
"cut_index": 563,
"middle_length": 229
} |
ContentBlocks } from "./content-blocks";
import DateComponent from "./date";
import Avatar from "./avatar";
export default function PostBody({ content }) {
return (
<div className="prose lg:prose-xl mx-auto max-w-2xl">
<div className="mb-6 block md:hidden">
{content.author.length ? (
<Av... | gDate !== "now" ? (
<div className="mb-6 text-lg">
Posted <DateComponent dateString={content.postingDate} />
</div>
) : null}
</div>
<ContentBlocks content={content.blogContent.json.content} />
</div> | iv className="mb-6 text-lg">
{content.postin | {
"filepath": "examples/cms-dotcms/components/post-body.tsx",
"language": "tsx",
"file_size": 836,
"cut_index": 520,
"middle_length": 52
} |
iner from "@components/container";
import MoreStories from "@components/more-stories";
import HeroPost from "@components/hero-post";
import Intro from "@components/intro";
import Layout from "@components/layout";
import { getAllPostsForHome } from "@lib/api";
import Head from "next/head";
import { CMS_NAME } from "@lib... | eroPost.title}
coverImage={heroPost.image}
date={heroPost.postingDate}
author={heroPost.author}
slug={heroPost.urlTitle}
excerpt={heroPost.teaser}
/>
)}
{ | E}`;
return (
<>
<Layout preview={preview}>
<Head>
<title>{title}</title>
</Head>
<Container>
<Intro />
{heroPost && (
<HeroPost
title={h | {
"filepath": "examples/cms-dotcms/pages/index.tsx",
"language": "tsx",
"file_size": 1288,
"cut_index": 524,
"middle_length": 229
} |
sets a custom webpack configuration to use your Next.js app
// with Sentry.
// https://nextjs.org/docs/app/api-reference/config/next-config-js
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
const { withSentryConfig } = require("@sentry/nextjs");
const moduleExports = {
// Your existing module.export... | hideSourceMaps: true,
},
};
// Make sure adding Sentry options is the last code to run before exporting, to
// ensure that your source maps include changes from all other Webpack plugins
module.exports = withSentryConfig(moduleExports, {
// Additi | // `@sentry/nextjs` version 8.0.0.) See
// https://webpack.js.org/configuration/devtool/ and
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map
// for more information.
| {
"filepath": "examples/with-sentry/next.config.js",
"language": "javascript",
"file_size": 1384,
"cut_index": 524,
"middle_length": 229
} |
This page is loaded by Nextjs:
* - on the server, when data-fetching methods throw or reject
* - on the client, when `getInitialProps` throws or rejects
* - on the client, when a React lifecycle method throws or rejects, and it's
* caught by the built-in Nextjs error boundary
*
* See:
* - https://nextjs.... | mErrorComponent.getInitialProps = async (contextData) => {
// In case this is running in a serverless function, await this in order to give Sentry
// time to send the error before the lambda exits
await Sentry.captureUnderscoreErrorException(contextD | errors-with-an-error-boundary
*/
import * as Sentry from "@sentry/nextjs";
import NextErrorComponent from "next/error";
const CustomErrorComponent = (props) => (
<NextErrorComponent statusCode={props.statusCode} />
);
Custo | {
"filepath": "examples/with-sentry/pages/_error.tsx",
"language": "tsx",
"file_size": 1164,
"cut_index": 518,
"middle_length": 229
} |
s.code}>npx @sentry/wizard -s -i nextjs</code>
</p>
<div>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<I... | height={37}
priority
/>
<div className={styles.thirteen}>
<Image src="/thirteen.svg" alt="13" width={40} height={31} priority />
</div>
</div>
<Image
src="/sentry.svg"
alt="Sentry Logo | />
</a>
</div>
</div>
<div className={styles.center}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js Logo"
width={180}
| {
"filepath": "examples/with-sentry/pages/index.tsx",
"language": "tsx",
"file_size": 10581,
"cut_index": 921,
"middle_length": 229
} |
string,
): Promise<CmsPost[]> {
const graphQLEndpoint = `${process.env.SF_API_URL}graphql`;
const response = await fetch(graphQLEndpoint, {
method: "POST",
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
}).then((x) => x.json());
return response["data"]["posts"];
}... | URL + url.substring(1);
}
return url;
}
function mapCmsBlog(source: CmsPost): PostType {
return {
content: source.content,
excerpt: source.excerpt,
date: source.dateCreated,
slug: source.itemDefaultUrl,
title: source.title,
| blogPosts = await executeGraphQLForBlogPosts(query);
const slugs = blogPosts.map((x) => x.itemDefaultUrl);
return slugs;
}
function transformImageUrl(url: string) {
if (!url.startsWith("http")) {
url = process.env.SF_ | {
"filepath": "examples/cms-sitefinity/lib/api.ts",
"language": "typescript",
"file_size": 3248,
"cut_index": 614,
"middle_length": 229
} |
r from "./avatar";
import DateFormatter from "./date-formatter";
import CoverImage from "./cover-image";
import Link from "next/link";
import type Author from "../interfaces/author";
type Props = {
title: string;
coverImage: string;
date: string;
excerpt: string;
author: Author;
slug: string;
};
const Her... | as={`/posts${slug}`}
href="/posts[slug]"
className="hover:underline"
>
{title}
</Link>
</h3>
<div className="mb-4 md:mb-0 text-lg">
<DateFormatter dateSt | rImage} slug={slug} />
</div>
<div className="md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8 mb-20 md:mb-28">
<div>
<h3 className="mb-4 text-4xl lg:text-5xl leading-tight">
<Link
| {
"filepath": "examples/cms-sitefinity/components/hero-post.tsx",
"language": "tsx",
"file_size": 1280,
"cut_index": 524,
"middle_length": 229
} |
iner from "./container";
import cn from "classnames";
import { EXAMPLE_PATH } from "../lib/constants";
type Props = {
preview?: boolean;
};
const Alert = ({ preview }: Props) => {
return (
<div
className={cn("border-b", {
"bg-neutral-800 border-neutral-800 text-white": preview,
"bg-neutr... | to exit preview mode.
</>
) : (
<>
The source code for this blog is{" "}
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
| view.{" "}
<a
href="/api/exit-preview"
className="underline hover:text-teal-300 duration-200 transition-colors"
>
Click here
</a>{" "}
| {
"filepath": "examples/cms-sitefinity/components/alert.tsx",
"language": "tsx",
"file_size": 1278,
"cut_index": 524,
"middle_length": 229
} |
tter";
import CoverImage from "./cover-image";
import PostTitle from "./post-title";
import type Author from "../interfaces/author";
type Props = {
title: string;
coverImage: string;
date: string;
author: Author;
};
const PostHeader = ({ title, coverImage, date, author }: Props) => {
return (
<>
<... | rImage} />
</div>
<div className="max-w-2xl mx-auto">
<div className="block md:hidden mb-6">
<Avatar name={author.name} picture={author.picture} />
</div>
<div className="mb-6 text-lg">
<DateFormatter | m:mx-0">
<CoverImage title={title} src={cove | {
"filepath": "examples/cms-sitefinity/components/post-header.tsx",
"language": "tsx",
"file_size": 984,
"cut_index": 582,
"middle_length": 52
} |
This file configures the initialization of Sentry on the browser.
// The config you add here will be used whenever a page is visited.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;... | replaysSessionSampleRate: 0.1,
// If the entire session is not sampled, use the below sample rate to sample
// sessions when an error occurs.
replaysOnErrorSampleRate: 1.0,
integrations: [
new Sentry.Replay({
// Additional SDK configur | atic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
// in development and sample at a lower rate in production
| {
"filepath": "examples/with-sentry/sentry.client.config.js",
"language": "javascript",
"file_size": 1102,
"cut_index": 515,
"middle_length": 229
} |
er } from "next/router";
import Code from "../components/Code";
import PageLayout from "../components/PageLayout";
export default function About() {
const t = useTranslations("About");
const { locale } = useRouter();
const intl = useIntl();
const lastUpdated = new Date(2021, 0, 26, 17, 4, 45);
return (
... | atedRelative: intl.formatRelativeTime(lastUpdated),
})}
</p>
</PageLayout>
);
}
export function getStaticProps({ locale }) {
return {
props: {
messages: {
...require(`../messages/shared/${locale}.json`),
... | Updated", {
lastUpdated,
lastUpd | {
"filepath": "examples/with-i18n-next-intl/pages/about.js",
"language": "javascript",
"file_size": 991,
"cut_index": 582,
"middle_length": 52
} |
from "next/head";
import { CMS_NAME, HOME_OG_IMAGE_URL } from "../lib/constants";
const Meta = () => {
return (
<Head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32... | " />
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#000" />
<link rel="alternate" type="application/rss+xml" hre | link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<link rel="shortcut icon" href="/favicon/favicon.ico | {
"filepath": "examples/cms-sitefinity/components/meta.tsx",
"language": "tsx",
"file_size": 1266,
"cut_index": 524,
"middle_length": 229
} |
port PostPreview from "./post-preview";
import type Post from "../interfaces/post";
type Props = {
posts: Post[];
};
const MoreStories = ({ posts }: Props) => {
return (
<section>
<h2 className="mb-8 text-5xl md:text-7xl font-bold tracking-tighter leading-tight">
More Stories
</h2>
<... | title}
coverImage={post.coverImage}
date={post.date}
author={post.author}
slug={post.slug}
excerpt={post.excerpt}
/>
))}
</div>
</section>
);
};
export default MoreS | title={post. | {
"filepath": "examples/cms-sitefinity/components/more-stories.tsx",
"language": "tsx",
"file_size": 792,
"cut_index": 514,
"middle_length": 14
} |
App({ Component, pageProps }) {
return (
<NextIntlProvider
// To achieve consistent date, time and number formatting
// across the app, you can define a set of global formats.
formats={{
dateTime: {
short: {
day: "numeric",
month: "short",
y... | now={new Date(pageProps.now)}
// Also an explicit time zone is helpful to ensure dates render the
// same way on the client as on the server, which might be located
// in a different time zone.
timeZone="Austria/Vienna"
>
| gardless of the server or client environment.
| {
"filepath": "examples/with-i18n-next-intl/pages/_app.js",
"language": "javascript",
"file_size": 950,
"cut_index": 582,
"middle_length": 52
} |
mport Avatar from "./avatar";
import DateFormatter from "./date-formatter";
import CoverImage from "./cover-image";
import Link from "next/link";
import type Author from "../interfaces/author";
type Props = {
title: string;
coverImage: string;
date: string;
excerpt: string;
author: Author;
slug: string;
};... | </Link>
</h3>
<div className="text-lg mb-4">
<DateFormatter dateString={date} />
</div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
<Avatar name={author.name} picture={author.picture} />
</div> | le} src={coverImage} />
</div>
<h3 className="text-3xl mb-3 leading-snug">
<Link
as={`/posts${slug}`}
href="/posts[slug]"
className="hover:underline"
>
{title}
| {
"filepath": "examples/cms-sitefinity/components/post-preview.tsx",
"language": "tsx",
"file_size": 1036,
"cut_index": 513,
"middle_length": 229
} |
Container from "./container";
import { EXAMPLE_PATH } from "../lib/constants";
const Footer = () => {
return (
<footer className="bg-neutral-50 border-t border-neutral-200">
<Container>
<div className="py-28 flex flex-col lg:flex-row items-center">
<h3 className="text-4xl lg:text-[2.5rem... | border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
>
Read Documentation
</a>
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${ | ex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
<a
href="https://nextjs.org/docs/basic-features/pages"
className="mx-3 bg-black hover:bg-white hover:text-black border | {
"filepath": "examples/cms-sitefinity/components/footer.tsx",
"language": "tsx",
"file_size": 1233,
"cut_index": 518,
"middle_length": 229
} |
orPage from "next/error";
import Container from "../../components/container";
import PostBody from "../../components/post-body";
import Header from "../../components/header";
import PostHeader from "../../components/post-header";
import Layout from "../../components/layout";
import { getAllPostSlugsFromCms, getPostBySl... | k && !post?.slug) {
return <ErrorPage statusCode={404} />;
}
return (
<Layout preview={preview}>
<Container>
<Header />
{router.isFallback ? (
<PostTitle>Loading…</PostTitle>
) : (
<>
| ../../interfaces/post";
type Props = {
post: PostType;
morePosts: PostType[];
preview?: boolean;
};
export default function Post({ post, morePosts, preview }: Props) {
const router = useRouter();
if (!router.isFallbac | {
"filepath": "examples/cms-sitefinity/pages/posts/[...slug].tsx",
"language": "tsx",
"file_size": 2170,
"cut_index": 563,
"middle_length": 229
} |
;
import algoliasearch from "algoliasearch/lite";
import type { Hit as AlgoliaHit } from "instantsearch.js";
import React from "react";
import {
Configure,
Highlight,
Hits,
Pagination,
RefinementList,
SearchBox,
} from "react-instantsearch";
import { InstantSearchNext } from "react-instantsearch-nextjs";
... | Hit-label" />
<span className="Hit-price">${hit.price}</span>
</>
);
}
export default function Search() {
return (
<InstantSearchNext
searchClient={searchClient}
indexName={INDEX_NAME}
routing
future={{
pr | 76ff61c053d5f9a3225e2a90f76";
const INDEX_NAME = "instant_search";
const searchClient = algoliasearch(APP_ID, API_KEY);
function Hit({ hit }: HitProps) {
return (
<>
<Highlight hit={hit} attribute="name" className=" | {
"filepath": "examples/with-algolia-react-instantsearch/components/Search.tsx",
"language": "tsx",
"file_size": 1410,
"cut_index": 524,
"middle_length": 229
} |
okie,
deleteCookie,
hasCookie,
} from "cookies-next";
const Home = () => {
const handleSetCookie = () => setCookie("client-cookie", "mock client value");
const handleCheckCookie = () => console.log(hasCookie("client-cookie"));
const handleGetCookie = () => console.log(getCookie("client-cookie"));
const han... | <button onClick={handleCheckCookie}>Check Cookie</button>
<br />
<button onClick={handleGetCookie}>Get Cookie</button>
<br />
<button onClick={handleGetCookies}>Get All Cookies</button>
<br />
<button onClick={handleDe | ndleSetCookie}>Set Cookie</button>
<br />
| {
"filepath": "examples/with-cookies-next/pages/index.tsx",
"language": "tsx",
"file_size": 968,
"cut_index": 582,
"middle_length": 52
} |
"@clerk/nextjs";
import { useEffect, useState } from "react";
import styles from "../styles/Home.module.css";
import "../styles/prism.css";
declare global {
interface Window {
Prism: any;
}
}
const apiSample = `import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";
export async fun... | );
const makeRequest = async () => {
setResponse("// Loading...");
try {
const res = await fetch("/api/getAuthenticatedUserId");
const body = await res.json();
setResponse(JSON.stringify(body, null, " "));
} catch (e) {
| }, { status: 200 })
}`;
export const APIRequest = () => {
useEffect(() => {
if (window.Prism) {
window.Prism.highlightAll();
}
});
const [response, setResponse] = useState("// Click above to run the request" | {
"filepath": "examples/with-clerk/app/api-request.tsx",
"language": "tsx",
"file_size": 2352,
"cut_index": 563,
"middle_length": 229
} |
test";
import path from "path";
// Use process.env.PORT by default and fallback to port 3000
const PORT = process.env.PORT || 3000;
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
const baseURL = `http://localhost:${PORT}`;
// Reference: https://playwright.dev/... | advanced#launching-a-development-web-server-during-the-tests
webServer: {
command: "npm run dev",
url: baseURL,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
use: {
// Use baseURL so to make navigations relative.
| itional 2 times
retries: 2,
// Artifacts folder where screenshots, videos, and traces are stored.
outputDir: "test-results/",
// Run your local dev server before starting the tests:
// https://playwright.dev/docs/test- | {
"filepath": "examples/with-playwright/playwright.config.ts",
"language": "typescript",
"file_size": 2142,
"cut_index": 563,
"middle_length": 229
} |
* @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
colors: {
"accent-1": "#FAFAFA",
"accent-2": "#EAEAEA",
"accent-7": "#333",
success: "#0070f3",
... | "5xl": "2.5rem",
"6xl": "2.75rem",
"7xl": "4.5rem",
"8xl": "6.25rem",
},
boxShadow: {
small: "0 5px 10px rgba(0, 0, 0, 0.12)",
medium: "0 8px 30px rgba(0, 0, 0, 0.12)",
},
},
},
plugins: | tSize: {
| {
"filepath": "examples/cms-ghost/tailwind.config.js",
"language": "javascript",
"file_size": 791,
"cut_index": 514,
"middle_length": 14
} |
om "@tryghost/content-api";
import { GHOST_API_URL_DEFAULT, GHOST_API_KEY_DEFAULT } from "./defaults.js";
const GHOST_API_URL = process.env.GHOST_API_URL || GHOST_API_URL_DEFAULT;
const GHOST_API_KEY = process.env.GHOST_API_KEY || GHOST_API_KEY_DEFAULT;
const api = new GhostContentAPI({
url: GHOST_API_URL,
key: G... | ync function getAllPostsWithSlug() {
const params = {
fields: "slug",
limit: "all",
};
const posts = await api.posts.browse(params);
return posts;
}
export async function getAllPostsForHome(preview) {
const params = {
limit: "all",
| lug",
limit: "all",
};
try {
const post = await api.posts.read(params);
return post;
} catch (error) {
// Don't throw if an slug doesn't exist
if (is404(error)) return;
throw error;
}
}
export as | {
"filepath": "examples/cms-ghost/lib/api.js",
"language": "javascript",
"file_size": 1811,
"cut_index": 537,
"middle_length": 229
} |
ort Avatar from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
export default function HeroPost({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<section>
<div className="mb-8 md:mb-16">
<CoverImage
t... | </h3>
<div className="mb-4 md:mb-0 text-lg">
<Date dateString={date} />
</div>
</div>
<div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
<Avatar name={author.name} picture={a | :gap-x-8 mb-20 md:mb-28">
<div>
<h3 className="mb-4 text-4xl lg:text-6xl leading-tight">
<Link href={`/posts/${slug}`} className="hover:underline">
{title}
</Link>
| {
"filepath": "examples/cms-ghost/components/hero-post.js",
"language": "javascript",
"file_size": 1074,
"cut_index": 515,
"middle_length": 229
} |
react";
import { Environment, Network, RecordSource, Store } from "relay-runtime";
let relayEnvironment;
// Define a function that fetches the results of an operation (query/mutation/etc)
// and returns its results as a Promise
function fetchQuery(operation, variables, cacheConfig, uploadables) {
return fetch(proce... | t({
// Create a network layer from the fetch function
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
});
}
export function initEnvironment(initialRecords) {
// Create a network layer from the fetch function
co | rs here
body: JSON.stringify({
query: operation.text, // GraphQL text from input
variables,
}),
}).then((response) => response.json());
}
function createEnvironment(initialRecords) {
return new Environmen | {
"filepath": "examples/with-relay-modern/lib/relay.js",
"language": "javascript",
"file_size": 1729,
"cut_index": 537,
"middle_length": 229
} |
react";
import {
applySnapshot,
Instance,
SnapshotIn,
SnapshotOut,
types,
} from "mobx-state-tree";
let store: IStore | undefined;
const Store = types
.model({
lastUpdate: types.Date,
light: false,
})
.actions((self) => {
let timer: any;
const start = () => {
timer = setInterval(... | const stop = () => {
clearInterval(timer);
};
return { start, stop, update };
});
export type IStore = Instance<typeof Store>;
export type IStoreSnapshotIn = SnapshotIn<typeof Store>;
export type IStoreSnapshotOut = SnapshotOut<typeof St | t yet know about the actions we're
// adding to self here)
(self as any).update();
}, 1000);
};
const update = () => {
self.lastUpdate = new Date(Date.now());
self.light = true;
};
| {
"filepath": "examples/with-mobx-state-tree/store.ts",
"language": "typescript",
"file_size": 1697,
"cut_index": 537,
"middle_length": 229
} |
xt/image";
import Link from "next/link";
import styles from "../../styles/Home.module.css";
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel... | /about" className={styles.card}>
<h2>About Page →</h2>
<p>Playwright will test if this link is working.</p>
</Link>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation & | </h1>
<p className={styles.description}>
Get started by editing{" "}
<code className={styles.code}>pages/index.js</code>
</p>
<div className={styles.grid}>
<Link href="/home | {
"filepath": "examples/with-playwright/pages/home/index.tsx",
"language": "tsx",
"file_size": 2516,
"cut_index": 563,
"middle_length": 229
} |
Container from "./container";
import cn from "classnames";
import { EXAMPLE_PATH } from "@/lib/constants";
export default function Alert({ preview }) {
return (
<div
className={cn("border-b", {
"bg-accent-7 border-accent-7 text-white": preview,
"bg-accent-1 border-accent-2": !preview,
... | </>
) : (
<>
The source code for this blog is{" "}
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
className="underline hover:text-succes | href="/api/exit-preview"
className="underline hover:text-cyan duration-200 transition-colors"
>
Click here
</a>{" "}
to exit preview mode.
| {
"filepath": "examples/cms-ghost/components/alert.js",
"language": "javascript",
"file_size": 1205,
"cut_index": 518,
"middle_length": 229
} |
.css";
import { ClerkProvider, SignedIn, SignedOut, UserButton } from "@clerk/nextjs";
import { Inter } from "next/font/google";
import Image from "next/image";
import Script from "next/script";
import styles from "../styles/Header.module.css";
import Link from "next/link";
import type { Metadata } from "next";
const ... | e}>Your application</span>
</Link>
</div>
<div className={styles.right}>
<SignedOut>
<Link href="/sign-in">Sign in</Link>
</SignedOut>
<SignedIn>
<UserButton afterSignOutUrl="/" />
</SignedIn>
</div | => (
<header className={styles.header}>
<div className={styles.left}>
<Link href="/" className={styles.logo}>
<Image src="/logo.svg" width="32" height="32" alt="Logo" />
<span className={styles.appNam | {
"filepath": "examples/with-clerk/app/layout.tsx",
"language": "tsx",
"file_size": 1534,
"cut_index": 537,
"middle_length": 229
} |
Container from "./container";
import { EXAMPLE_PATH } from "@/lib/constants";
export default function Footer() {
return (
<footer className="bg-accent-1 border-t border-accent-2">
<Container>
<div className="py-28 flex flex-col lg:flex-row items-center">
<h3 className="text-4xl lg:text-5... | r border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
>
Read Documentation
</a>
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/$ | lex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
<a
href="https://nextjs.org/docs/basic-features/pages"
className="mx-3 bg-black hover:bg-white hover:text-black borde | {
"filepath": "examples/cms-ghost/components/footer.js",
"language": "javascript",
"file_size": 1209,
"cut_index": 518,
"middle_length": 229
} |
mport Link from "next/link";
import { APIRequest } from "./api-request";
const ClerkFeatures = () => (
<Link href="/user" className={styles.cardContent}>
<img src="/icons/layout.svg" />
<div>
<h3>Explore features provided by Clerk</h3>
<p>
Interact with the user button, user profile, and ... | Clerk
out-of-the-box
</p>
</div>
<div className={styles.arrow}>
<img src="/icons/arrow-right.svg" />
</div>
</Link>
);
// Main component using <SignedIn> & <SignedOut>.
//
// The SignedIn and SignedOut components are use | () => (
<Link href="/sign-up" className={styles.cardContent}>
<img src="/icons/user-plus.svg" />
<div>
<h3>Sign up for an account</h3>
<p>
Sign up and sign in to explore all the features provided by | {
"filepath": "examples/with-clerk/app/page.tsx",
"language": "tsx",
"file_size": 3392,
"cut_index": 614,
"middle_length": 229
} |
ar from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import PostTitle from "./post-title";
export default function PostHeader({ title, coverImage, date, author }) {
return (
<>
<PostTitle>{title}</PostTitle>
<div className="hidden md:block md:mb-12">
<Avatar ... | to">
<div className="block md:hidden mb-6">
<Avatar name={author.name} picture={author.profile_image} />
</div>
<div className="mb-6 text-lg">
<Date dateString={date} />
</div>
</div>
</>
);
} | >
</div>
<div className="max-w-2xl mx-au | {
"filepath": "examples/cms-ghost/components/post-header.js",
"language": "javascript",
"file_size": 832,
"cut_index": 523,
"middle_length": 52
} |
from "next/head";
import { CMS_NAME, HOME_OG_IMAGE_URL } from "@/lib/constants";
export default function Meta() {
return (
<Head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
... | favicon.ico" />
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#000" />
<link rel="alternate" type="application/r | />
<link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<link rel="shortcut icon" href="/favicon/ | {
"filepath": "examples/cms-ghost/components/meta.js",
"language": "javascript",
"file_size": 1254,
"cut_index": 524,
"middle_length": 229
} |
r } from "next/router";
export const CacheStrategySelector = () => {
const router = useRouter();
const { asPath, route } = router;
const value = asPath.split("/")[2];
return (
<div className="cache-option-toggler">
<h4>Cache option</h4>
<select
name="cache-option"
onChange={(ev... | <option value="no-cache">Without cache</option>
<option value="memory-cache">Memory Cache</option>
<option value="session-storage-cache">Session Storage Cache</option>
<option value="ls-cache">Local Storage Cache</option>
< | e });
}}
value={value}
>
| {
"filepath": "examples/with-fingerprintjs-pro/components/CacheStrategySelector.tsx",
"language": "tsx",
"file_size": 865,
"cut_index": 529,
"middle_length": 52
} |
import Avatar from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
import AuthorType from "../types/authorType";
type Props = {
title: string;
coverImage: string;
date: string;
excerpt: string;
author: AuthorType;
slug: string;
};
export default... | </h3>
<div className="text-lg mb-4">
<Date dateString={date} />
</div>
<div
className="text-lg leading-relaxed mb-4"
dangerouslySetInnerHTML={{ __html: excerpt }}
/>
<Avatar author={author} />
| title={title} coverImage={coverImage} slug={slug} />
)}
</div>
<h3 className="text-3xl mb-3 leading-snug">
<Link href={`/posts${slug}`} className="hover:underline">
{title}
</Link>
| {
"filepath": "examples/cms-enterspeed/components/post-preview.tsx",
"language": "tsx",
"file_size": 1011,
"cut_index": 512,
"middle_length": 229
} |
int-disable @typescript-eslint/no-namespace */
// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can... | rom "cypress/react18";
// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare | iguration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')
import { mount } f | {
"filepath": "examples/with-cypress/cypress/support/component.ts",
"language": "typescript",
"file_size": 1184,
"cut_index": 518,
"middle_length": 229
} |
Container from "@/components/container";
import MoreStories from "@/components/more-stories";
import HeroPost from "@/components/hero-post";
import Intro from "@/components/intro";
import Layout from "@/components/layout";
import { getAllPostsForHome } from "@/lib/api";
import Head from "next/head";
import { CMS_NAME ... | ge={heroPost.feature_image}
date={heroPost.published_at}
author={heroPost.primary_author}
slug={heroPost.slug}
excerpt={heroPost.excerpt}
/>
)}
{morePosts.length > 0 && | <title>{`Next.js Blog Example with ${CMS_NAME}`}</title>
</Head>
<Container>
<Intro />
{heroPost && (
<HeroPost
title={heroPost.title}
coverIma | {
"filepath": "examples/cms-ghost/pages/index.js",
"language": "javascript",
"file_size": 1249,
"cut_index": 518,
"middle_length": 229
} |
orPage from "next/error";
import Container from "@/components/container";
import PostBody from "@/components/post-body";
import MoreStories from "@/components/more-stories";
import Header from "@/components/header";
import PostHeader from "@/components/post-header";
import SectionSeparator from "@/components/section-se... | ;
}
return (
<Layout preview={preview}>
<Container>
<Header />
{router.isFallback ? (
<PostTitle>Loading…</PostTitle>
) : (
<>
<article>
<Head>
<title>
| t/head";
import { CMS_NAME } from "@/lib/constants";
export default function Post({ post, morePosts, preview }) {
const router = useRouter();
if (!router.isFallback && !post?.slug) {
return <ErrorPage statusCode={404} /> | {
"filepath": "examples/cms-ghost/pages/posts/[slug].js",
"language": "javascript",
"file_size": 2135,
"cut_index": 563,
"middle_length": 229
} |
vatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
export default function PostPreview({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<div>
<div className="mb-5">
<CoverImage
slug={slug}
title={ti... | </Link>
</h3>
<div className="text-lg mb-4">
<Date dateString={date} />
</div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
<Avatar name={author.name} picture={author.profile_image} />
</div>
);
}
| lassName="hover:underline">
{title}
| {
"filepath": "examples/cms-ghost/components/post-preview.js",
"language": "javascript",
"file_size": 843,
"cut_index": 535,
"middle_length": 52
} |
ription, useMutation, gql } from "@apollo/client";
import { PrivateRoute } from "../components/private-route";
import { nhost } from "../utils/nhost";
const INSERT_ITEM = gql`
mutation insertItem($item: items_insert_input!) {
insert_items_one(object: $item) {
id
}
}
`;
const S_GET_ITEMS = gql`
sub... | {
item: {
name,
},
},
});
} catch (error) {
console.error(error);
return alert("Error inserting item");
}
setName("");
}
return (
<div style={{ padding: "10px" }}>
<form | `;
function InsertItem() {
const [name, setName] = useState("");
const [insertItem] = useMutation(INSERT_ITEM);
async function handleFormSubmit(e) {
e.preventDefault();
try {
insertItem({
variables: | {
"filepath": "examples/with-nhost-auth-realtime-graphql/pages/index.js",
"language": "javascript",
"file_size": 2589,
"cut_index": 563,
"middle_length": 229
} |
"react";
import { useRouter } from "next/router";
import Link from "next/link";
import { nhost } from "../utils/nhost";
export default function Login() {
const router = useRouter();
const [displayName, setDisplayName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useS... | nSubmit={handleLogin}>
<div>
<input
placeholder="Name"
type="text"
value={displayName}
onChange={(e) => setDisplayName(e.target.value)}
/>
</div>
<div>
<i | display_name: displayName,
},
},
});
} catch (error) {
console.error(error);
return alert("failed to register");
}
router.push("/");
}
return (
<div>
<form o | {
"filepath": "examples/with-nhost-auth-realtime-graphql/pages/register.js",
"language": "javascript",
"file_size": 1580,
"cut_index": 537,
"middle_length": 229
} |
led } from "@filbert-js/macro";
import React from "react";
const Heading = styled.h1`
outline: none;
text-decoration: none;
font-weight: 300;
letter-spacing: 1px;
transition: all 0.2s ease;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.01);
padding: 0.4125em 1.25em;
color: #3793e0;
&:hover {
border-botto... | tyles={`
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue,
| play: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
> * + * {
margin-top: 1rem;
}
`;
export default function Home() {
return (
<Container>
<Global
s | {
"filepath": "examples/with-filbert/pages/index.js",
"language": "javascript",
"file_size": 1673,
"cut_index": 537,
"middle_length": 229
} |
c function preview(req, res) {
// Check the secret and next parameters
// This secret should only be known to this API route and the CMS
if (
req.query.secret !== process.env.GHOST_PREVIEW_SECRET ||
!req.query.slug
) {
return res.status(401).json({ message: "Invalid token" });
}
// Fetch the he... | lid slug" });
}
// Enable Draft Mode by setting the cookie
res.setDraftMode({ enable: true });
// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeH | ) {
return res.status(401).json({ message: "Inva | {
"filepath": "examples/cms-ghost/pages/api/preview.js",
"language": "javascript",
"file_size": 952,
"cut_index": 582,
"middle_length": 52
} |
ment from "next/document";
import { createStylesheet } from "@filbert-js/server-stylesheet";
class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = createStylesheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({... | styleTags = sheet.getReactElements();
return {
...initialProps,
styles: (
<>
{styleTags}
{initialProps.styles}
</>
),
};
} finally {
}
}
}
export default MyDocument | = await Document.getInitialProps(ctx);
const | {
"filepath": "examples/with-filbert/pages/_document.js",
"language": "javascript",
"file_size": 833,
"cut_index": 523,
"middle_length": 52
} |
er, REALM_GRAPHQL_ENDPOINT } from "../lib/RealmClient";
const FIND_MOVIES = `
query FindMovies{
movies(query: { year: 2014, rated: "PG" } ) {
title
year
runtime
}
}
`;
const fetcher = async (query) =>
fetch(REALM_GRAPHQL_ENDPOINT, {
method: "POST",
headers: await generateAuthHe... | ? (
!movies && <div className="status">No movies Found</div>
) : (
<div className="status"> Fetching data...</div>
)}
{movies && (
<table>
<thead>
<tr>
<th>#< | e.error(data.error);
return <p>An error occurred: ${data.error}</p>;
}
const movies = data ? data.data.movies : null;
return (
<>
<div className="App">
<h1>"PG" Rated Movies - 2014</h1>
{data | {
"filepath": "examples/with-realm-web/pages/index.js",
"language": "javascript",
"file_size": 2089,
"cut_index": 563,
"middle_length": 229
} |
ateContext, useContext } from "react";
import { createStore, useStore as useZustandStore } from "zustand";
import { PreloadedStoreInterface } from "./StoreProvider";
export interface StoreInterface {
lastUpdate: number;
light: boolean;
count: number;
tick: (lastUpdate: number) => void;
increment: () => void;... | ace) => T) {
const store = useContext(storeContext);
if (!store) throw new Error("Store is missing the provider");
return useZustandStore(store, selector);
}
export function initializeStore(preloadedState: PreloadedStoreInterface) {
return creat |
export type StoreType = ReturnType<typeof initializeStore>;
const storeContext = createContext<StoreType | null>(null);
export const Provider = storeContext.Provider;
export function useStore<T>(selector: (state: StoreInterf | {
"filepath": "examples/with-zustand/src/lib/store.ts",
"language": "typescript",
"file_size": 1447,
"cut_index": 524,
"middle_length": 229
} |
earn more about each option below in the Jest docs: https://jestjs.io/docs/configuration.
module.exports = {
collectCoverageFrom: [
"**/*.{js,jsx,ts,tsx}",
"!**/*.d.ts",
"!**/node_modules/**",
],
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mo... | s/(.*)$": "<rootDir>/components/$1",
"^@/pages/(.*)$": "<rootDir>/pages/$1",
},
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.next/"],
transform: {
// Use babel-jest to tra | ,
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
"^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$": `<rootDir>/__mocks__/fileMock.js`,
// Handle module aliases
"^@/component | {
"filepath": "examples/with-jest-babel/jest.config.js",
"language": "javascript",
"file_size": 1383,
"cut_index": 524,
"middle_length": 229
} |
hChildren } from "react";
import {
CacheLocation,
FpjsProvider,
LoadOptions,
} from "@fingerprintjs/fingerprintjs-pro-react";
const fpjsPublicApiKey = process.env.NEXT_PUBLIC_FPJS_PUBLIC_API_KEY as string;
export const InMemoryCache: React.FC<PropsWithChildren> = ({ children }) => {
const loadOptions: LoadOpt... | th an in-memory cache</h2>
<div className="subheader">
New API call made after a key expires, a page is reloaded or the
provider is unmounted
</div>
</header>
{children}
</div>
</FpjsPro | header className="header">
<h2>Solution wi | {
"filepath": "examples/with-fingerprintjs-pro/providers/InMemoryCache.tsx",
"language": "tsx",
"file_size": 852,
"cut_index": 529,
"middle_length": 52
} |
FpjsProvider,
LoadOptions,
} from "@fingerprintjs/fingerprintjs-pro-react";
const fpjsPublicApiKey = process.env.NEXT_PUBLIC_FPJS_PUBLIC_API_KEY as string;
export const SessionStorageCache: React.FC<PropsWithChildren> = ({
children,
}) => {
const loadOptions: LoadOptions = {
apiKey: fpjsPublicApiKey,
};
... | Solution with a custom implementation of a session storage cache
</h2>
<div className="subheader">
New API call made after a key expires or is cleared from the local
storage
</div>
</header>
| ader className="header">
<h2>
| {
"filepath": "examples/with-fingerprintjs-pro/providers/SessionStorageCache.tsx",
"language": "tsx",
"file_size": 947,
"cut_index": 582,
"middle_length": 52
} |
{ useState } from "react";
import { useRouter } from "next/router";
import Link from "next/link";
import { nhost } from "../utils/nhost";
export default function Login() {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
async function handleL... | tEmail(e.target.value)}
/>
</div>
<div>
<input
placeholder="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</ | router.push("/");
}
return (
<div>
<form onSubmit={handleLogin}>
<div>
<input
placeholder="Email"
type="email"
value={email}
onChange={(e) => se | {
"filepath": "examples/with-nhost-auth-realtime-graphql/pages/login.js",
"language": "javascript",
"file_size": 1189,
"cut_index": 518,
"middle_length": 229
} |
Script from "next/script";
type RenderParameters = {
sitekey: string;
theme?: "light" | "dark";
callback?(token: string): void;
};
declare global {
interface Window {
onloadTurnstileCallback(): void;
turnstile: {
render(container: string | HTMLElement, params: RenderParameters): void;
};
... | ?onload=onloadTurnstileCallback"
async={true}
defer={true}
/>
<form method="POST" action="/api/handler">
<h2>Dummy Login Demo</h2>
<div id="my-widget" className="checkbox" />
<button type="submit">Sign in | ile.render('#my-widget', {
sitekey: '${process.env.NEXT_PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY}',
})
}`}
</Script>
<Script
src="https://challenges.cloudflare.com/turnstile/v0/api.js | {
"filepath": "examples/cloudflare-turnstile/pages/explicit.tsx",
"language": "tsx",
"file_size": 1136,
"cut_index": 518,
"middle_length": 229
} |
use client";
import useInterval from "../lib/useInterval";
import { useStore } from "../lib/store";
import { useShallow } from "zustand/react/shallow";
import "./clock.css";
function useClock() {
return useStore(
useShallow((store) => ({
lastUpdate: store.lastUpdate,
light: store.light,
})),
)... | piece of state:
const tick = useStore((store) => store.tick);
useInterval(() => {
tick(Date.now());
}, 1000);
return (
<div className={`clock ${light ? "light" : ""}`}>
{formatTime(lastUpdate)}
</div>
);
}
export default Cloc | fetch single | {
"filepath": "examples/with-zustand/src/components/clock.tsx",
"language": "tsx",
"file_size": 786,
"cut_index": 513,
"middle_length": 14
} |
ions,
} from "@fingerprintjs/fingerprintjs-pro-react";
const fpjsPublicApiKey = process.env.NEXT_PUBLIC_FPJS_PUBLIC_API_KEY as string;
export const LocalStorageCache: React.FC<PropsWithChildren> = ({
children,
}) => {
const loadOptions: LoadOptions = {
apiKey: fpjsPublicApiKey,
};
return (
<FpjsProvi... | lution with a local storage cache</h2>
<div className="subheader">
New API call made after a key expires or is cleared from the local
storage
</div>
</header>
{children}
</div>
</FpjsPro | <header className="header">
<h2>So | {
"filepath": "examples/with-fingerprintjs-pro/providers/LocalStorageCache.tsx",
"language": "tsx",
"file_size": 929,
"cut_index": 606,
"middle_length": 52
} |
xt/image";
import styles from "../styles/Home.module.css";
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next app</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<h1 className={st... | <p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn →</h3>
<p>Learn about Next.js in an interactive course with | <code className={styles.code}>pages/index.tsx</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation →</h3>
| {
"filepath": "examples/with-docker-compose/next-app/src/pages/index.tsx",
"language": "tsx",
"file_size": 2244,
"cut_index": 563,
"middle_length": 229
} |
mport { PropsWithChildren } from "react";
import {
CacheLocation,
FpjsProvider,
LoadOptions,
} from "@fingerprintjs/fingerprintjs-pro-react";
const fpjsPublicApiKey = process.env.NEXT_PUBLIC_FPJS_PUBLIC_API_KEY as string;
export const WithoutCache: React.FC<PropsWithChildren> = ({ children }) => {
const loadO... | <header className="header">
<h2>Solution without cache</h2>
<div className="subheader">
New API call made on every component render
</div>
</header>
{children}
</div>
</FpjsProvider>
); | "App">
| {
"filepath": "examples/with-fingerprintjs-pro/providers/WithoutCache.tsx",
"language": "tsx",
"file_size": 787,
"cut_index": 513,
"middle_length": 14
} |
P_ID;
export const REALM_GRAPHQL_ENDPOINT = `https://realm.mongodb.com/api/client/v2.0/app/${APP_ID}/graphql`;
const app = new App({
id: APP_ID,
baseUrl: "https://realm.mongodb.com",
});
export const generateAuthHeader = async () => {
if (!app.currentUser) {
// If no user is logged in, log in an anonymous u... |
await app.currentUser.refreshCustomData();
}
// Get a valid access token for the current user
const { accessToken } = app.currentUser;
// Set the Authorization header, preserving any other headers
return {
Authorization: `Bearer ${acces | custom data which also refreshes their access token. | {
"filepath": "examples/with-realm-web/lib/RealmClient.js",
"language": "javascript",
"file_size": 932,
"cut_index": 606,
"middle_length": 52
} |
"next/router";
import Head from "next/head";
import "../styles/globals.css";
import "../styles/App.css";
import { InMemoryCache } from "../providers/InMemoryCache";
import { LocalStorageCache } from "../providers/LocalStorageCache";
import { WithoutCache } from "../providers/WithoutCache";
import { SessionStorageCache... | ":
return WithoutCache;
case "ls-cache":
return LocalStorageCache;
case "session-storage-cache":
return SessionStorageCache;
default:
return InMemoryCache;
}
};
function MyApp({ Component, pageProps }: AppProps) {
c | "next/app";
import type { CacheStrategyPath, RouterProps } from "../components/types";
const getFingerprintJsProProviderByCacheStrategy = (
cacheStrategy: CacheStrategyPath,
) => {
switch (cacheStrategy) {
case "no-cache | {
"filepath": "examples/with-fingerprintjs-pro/pages/_app.tsx",
"language": "tsx",
"file_size": 1592,
"cut_index": 537,
"middle_length": 229
} |
mport Toggler from "../../components/Toggler";
import VisitorDataPresenter from "../../components/VisitorDataPresenter";
import { useContext } from "react";
import {
FpjsContext,
useVisitorData,
} from "@fingerprintjs/fingerprintjs-pro-react";
function VisitorDataComponent() {
const { data, isLoading, error } = ... | soon as the page loads. This
is the most common use-case.
</div>
<Toggler>
<VisitorDataComponent />
</Toggler>
<button className="clear-cache-button" onClick={() => clearCache()}>
Clear cache
</button>
| text(FpjsContext);
return (
<section className="body">
<h3>Home page</h3>
<div>
On this page we use the <code>useVisitorData</code> hook with default
settings and identification is performed as | {
"filepath": "examples/with-fingerprintjs-pro/pages/home/[cacheStrategy].tsx",
"language": "tsx",
"file_size": 1046,
"cut_index": 513,
"middle_length": 229
} |
UCTION_API_KEY =
process.env.ENTERSPEED_PRODUCTION_ENVIRONMENT_API_KEY;
const PREVIEW_API_KEY = process.env.ENTERSPEED_PREVIEW_ENVIRONMENT_API_KEY;
const call = async (query: string, preview: boolean) => {
const url = `https://delivery.enterspeed.com/v1?${query}`;
const response = await fetch(new Request(url), {... | dle: string, preview: boolean) => {
const response = await call(`handle=${handle}`, preview);
return response.views[handle];
};
export const getByUrl = async (url: string, preview: boolean) => {
const response = await call(`url=${url}`, preview);
| e = async (han | {
"filepath": "examples/cms-enterspeed/lib/api.ts",
"language": "typescript",
"file_size": 818,
"cut_index": 522,
"middle_length": 14
} |
r from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
import AuthorType from "../types/authorType";
type Props = {
title: string;
coverImage: string;
date: string;
excerpt: string;
author: AuthorType;
slug: string;
};
export default function He... | ding-tight">
<Link
href={`/posts${slug}`}
className="hover:underline"
dangerouslySetInnerHTML={{ __html: title }}
></Link>
</h3>
<div className="mb-4 md:mb-0 text-lg">
| itle={title} coverImage={coverImage} slug={slug} />
)}
</div>
<div className="md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8 mb-20 md:mb-28">
<div>
<h3 className="mb-4 text-4xl lg:text-6xl lea | {
"filepath": "examples/cms-enterspeed/components/hero-post.tsx",
"language": "tsx",
"file_size": 1318,
"cut_index": 524,
"middle_length": 229
} |
Head from "next/head";
import { EXAMPLE_TOOL_NAME } from "../lib/constants";
export default function Meta() {
return (
<Head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
s... | icon.ico" />
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#000" />
<link rel="alternate" type="application/rss+ |
<link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<link rel="shortcut icon" href="/favicon/fav | {
"filepath": "examples/cms-enterspeed/components/meta.tsx",
"language": "tsx",
"file_size": 1191,
"cut_index": 518,
"middle_length": 229
} |
mport Avatar from "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import PostTitle from "./post-title";
import Categories from "./categories";
import AuthorType from "../types/authorType";
type Props = {
title: string;
coverImage: string;
date: string;
author: AuthorType;
categ... | x-w-2xl mx-auto">
<div className="block md:hidden mb-6">
<Avatar author={author} />
</div>
<div className="mb-6 text-lg">
Posted <Date dateString={date} />
<Categories categories={categories} />
| lassName="hidden md:block md:mb-12">
<Avatar author={author} />
</div>
<div className="mb-8 md:mb-16 sm:mx-0">
<CoverImage title={title} coverImage={coverImage} />
</div>
<div className="ma | {
"filepath": "examples/cms-enterspeed/components/post-header.tsx",
"language": "tsx",
"file_size": 1034,
"cut_index": 513,
"middle_length": 229
} |
ad";
import Image from "next/image";
import styles from "@/pages/index.module.css";
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<h1 className={... | es and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn →</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
h | ode>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation →</h3>
<p>Find in-depth information about Next.js featur | {
"filepath": "examples/with-jest-babel/pages/index.tsx",
"language": "tsx",
"file_size": 1977,
"cut_index": 537,
"middle_length": 229
} |
Container from "./container";
import cn from "classnames";
import { EXAMPLE_PATH } from "../lib/constants";
type Props = {
preview?: boolean;
};
export default function Alert({ preview }: Props) {
return (
<div
className={cn("border-b", {
"bg-accent-7 border-accent-7 text-white": preview,
... | to exit preview mode.
</>
) : (
<>
The source code for this blog is{" "}
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
| age preview.{" "}
<a
href="/api/exit-preview"
className="underline hover:text-cyan duration-200 transition-colors"
>
Click here
</a>{" "}
| {
"filepath": "examples/cms-enterspeed/components/alert.tsx",
"language": "tsx",
"file_size": 1250,
"cut_index": 518,
"middle_length": 229
} |
Container from "./container";
import { EXAMPLE_PATH } from "../lib/constants";
export default function Footer() {
return (
<footer className="bg-accent-1 border-t border-accent-2">
<Container>
<div className="py-28 flex flex-col lg:flex-row items-center">
<h3 className="text-4xl lg:text-... | er border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
>
Read Documentation
</a>
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/ | flex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
<a
href="https://nextjs.org/docs/basic-features/pages"
className="mx-3 bg-black hover:bg-white hover:text-black bord | {
"filepath": "examples/cms-enterspeed/components/footer.tsx",
"language": "tsx",
"file_size": 1210,
"cut_index": 518,
"middle_length": 229
} |
k from "next/link";
import { RouterProps } from "./types";
const CustomLink: React.FC<PropsWithChildren<{ to: string }>> = ({
to,
children,
}) => {
const router = useRouter();
const { pathname } = router;
const { cacheStrategy } = router.query as RouterProps;
const linkPathname = `/${to}/[cacheStrategy]`;
... | ame={className}
>
{children}
</Link>
</div>
);
};
export const Nav: React.FC = () => {
return (
<nav className="nav">
<CustomLink to="home">Home</CustomLink>
<CustomLink to="signin">Sign in</CustomLink>
</na | },
}}
scroll={false}
classN | {
"filepath": "examples/with-fingerprintjs-pro/components/Nav.tsx",
"language": "tsx",
"file_size": 925,
"cut_index": 606,
"middle_length": 52
} |
_TOOL_URL } from "../lib/constants";
export default function Intro() {
return (
<section className="flex-col md:flex-row flex items-center md:justify-between mt-16 mb-16 md:mb-12">
<h1 className="text-6xl md:text-8xl font-bold tracking-tighter leading-tight md:pr-8">
Blog.
</h1>
<h4 cla... | >
Next.js
</a>{" "}
and{" "}
<a
href={EXAMPLE_TOOL_URL}
className="underline hover:text-success duration-200 transition-colors"
>
{EXAMPLE_TOOL_NAME}
</a>
.
| ver:text-success duration-200 transition-colors"
| {
"filepath": "examples/cms-enterspeed/components/intro.tsx",
"language": "tsx",
"file_size": 883,
"cut_index": 547,
"middle_length": 52
} |
from "next/head";
import Container from "../components/container";
import MoreStories from "../components/more-stories";
import HeroPost from "../components/hero-post";
import Intro from "../components/intro";
import Layout from "../components/layout";
import { EXAMPLE_TOOL_NAME } from "../lib/constants";
import { getB... | ntainer>
<Intro />
{heroPost && (
<HeroPost
title={heroPost.title}
coverImage={heroPost.featuredImage}
date={heroPost.date}
author={heroPost.author}
slug= | const heroPost = posts[0];
const morePosts = posts.slice(1);
return (
<>
<Layout preview={preview}>
<Head>
<title>Next.js Blog Example with {EXAMPLE_TOOL_NAME}</title>
</Head>
<Co | {
"filepath": "examples/cms-enterspeed/pages/index.tsx",
"language": "tsx",
"file_size": 1449,
"cut_index": 524,
"middle_length": 229
} |
* @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
colors: {
"accent-1": "#FAFAFA",
"accent-2": "#EAEAEA",
"accent-7": "#333",
success: "#0070f3",
... | "5xl": "2.5rem",
"6xl": "2.75rem",
"7xl": "4.5rem",
"8xl": "6.25rem",
},
boxShadow: {
small: "0 5px 10px rgba(0, 0, 0, 0.12)",
medium: "0 8px 30px rgba(0, 0, 0, 0.12)",
},
},
},
plugins: | tSize: {
| {
"filepath": "examples/cms-prepr/tailwind.config.js",
"language": "javascript",
"file_size": 791,
"cut_index": 514,
"middle_length": 14
} |
Container from "./container";
import cn from "classnames";
import { EXAMPLE_PATH } from "@/lib/constants";
export default function Alert({ preview }) {
return (
<div
className={cn("border-b", {
"bg-accent-7 border-accent-7 text-white": preview,
"bg-accent-1 border-accent-2": !preview,
... | </>
) : (
<>
The source code for this blog is{" "}
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
className="underline hover:text-succes | href="/api/exit-preview"
className="underline hover:text-cyan duration-200 transition-colors"
>
Click here
</a>{" "}
to exit preview mode.
| {
"filepath": "examples/cms-prepr/components/alert.js",
"language": "javascript",
"file_size": 1205,
"cut_index": 518,
"middle_length": 229
} |
Container from "./container";
import { EXAMPLE_PATH } from "@/lib/constants";
export default function Footer() {
return (
<footer className="bg-accent-1 border-t border-accent-2">
<Container>
<div className="py-28 flex flex-col lg:flex-row items-center">
<h3 className="text-4xl lg:text-5... | r border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
>
Read Documentation
</a>
<a
href={`https://github.com/vercel/next.js/tree/canary/examples/$ | lex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
<a
href="https://nextjs.org/docs/basic-features/pages"
className="mx-3 bg-black hover:bg-white hover:text-black borde | {
"filepath": "examples/cms-prepr/components/footer.js",
"language": "javascript",
"file_size": 1209,
"cut_index": 518,
"middle_length": 229
} |
from "next/head";
import { CMS_NAME, HOME_OG_IMAGE_URL } from "@/lib/constants";
export default function Meta() {
return (
<Head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
... | favicon.ico" />
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#000" />
<link rel="alternate" type="application/r | />
<link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<link rel="shortcut icon" href="/favicon/ | {
"filepath": "examples/cms-prepr/components/meta.js",
"language": "javascript",
"file_size": 1254,
"cut_index": 524,
"middle_length": 229
} |
m "./avatar";
import Date from "./date";
import CoverImage from "./cover-image";
import Link from "next/link";
export default function PostPreview({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<div>
<div className="mb-5">
<CoverImage slug={slug} title={title} url={cove... | <Date dateString={date} />
</div>
)}
<div
className="text-lg leading-relaxed mb-4"
dangerouslySetInnerHTML={{ __html: excerpt }}
></div>
<Avatar name={author.full_name} picture={author.profile_pic[0] | {date && (
<div className="text-lg mb-4">
| {
"filepath": "examples/cms-prepr/components/post-preview.js",
"language": "javascript",
"file_size": 864,
"cut_index": 529,
"middle_length": 52
} |
async function handler(req, res) {
// Check the secret and next parameters
// This secret should only be known to this API route and the CMS
if (
req.query.secret !== process.env.PREPRIO_PREVIEW_SECRET ||
!req.query.slug
) {
return res.status(401).json({ message: "Invalid token" });
}
// Fetch... | : "Invalid slug" });
}
// Enable Draft Mode by setting the cookie
res.setDraftMode({ enable: true });
// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res | (!post) {
return res.status(401).json({ message | {
"filepath": "examples/cms-prepr/pages/api/preview.js",
"language": "javascript",
"file_size": 960,
"cut_index": 582,
"middle_length": 52
} |
lint-disable */
// Disable ESLint to prevent failing linting inside the Next.js repo.
// If you're using ESLint on your project, we recommend installing the ESLint Cypress plugin instead:
// https://github.com/cypress-io/eslint-plugin-cypress
// Cypress E2E Test
describe("Navigation", () => {
it("should navigate to ... | ck();
// The new url should include "/about"
cy.url().should("include", "/about");
// The new page should contain an h1 with "About page"
cy.get("h1").contains("About Page");
});
});
// Prevent TypeScript from reading file as legacy sc | "about"]').cli | {
"filepath": "examples/with-cypress/cypress/e2e/app.cy.ts",
"language": "typescript",
"file_size": 803,
"cut_index": 517,
"middle_length": 14
} |
ct";
import VisitorDataPresenter from "../../components/VisitorDataPresenter";
function SignInPage() {
const [login, setLogin] = useState("");
const [password, setPassword] = useState("");
const [tag, setTag] = useState("");
const [ignoreCache, setIgnoreCache] = useState(false);
const [extendedResult, setEx... |
purpose <code>useVisitorData</code> hook should be called with{" "}
<code>immediate</code> flag set to <code>false</code> and call the{" "}
<code>getData</code> function on form submission.
</p>
<p>
| ction className="body">
<h3>Sign in</h3>
<div>
<p>
Another common use-case is when you want to only fingerprint a user
after they perform some action, in this case - submit a form. For this | {
"filepath": "examples/with-fingerprintjs-pro/pages/signin/[cacheStrategy].tsx",
"language": "tsx",
"file_size": 3647,
"cut_index": 614,
"middle_length": 229
} |
} = {}) {
const response = await fetch(process.env.PREPRIO_API, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization:
"Bearer " +
(preview
? process.env.PREPRIO_PREVIEW_TOKEN
: process.env.PREPRIO_PRODUCTION_TOKEN),
},
body: JS... | async function getAllPostsWithSlug() {
const { data } = await fetchAPI(
`
{
Articles {
items {
_slug
}
}
}
`,
{ preview: true },
);
return data?.Articles.items;
}
export async function getAllPo | wait fetchAPI(
`
query ArticleBySlug($slug: String!) {
Article(slug: $slug) {
_slug
}
}
`,
{
preview: true,
variables: {
slug,
},
},
);
return data.Article;
}
export | {
"filepath": "examples/cms-prepr/lib/api.js",
"language": "javascript",
"file_size": 2859,
"cut_index": 563,
"middle_length": 229
} |
URL } from "@/lib/constants";
export default function Intro() {
return (
<section className="flex-col md:flex-row flex items-center md:justify-between mt-16 mb-16 md:mb-12">
<h1 className="text-6xl md:text-8xl font-bold tracking-tighter leading-tight md:pr-8">
Blog.
</h1>
<h4 className=... | Next.js
</a>{" "}
and{" "}
<a
href={CMS_URL}
className="underline hover:text-success duration-200 transition-colors"
>
{CMS_NAME}
</a>
.
</h4>
</section>
); | t-success duration-200 transition-colors"
>
| {
"filepath": "examples/cms-prepr/components/intro.js",
"language": "javascript",
"file_size": 846,
"cut_index": 535,
"middle_length": 52
} |
iner from "@/components/container";
import MoreStories from "@/components/more-stories";
import HeroPost from "@/components/hero-post";
import Intro from "@/components/intro";
import Layout from "@/components/layout";
import { getAllPostsForHome } from "@/lib/api";
import Head from "next/head";
import { CMS_NAME } from... | coverImage={heroPost.cover[0].url}
date={heroPost._publish_on}
author={heroPost.authors[0]}
slug={heroPost._slug}
excerpt={heroPost.excerpt}
/>
)}
{morePo | view}>
<Head>
<title>{`Next.js Blog Example with ${CMS_NAME}`}</title>
</Head>
<Container>
<Intro />
{heroPost && (
<HeroPost
title={heroPost.title}
| {
"filepath": "examples/cms-prepr/pages/index.js",
"language": "javascript",
"file_size": 1288,
"cut_index": 524,
"middle_length": 229
} |
ce types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// *****... | is will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<v | ess.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- Th | {
"filepath": "examples/with-cypress/cypress/support/commands.ts",
"language": "typescript",
"file_size": 1384,
"cut_index": 524,
"middle_length": 229
} |
vatar";
import Date from "../components/date";
import CoverImage from "../components/cover-image";
import PostTitle from "../components/post-title";
export default function PostHeader({ title, coverImage, date, author }) {
return (
<>
<PostTitle>{title}</PostTitle>
<div className="hidden md:block md:... | mx-auto">
<div className="block md:hidden mb-6">
<Avatar name={author.full_name} picture={author.profile_pic[0].url} />
</div>
{date && (
<div className="mb-6 text-lg">
<Date dateString={date} />
| age} />
</div>
<div className="max-w-2xl | {
"filepath": "examples/cms-prepr/components/post-header.js",
"language": "javascript",
"file_size": 908,
"cut_index": 547,
"middle_length": 52
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.