gatsby

gatsby --version > -bash: gatsby: command not found

廉价感情. 提交于 2019-12-01 06:49:16
I use mac and I installed gatsby-cli by: npm install --global gatsby-cli and 'npm root -g' command prints: /usr/local/lib/node_modules/npm/lib/node_modules npm successfully installed gatsby but, I cannot run gatsby command (gatsby --version, gatsby --help) Whenever I type and run "gatsby --version" it prints: -bash: gatsby: command not found Is there any way I can fix this problem?? you have to update your config. You may have to follow few steps Set Config remove existing config npm config delete prefix set new config npm config set prefix /usr/local Install gatsby npm i -g gatsby-cli now

Connecting two gatsby nodes

[亡魂溺海] 提交于 2019-11-30 17:51:55
问题 So, I'm using the gatsby-mdx plugin to create a site from MDX files. I want to create an association between the SitePage object and the Mdx object so that I can do one graphQL query of the SitePage edges in order to construct a site navigation. Much of my code is in TypeScript, so ignore any type annotations if you're wondering WTF those are. Things I've tried Using Fields My first thought was to use the onCreateNode API, grab the MDX node, and add it to the SitePage using the

How to include local javascript on a Gatsby page?

六眼飞鱼酱① 提交于 2019-11-30 08:41:43
问题 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

How to create multiple pages from single json files in Gatsby

眉间皱痕 提交于 2019-11-30 03:56:12
I am new to node.js and react but I love gatsby.js. I have followed all the tutorials that I can find and it's such a great tool. However one of the main reasons why I want to use it is I have a file json with 1000 different records in and I would like to generate a new page for each record. I believe I have come to the conclusion that I need to learn more about the gatsby-node.js file and am aware of the following resource but are there any tutorials or other examples on this topic that maybe a little easier to follow: https://www.gatsbyjs.org/docs/creating-and-modifying-pages/#creating-pages

GatsbyJS getting data from Restful API

依然范特西╮ 提交于 2019-11-29 19:53:20
I am new in both React and GatsbyJS. I am confused and could not make figuring out in a simple way to load data from third-party Restful API. for example: I would like to fetch data from randomuser.me/API and then be able to use the data in pages. Let’s say something like this : import React from 'react' import Link from 'gatsby-link' class User extends React.Component { constructor(){ super(); this.state = { pictures:[], }; } componentDidMount(){ fetch('https://randomuser.me/api/?results=500') .then(results=>{ return results.json(); }) .then(data=>{ let pictures = data.results.map((pic,i)=>{

How to create multiple pages from single json files in Gatsby

China☆狼群 提交于 2019-11-29 01:36:11
问题 I am new to node.js and react but I love gatsby.js. I have followed all the tutorials that I can find and it's such a great tool. However one of the main reasons why I want to use it is I have a file json with 1000 different records in and I would like to generate a new page for each record. I believe I have come to the conclusion that I need to learn more about the gatsby-node.js file and am aware of the following resource but are there any tutorials or other examples on this topic that

GatsbyJS getting data from Restful API

北战南征 提交于 2019-11-28 15:39:07
问题 I am new in both React and GatsbyJS. I am confused and could not make figuring out in a simple way to load data from third-party Restful API. for example: I would like to fetch data from randomuser.me/API and then be able to use the data in pages. Let’s say something like this : import React from 'react' import Link from 'gatsby-link' class User extends React.Component { constructor(){ super(); this.state = { pictures:[], }; } componentDidMount(){ fetch('https://randomuser.me/api/?results=500

How to query date range in gatsby graphql?

十年热恋 提交于 2019-11-28 10:21:11
问题 So i have this query in graphql. But greater than(gt) and less than(lt) is not a defined field. query Test { allStrapiEvent(filter:{date:{gt:"02/13/2019"}}){ edges{ node{ name date(formatString:"MM/DD/YYYY") } } } } 回答1: It looks like date is of String type, and therefore doesn't get the comparison operators (gt, lt, gte, lte); which is a shame, because this is really useful. I think as a workaround, you can add an additional field like timestamp and store the date in number (if not already

How to create dynamic route in gatsby

柔情痞子 提交于 2019-11-28 04:40:05
问题 I have setup gatsby project using this link. It is working correctly. Now I know how to create route by defining the component inside the pages folder. But now I have a new challenge I need to create one dynamic route so that I can pass my id in it (Just like reactjs ). <Route path: "/path/:id"/> How do I do that in gatsby? 回答1: You have to explicitly tell gatsby that a path should be dynamic. From the docs: // gatsby-node.js // Implement the Gatsby API “onCreatePage”. This is // called after

add raw HTML with <script> inside Gatsby React page

匆匆过客 提交于 2019-11-27 23:51:07
I am trying to add an external embed code to my Gatsby page. I currently use import React from 'react' import Link from 'gatsby-link' let test ="<script type='text/javascript'> (function(d, s) { var useSSL = 'https:' == document.location.protocol; var js, where = d.getElementsByTagName(s)[0], js = d.createElement(s); js.src = (useSSL ? 'https:' : 'http:') + '//www.peopleperhour.com/hire/1002307300/1213788.js?width=300&height=135&orientation=vertical&theme=light&rnd='+parseInt(Math.random()*10000, 10); try { where.parentNode.insertBefore(js, where); } catch (e) { if (typeof console !==