gatsby

How to handle internationalization/localization with Gatsby JS?

对着背影说爱祢 提交于 2019-12-05 00:09:55
I would like to publish my static site in various locals around the world with localized content. How does one accomplish this? There's a community plugin gatsby-plugin-i18n that you could "use […] with react-intl, i18next, or any other i18n library. This plugin do not translate messages, it just creates routes for each language, and you can use different layouts for each language if you want to." (quoting the plugin README). Its first release is dated 30th of August 2017, so maybe you already stumbled upon it in the meantime?! I recently added a default Gatsby starter with features of multi

Executing GraphQL queries on the result of another one

血红的双手。 提交于 2019-12-04 15:42:56
I'm trying to get a list of folders name in Gatsby, along with the name of the files located inside them. Here are the 2 queries I can use : query fetchDirectories { allDirectory(filter: { relativeDirectory: { regex: "/documentation/" } }) { edges { node { name } } } } and query fetchFilesByDirectory($directory: String) { allFile(filter: { internal: { mediaType: { eq: "text/markdown" } } relativePath: { regex: $directory } }) { edges { node { name } } } } Separately, the queries are working, and I can get the good results. In my code, I'd like to execute that second query for each directories

How do you pass variables to pageQuery

自闭症网瘾萝莉.ら 提交于 2019-12-03 23:38:10
I have this page in Gatsby: import React from 'react' import Link from 'gatsby-link' import IntroPartial from '../partials/themes/intro' export default class ThemeTemplate extends React.Component { render(){ const theme = this.props.pathContext.theme console.dir(this.data) return ( <div> <h1>{theme.name}</h1> <IntroPartial theme={theme} /> </div> ) } } export const pageQuery = graphql` query ThemeQuery($theme: String){ allMarkdownRemark( filter: { frontmatter: { themes: { in: [$theme] } } } ){ edges{ node{ frontmatter{ title themes } html } } } } ` This query works fine in the GraphQL tester

Custom frontmatter variables with Markdown Remark in Gatsby.js

若如初见. 提交于 2019-12-03 23:25:59
I am building a website using Gatsbyjs and NetlifyCMS. I've started using this starter https://github.com/AustinGreen/gatsby-starter-netlify-cms , and I am trying to customise it now. I want to use custom variables in the frontmatter of a markdown file like this: --- templateKey: mirror nazev: Černobílá title: Black and White cena: '2700' price: '108' thumbnail: /img/img_1659.jpeg --- I want to acess this data with GraphQL. I use gatsby-source-filesystem and gatsby-transform-remark. This is my query: { allMarkdownRemark { edges { node { frontmatter { templateKey nazev title cena price } } } }

GraphQL queries for Gatsby - Contentful setup with a flexible content model

自古美人都是妖i 提交于 2019-12-03 09:32:28
I have a gatsby site with the contentful plugin and graphql queries (setup is working). [EDIT] My gatsby setup pulls data dynamically using the pageCreate feature. And populates my template component, the root graphql query of which I've shared below. I can create multiple pages using the setup if the pages on contentful follow the structure given in the below query. [/EDIT] My question is about a limitation I seemed to have come across or just don't know enough grpahql to understand this yet. My high level content model 'BasicPageLayout' consists of references to other content types through

Remount componentDidMount() by path.name

别来无恙 提交于 2019-12-02 18:56:28
问题 When the page loads I use componentDidMount() to document.createElement("script"); in the layout index.js of a ReactJS and GatsbyJS project as componentDidMount () { const tripadvisorLeft = document.createElement("script"); tripadvisorLeft.src = "https://www.jscache.com/wejs?wtype=selfserveprop&uniq=789&locationId=10467767&lang=en_NZ&rating=true&nreviews=0&writereviewlink=true&popIdx=true&iswide=true&border=false&display_version=2"; tripadvisorLeft.async = true; document.body.appendChild

Remount componentDidMount() by path.name

☆樱花仙子☆ 提交于 2019-12-02 10:34:18
When the page loads I use componentDidMount() to document.createElement("script"); in the layout index.js of a ReactJS and GatsbyJS project as componentDidMount () { const tripadvisorLeft = document.createElement("script"); tripadvisorLeft.src = "https://www.jscache.com/wejs?wtype=selfserveprop&uniq=789&locationId=10467767&lang=en_NZ&rating=true&nreviews=0&writereviewlink=true&popIdx=true&iswide=true&border=false&display_version=2"; tripadvisorLeft.async = true; document.body.appendChild(tripadvisorLeft); } This then requests the data to be displayed and works fine. However, when I <link to=..

How to get previous url in react gatsby

半世苍凉 提交于 2019-12-01 22:21:06
问题 I am pretty much familiar with the React.js but new to Gatsby . I want to detect the previous page URL in Gatsby ? 回答1: You can pass down state using the Link component: import React from 'react'; import { Link } from 'gatsby'; const PrevPage = () => ( <div> <Link to={`/nextpage`} state={{ prevPath: location.pathname }} > Next Page </Link> </div> ) const NextPage = (props) => ( <div> <p>previous path is: {props.location.state.prevPath}</p> </div> ); Then you have access to prevPath from this

How to include local javascript on a Gatsby page?

醉酒当歌 提交于 2019-12-01 09:26:38
I'm a total React newbie and I guess there is something fundamental I don't quite understand here. A default Gatsby page looks like this. Is there a way to use a local .js file somewhat like this? <script src="../script/script.js"></script> What I would like to achieve is to have react ignore script.js but still have the client side use it. A default Gatsby page looks like this, is it possible to do somerthing like that there? import React from "react" import { Link } from "gatsby" import Layout from "../components/layout" import Image from "../components/image" import SEO from "../components

Add ImageSharp as a field to MarkdownRemark nodes (not frontmatter)

ぐ巨炮叔叔 提交于 2019-12-01 08:54:37
问题 I have the following graphQL query I'm trying to get working: { allMarkdownRemark( limit: 1000 ) { edges { node { id parent { id } fields{ slug hero { childImageSharp { fixed { src } } } } frontmatter { template } } } } } The hero field currently returns a path to an image using the following code: exports.onCreateNode = ({ node, actions, getNode }) => { const { createNodeField } = actions // Add slug to MarkdownRemark node if (node.internal.type === 'MarkdownRemark') { const value =