參考連結: https://www.gatsbyjs.com/docs/
Layout, Component, CSS module, query
Gatsby 頁面常用 component 及 Styling 官方教學
Gatsby Link
Use the <Link> component
// src/pages/index.js
import * as React from 'react'
import { Link } from 'gatsby'
const IndexPage = () => {
return (
<main>
<title>Home Page</title>
<h1>Welcome to my Gatsby site!</h1>
<Link to="/about">About</Link>
<p>I'm making this by following the Gatsby Tutorial.</p>
</main>
)
}
export default IndexPage
npm run develop
gatsby develop
網址:http://localhost:8000/___graphql
query MyQuery {
site {
siteMetadata {
title
}
}
}
{
"data": {
"site": {
"siteMetadata": {
"title": "My First Gatsby Site"
}
}
},
"extensions": {}
}
import * as React from 'react'
import { Link, useStaticQuery, graphql } from 'gatsby'
import {
container,
heading,
navLinks,
navLinkItem,
navLinkText
} from './layout.module.css'
const Layout = ({ pageTitle, children }) => {
const data = useStaticQuery(graphql`
query {
site {
siteMetadata {
title
}
}
}
`)
return (
<div className={container}>
<title>{pageTitle} | {data.site.siteMetadata.title}</title>
<header>{data.site.siteMetadata.title}</header>
</div>
)
}
export default Layout
gatsby-config.js
file.用 npm 安裝該套件
npm install plugin-name
修改並設定 gatsby-config.js
// gatsby-config.js
module.exports = {
siteMetadata: {
title: "My First Gatsby Site",
},
plugins: [
{
resolve: "plugin-name",
options: {
// Check the plugin README for what options go in here
}
},
]
}
"gatsby-plugin-image"
"gatsby-plugin-sharp"