new examples

This commit is contained in:
Andras Bacsai
2025-12-26 11:40:00 +01:00
parent 35e4d33085
commit d3a2a9d83b
1164 changed files with 101362 additions and 160055 deletions

View File

@@ -0,0 +1,32 @@
import * as React from "react"
import { Link } from "gatsby"
const Header = ({ siteTitle }) => (
<header
style={{
margin: `0 auto`,
padding: `var(--space-4) var(--size-gutter)`,
display: `flex`,
alignItems: `center`,
justifyContent: `space-between`,
}}
>
<Link
to="/"
style={{
fontSize: `var(--font-sm)`,
textDecoration: `none`,
}}
>
{siteTitle}
</Link>
<img
alt="Gatsby logo"
height={20}
style={{ margin: 0 }}
src="data:image/svg+xml,%3Csvg fill='none' viewBox='0 0 107 28' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3CclipPath id='a'%3E%3Cpath d='m0 0h106.1v28h-106.1z'/%3E%3C/clipPath%3E%3Cg clip-path='url(%23a)'%3E%3Cg fill='%23000'%3E%3Cpath clip-rule='evenodd' d='m89 11.7c-.8 0-2.2.2-3.2 1.6v-8.10005h-2.8v16.80005h2.7v-1.3c1.1 1.5 2.6 1.5999 3.2 1.5999 3 0 5-2.2999 5-5.2999s-2-5.3-4.9-5.3zm-.7 2.5c1.7 0 2.8 1.2 2.8 2.8s-1.2 2.8-2.8 2.8c-1.7 0-2.8-1.2-2.8-2.8s1.1-2.8 2.8-2.8z' fill-rule='evenodd'/%3E%3Cpath d='m71.2 21.9999v-7.6h1.9v-2.4h-1.9v-3.40005h-2.8v3.40005h-1.1v2.4h1.1v7.6z'/%3E%3Cpath clip-rule='evenodd' d='m65.6999 12h-2.9v1.3c-.8999-1.5-2.4-1.6-3.2-1.6-2.9 0-4.8999 2.4-4.8999 5.3s1.9999 5.2999 5.0999 5.2999c.8 0 2.1001-.0999 3.1001-1.5999v1.3h2.7999zm-5.1999 7.8c-1.7001 0-2.8-1.2-2.8-2.8s1.2-2.8 2.8-2.8c1.7 0 2.7999 1.2 2.7999 2.8s-1.1999 2.8-2.7999 2.8z' fill-rule='evenodd'/%3E%3Cpath d='m79.7001 14.4c-.7-.6-1.3-.7-1.6-.7-.7 0-1.1.3-1.1.8 0 .3.1.6.9.9l.7.2c.1261.0472.2621.0945.4037.1437.7571.2632 1.6751.5823 2.0963 1.2563.3.4.5 1 .5 1.7 0 .9-.3 1.8-1.1 2.5s-1.8 1.0999-3 1.0999c-2.1 0-3.2-.9999-3.9-1.6999l1.5-1.7c.6.6 1.4 1.2 2.2 1.2s1.4-.4 1.4-1.1c0-.6-.5-.9-.9-1l-.6-.2c-.0687-.0295-.1384-.0589-.2087-.0887l-.0011-.0004c-.6458-.2729-1.3496-.5704-1.8902-1.1109-.5-.5-.8-1.1-.8-1.9 0-1 .5-1.8 1-2.3.8-.6 1.8-.7 2.6-.7.7 0 1.9.1 3.2 1.1z'/%3E%3Cpath d='m98.5 20.5-4.8-8.5h3.3l3.1 5.7 2.8-5.7h3.2l-8 15.3h-3.2z'/%3E%3Cpath d='m47 13.7h7c0 .0634.01.1267.0206.1932.0227.1435.0477.3018-.0206.5068 0 4.5-3.4 8.1-8 8.1s-8-3.6-8-8.1c0-4.49995 3.6-8.09995 8-8.09995 2.6 0 5 1.2 6.5 3.3l-2.3 1.49995c-1-1.29995-2.6-2.09995-4.2-2.09995-2.9 0-4.9 2.49995-4.9 5.39995s2.1 5.3 5 5.3c2.6 0 4-1.3 4.6-3.2h-3.7z'/%3E%3C/g%3E%3Cpath d='m18 14h7c0 5.2-3.7 9.6-8.5 10.8l-13.19995-13.2c1.1-4.9 5.5-8.6 10.69995-8.6 3.7 0 6.9 1.8 8.9 4.5l-1.5 1.3c-1.7-2.3-4.4-3.8-7.4-3.8-3.9 0-7.29995 2.5-8.49995 6l11.49995 11.5c2.9-1 5.1-3.5 5.8-6.5h-4.8z' fill='%23fff'/%3E%3Cpath d='m6.2 21.7001c-2.1-2.1-3.2-4.8-3.2-7.6l10.8 10.8c-2.7 0-5.5-1.1-7.6-3.2z' fill='%23fff'/%3E%3Cpath d='m14 0c-7.7 0-14 6.3-14 14s6.3 14 14 14 14-6.3 14-14-6.3-14-14-14zm-7.8 21.8c-2.1-2.1-3.2-4.9-3.2-7.6l10.9 10.8c-2.8-.1-5.6-1.1-7.7-3.2zm10.2 2.9-13.1-13.1c1.1-4.9 5.5-8.6 10.7-8.6 3.7 0 6.9 1.8 8.9 4.5l-1.5 1.3c-1.7-2.3-4.4-3.8-7.4-3.8-3.9 0-7.2 2.5-8.5 6l11.5 11.5c2.9-1 5.1-3.5 5.8-6.5h-4.8v-2h7c0 5.2-3.7 9.6-8.6 10.7z' fill='%237026b9'/%3E%3C/g%3E%3C/svg%3E"
/>
</header>
)
export default Header

View File

@@ -0,0 +1,54 @@
.list {
display: grid;
margin: 0;
/* https://css-tricks.com/responsive-layouts-fewer-media-queries/ */
--w: 280px;
--n: 2;
gap: var(--size-gap);
grid-template-columns: repeat(
auto-fit,
minmax(max(var(--w), 100%/ (var(--n) + 1) + 0.1%), 1fr)
);
margin-bottom: var(--size-gap);
margin-top: var(--size-gap);
}
.listItem {
margin: 0;
}
.listItem::marker {
color: #e95800;
}
.listItem:nth-child(2)::marker {
color: #159bf3;
}
.listItem:nth-child(3)::marker {
color: #8eb814;
}
.listItem:nth-child(4)::marker {
color: #663399;
}
.listItemLink {
color: var(--color-primary);
font-weight: bold;
}
.listItemDescription {
color: var(--color-text);
margin-bottom: 0;
margin-top: var(--space-1);
}
.textCenter {
text-align: center;
}
.intro {
max-width: none;
line-height: var(--line-height-loose);
}

View File

@@ -0,0 +1,224 @@
:root {
--border-radius: 4px;
--color-text: #333;
--color-primary: #7026b9;
--color-code-bg: #fff4db;
--color-code: #8a6534;
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
--font-mono: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
"Courier New", monospace;
--font-lg: 18px;
--font-md: 16px;
--font-sm: 14px;
--font-sx: 12px;
--line-height-loose: 1.75;
--line-height-normal: 1.5;
--line-height-dense: 1.1;
--space-1: 4px;
--space-2: 8px;
--space-3: 16px;
--space-4: 24px;
--space-5: 32px;
--space-6: 64px;
--size-content: 54rem;
--size-gutter: var(--space-5);
--size-gap: var(--space-6);
}
html {
-webkit-text-size-adjust: 100%;
box-sizing: border-box;
font: sans-serif;
font-size: var(--font-md);
line-height: var(--line-height-normal);
overflow-y: scroll;
}
body {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
color: var(--color-text);
font-family: sans-serif;
font-family: var(--font-sans);
font-weight: normal;
margin: 0;
word-wrap: break-word;
}
a {
background-color: transparent;
color: var(--color-primary);
text-decoration: none;
font-weight: 500;
text-decoration: underline;
text-decoration-thickness: 1.5px;
text-underline-offset: 2px;
}
a:active,
a:hover {
outline-width: 0;
text-decoration: none;
}
abbr[title] {
border-bottom: 1px dotted hsla(0, 0%, 0%, 0.5);
cursor: help;
text-decoration: none;
}
b,
strong {
font-weight: inherit;
font-weight: bolder;
}
dfn {
font-style: italic;
}
h1 {
margin: 0;
margin-bottom: 3rem;
padding: 0;
line-height: var(--line-height-dense);
letter-spacing: -0.01em;
}
h1 > b {
color: var(--color-primary);
}
img {
border-style: none;
max-width: 100%;
}
code,
kbd,
pre,
samp {
font-family: var(--font-mono);
font-size: 1em;
line-height: inherit;
}
hr {
box-sizing: content-box;
overflow: visible;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding: 0;
margin-bottom: calc(var(--space-4) - 1px);
background: hsla(0, 0%, 0%, 0.2);
border: none;
height: 1px;
}
* {
box-sizing: inherit;
}
*:before {
box-sizing: inherit;
}
*:after {
box-sizing: inherit;
}
hgroup,
img,
figure,
fieldset,
ul,
ol,
dl,
dd,
p {
margin: 0;
padding: 0;
margin-bottom: var(--space-4);
}
ul,
ol {
margin-left: var(--space-4);
list-style-position: outside;
list-style-image: none;
}
pre {
margin-left: 0;
margin-right: 0;
margin-top: 0;
margin-bottom: var(--space-4);
font-size: 0.875rem;
line-height: var(--line-height-normal);
background: hsla(0, 0%, 0%, 0.04);
border-radius: var(--border-radius);
overflow: auto;
word-wrap: normal;
padding: var(--space-4);
}
b,
strong,
dt,
th {
font-weight: bold;
}
li {
margin-bottom: calc(var(--space-4) / 2);
}
ol li,
ul li {
padding-left: 0;
}
li > ol,
li > ul {
margin-bottom: calc(var(--space-4) / 2);
margin-left: var(--space-4);
margin-top: calc(var(--space-4) / 2);
}
blockquote *:last-child {
margin-bottom: 0;
}
li *:last-child {
margin-bottom: 0;
}
p *:last-child {
margin-bottom: 0;
}
li > p {
margin-bottom: calc(var(--space-4) / 2);
}
p {
max-width: 680px;
}
code {
font-size: 0.875rem;
}
kbd {
font-size: 0.875rem;
}
samp {
font-size: 0.875rem;
}
abbr {
border-bottom: 1px dotted hsla(0, 0%, 0%, 0.5);
cursor: help;
}
acronym {
border-bottom: 1px dotted hsla(0, 0%, 0%, 0.5);
cursor: help;
}
tt,
code {
background-color: var(--color-code-bg);
border-radius: var(--border-radius);
color: var(--color-code);
font-family: var(--font-mono);
padding-bottom: 0.25em;
padding-top: 0.25em;
word-break: normal;
}
pre code {
background: none;
}
code:before,
code:after,
tt:before,
tt:after {
content: "\00a0";
letter-spacing: -0.2em;
}
pre code:before,
pre code:after,
pre tt:before,
pre tt:after {
content: none;
}

View File

@@ -0,0 +1,51 @@
/**
* Layout component that queries for data
* with Gatsby's useStaticQuery component
*
* See: https://www.gatsbyjs.com/docs/how-to/querying-data/use-static-query/
*/
import * as React from "react"
import { useStaticQuery, graphql } from "gatsby"
import Header from "./header"
import "./layout.css"
const Layout = ({ children }) => {
const data = useStaticQuery(graphql`
query SiteTitleQuery {
site {
siteMetadata {
title
}
}
}
`)
return (
<>
<Header siteTitle={data.site.siteMetadata?.title || `Title`} />
<div
style={{
margin: `0 auto`,
maxWidth: `var(--size-content)`,
padding: `var(--size-gutter)`,
}}
>
<main>{children}</main>
<footer
style={{
marginTop: `var(--space-5)`,
fontSize: `var(--font-sm)`,
}}
>
© {new Date().getFullYear()} &middot; Built with
{` `}
<a href="https://www.gatsbyjs.com">Gatsby</a>
</footer>
</div>
</>
)
}
export default Layout

View File

@@ -0,0 +1,45 @@
/**
* SEO component that queries for data with
* Gatsby's useStaticQuery React hook
*
* See: https://www.gatsbyjs.com/docs/how-to/querying-data/use-static-query/
*/
import * as React from "react"
import { useStaticQuery, graphql } from "gatsby"
function Seo({ description, title, children }) {
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
description
author
}
}
}
`
)
const metaDescription = description || site.siteMetadata.description
const defaultTitle = site.siteMetadata?.title
return (
<>
<title>{defaultTitle ? `${title} | ${defaultTitle}` : title}</title>
<meta name="description" content={metaDescription} />
<meta property="og:title" content={title} />
<meta property="og:description" content={metaDescription} />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content={site.siteMetadata?.author || ``} />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={metaDescription} />
{children}
</>
)
}
export default Seo

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -0,0 +1,15 @@
import * as React from "react"
import Layout from "../components/layout"
import Seo from "../components/seo"
const NotFoundPage = () => (
<Layout>
<h1>404: Not Found</h1>
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
</Layout>
)
export const Head = () => <Seo title="404: Not Found" />
export default NotFoundPage

View File

@@ -0,0 +1,145 @@
import * as React from "react"
import { Link } from "gatsby"
import { StaticImage } from "gatsby-plugin-image"
import Layout from "../components/layout"
import Seo from "../components/seo"
import * as styles from "../components/index.module.css"
// Build-time public var (baked into bundle)
const buildPublicVar = process.env.GATSBY_BUILD_PUBLIC_VAR || 'default-value';
const links = [
{
text: "Tutorial",
url: "https://www.gatsbyjs.com/docs/tutorial",
description:
"A great place to get started if you're new to web development. Designed to guide you through setting up your first Gatsby site.",
},
{
text: "Examples",
url: "https://github.com/gatsbyjs/gatsby/tree/master/examples",
description:
"A collection of websites ranging from very basic to complex/complete that illustrate how to accomplish specific tasks within your Gatsby sites.",
},
{
text: "Plugin Library",
url: "https://www.gatsbyjs.com/plugins",
description:
"Learn how to add functionality and customize your Gatsby site or app with thousands of plugins built by our amazing developer community.",
},
{
text: "Build and Host",
url: "https://www.gatsbyjs.com/cloud",
description:
"Now youre ready to show the world! Give your Gatsby site superpowers: Build and host on Gatsby Cloud. Get started for free!",
},
]
const samplePageLinks = [
{
text: "Page 2",
url: "page-2",
badge: false,
description:
"A simple example of linking to another page within a Gatsby site",
},
{ text: "TypeScript", url: "using-typescript" },
{ text: "Server Side Rendering", url: "using-ssr" },
{ text: "Deferred Static Generation", url: "using-dsg" },
]
const moreLinks = [
{
text: "Documentation",
url: "https://gatsbyjs.com/docs/",
},
{
text: "Starters",
url: "https://gatsbyjs.com/starters/",
},
{
text: "Showcase",
url: "https://gatsbyjs.com/showcase/",
},
{
text: "Contributing",
url: "https://www.gatsbyjs.com/contributing/",
},
{ text: "Issues", url: "https://github.com/gatsbyjs/gatsby/issues" },
]
const utmParameters = `?utm_source=starter&utm_medium=start-page&utm_campaign=default-starter`
const IndexPage = () => {
React.useEffect(() => {
console.log('=== Build-time Variables ===');
console.log('GATSBY_BUILD_PUBLIC_VAR:', buildPublicVar);
}, []);
return (
<Layout>
<div style={{ padding: '20px', background: '#f0f0f0', margin: '20px', borderRadius: '8px' }}>
<h2>Environment Variable Test</h2>
<h3>Build-time (baked into bundle)</h3>
<p><strong>GATSBY_BUILD_PUBLIC_VAR:</strong> {buildPublicVar}</p>
<p style={{ color: '#666', fontSize: '14px' }}>
Note: Static sites only support build-time env vars (no server at runtime)
</p>
</div>
<div className={styles.textCenter}>
<StaticImage
src="../images/example.png"
loading="eager"
width={64}
quality={95}
formats={["auto", "webp", "avif"]}
alt=""
style={{ marginBottom: `var(--space-3)` }}
/>
<h1>
Welcome to <b>Gatsby!</b>
</h1>
<p className={styles.intro}>
<b>Example pages:</b>{" "}
{samplePageLinks.map((link, i) => (
<React.Fragment key={link.url}>
<Link to={link.url}>{link.text}</Link>
{i !== samplePageLinks.length - 1 && <> · </>}
</React.Fragment>
))}
<br />
Edit <code>src/pages/index.js</code> to update this page.
</p>
</div>
<ul className={styles.list}>
{links.map(link => (
<li key={link.url} className={styles.listItem}>
<a
className={styles.listItemLink}
href={`${link.url}${utmParameters}`}
>
{link.text}
</a>
<p className={styles.listItemDescription}>{link.description}</p>
</li>
))}
</ul>
{moreLinks.map((link, i) => (
<React.Fragment key={link.url}>
<a href={`${link.url}${utmParameters}`}>{link.text}</a>
{i !== moreLinks.length - 1 && <> · </>}
</React.Fragment>
))}
</Layout>
);
}
/**
* Head export to define metadata for the page
*
* See: https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-head/
*/
export const Head = () => <Seo title="Home" />
export default IndexPage

View File

@@ -0,0 +1,17 @@
import * as React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
import Seo from "../components/seo"
const SecondPage = () => (
<Layout>
<h1>Hi from the second page</h1>
<p>Welcome to page 2</p>
<Link to="/">Go back to the homepage</Link>
</Layout>
)
export const Head = () => <Seo title="Page two" />
export default SecondPage

View File

@@ -0,0 +1,55 @@
import * as React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
import Seo from "../components/seo"
const UsingSSR = ({ serverData }) => {
return (
<Layout>
<h1>
This page is <b>rendered server-side</b>
</h1>
<p>
This page is rendered server side every time the page is requested.
Reload it to see a(nother) random photo from{" "}
<code>dog.ceo/api/breed/shiba/images/random</code>:
</p>
<img
style={{ width: "320px", borderRadius: "var(--border-radius)" }}
alt="A random dog"
src={serverData.message}
/>
<p>
To learn more, head over to our{" "}
<a href="https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/">
documentation about Server Side Rendering
</a>
.
</p>
<Link to="/">Go back to the homepage</Link>
</Layout>
)
}
export const Head = () => <Seo title="Using SSR" />
export default UsingSSR
export async function getServerData() {
try {
const res = await fetch(`https://dog.ceo/api/breed/shiba/images/random`)
if (!res.ok) {
throw new Error(`Response failed`)
}
return {
props: await res.json(),
}
} catch (error) {
return {
status: 500,
headers: {},
props: {},
}
}
}

View File

@@ -0,0 +1,56 @@
// If you don't want to use TypeScript you can delete this file!
import * as React from "react"
import { PageProps, Link, graphql, HeadFC } from "gatsby"
import Layout from "../components/layout"
import Seo from "../components/seo"
type DataProps = {
site: {
buildTime: string
}
}
const UsingTypescript: React.FC<PageProps<DataProps>> = ({
data,
location,
}) => (
<Layout>
<h1>
Gatsby supports <b>TypeScript by default</b>
</h1>
<p>
This means that you can create and write <code>.ts/.tsx</code> files for
your pages, components, and <code>gatsby-*</code> configuration files (for
example <code>gatsby-config.ts</code>).
</p>
<p>
For type checking you'll want to install <code>typescript</code> via npm
and run <code>tsc --init</code> to create a <code>tsconfig</code> file.
</p>
<p>
You're currently on the page <code>{location.pathname}</code> which was
built on {data.site.buildTime}.
</p>
<p>
To learn more, head over to our{" "}
<a href="https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/">
documentation about TypeScript
</a>
.
</p>
<Link to="/">Go back to the homepage</Link>
</Layout>
)
export const Head: HeadFC<DataProps> = () => <Seo title="Using TypeScript" />
export default UsingTypescript
export const query = graphql`
{
site {
buildTime(formatString: "YYYY-MM-DD hh:mm a z")
}
}
`

View File

@@ -0,0 +1,26 @@
import * as React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
import Seo from "../components/seo"
const UsingDSG = () => (
<Layout>
<h1>
Hello from a <b>DSG Page</b>
</h1>
<p>This page is not created until requested by a user.</p>
<p>
To learn more, head over to our{" "}
<a href="https://www.gatsbyjs.com/docs/reference/rendering-options/deferred-static-generation/">
documentation about Deferred Static Generation
</a>
.
</p>
<Link to="/">Go back to the homepage</Link>
</Layout>
)
export const Head = () => <Seo title="Using DSG" />
export default UsingDSG