gatsby

Why does PathPrefixStrip work when PathPrefix won't?

社会主义新天地 提交于 2019-12-07 11:48:08
问题 I have a GatsbyJS static site built with --prefix-paths . The pathPrefix is set to /environment/test in gatsby-config.js . It is deployed to a docker swarm running Traefik. Adding the following label to the service makes everything run ok: traefik.frontend.rule=PathPrefixStrip:/environment/test I can then browse to /environment/test and click around in my GatsbyJs site. However I find it strange since the backend is build with the path prefix. Adding the following label does not work: traefik

How to share state between child component (siblings) in ReactJS?

偶尔善良 提交于 2019-12-07 09:33:26
问题 I would like to pass state to a sibling or even a grandparent whatever. I have 3 components. Inside Header , I have a button with an onClick function to toggle a Dropdown Menu inside Navigation . And by the way, I would like to pass the same state to AnotherComponent . How to pass state (such as isDropdownOpened ) from Header to Navigation and AnotherComponent ? <div> <Header /> <Navigation /> <div> <div> <div> <AnotherComponent /> </div> </div> </div> </div> 回答1: That's the exact reason why

How do I query multiple images with gatsby-image?

久未见 提交于 2019-12-07 07:02:22
问题 I have 16 images that I want to render out onto a website in a grid format. I'm using the following plugins for this: gatsby-image gatsby-source-filesystem gatsby-plugin-sharp gatsby-transformer-sharp I read the documentation and as for as I know, it only demonstrated how to query for one single image. e.g. import React from "react" import { graphql } from "gatsby" import Img from "gatsby-image" export default ({ data }) => ( <div> <h1>Hello gatsby-image</h1> <Img fixed={data.file

Gatsby.js: Filter GraphQL query by nested object property

梦想的初衷 提交于 2019-12-07 05:35:51
问题 I'm working on a news site which will have articles, each with one or multiple respective authors. If you click on an author's name, it will take you to a page displaying their information and a list of articles they have contributed to. So each article has an authors property, which in turn is an array of author objects with properties: full name, slug ( lowercase version of full name with spaces replaced by dashes ), etc. Is it possible to filter the articles by a particular author's slug

Gatsby.js: Navigating with URL Parameters and the Browser Back / Forward Buttons

给你一囗甜甜゛ 提交于 2019-12-07 02:21:35
问题 I have an Articles component which displays a list of posts. The list is paginated so that a maximum of 10 posts can display per page. There is a "Next Page" button that when clicked will update the component state and the corresponding url parameter like so: page 1: /news page 2: /news?page=2 page 3: /news?page=3 ...and so on. The way the constructor() and render() methods are set up, it will read this URL parameter and display the correct posts if the user navigates directly to /news?page=3

Querying all images in folder using GraphQL

…衆ロ難τιáo~ 提交于 2019-12-06 20:31:40
问题 I am currently learning Gatsby.js and GraphQL as a supplementary technology and got stuck with querying. I want to query all images from a folder, map trough them and display them in a react component as a grid. I am using gatsby-source-filesystem but can't figure out, how to address specifically that folder and get all images from it. My plugin set up for source-filesystem looks like this. { resolve: `gatsby-source-filesystem`, options: { path: `${__dirname}/src/posts`, name: 'posts', }, },

Retrieve file contents during Gatsby build

假如想象 提交于 2019-12-06 14:37:22
I need to pull in the contents of a program source file for display in a page generated by Gatsby. I've got everything wired up to the point where I should be able to call // my-fancy-template.tsx import { readFileSync } from "fs"; // ... const fileContents = readFileSync("./my/relative/file/path.cs"); However, on running either gatsby develop or gatsby build , I'm getting the following error This dependency was not found: ⠀ * fs in ./src/templates/my-fancy-template.tsx ⠀ To install it, you can run: npm install --save fs However, all the documentation would suggest that this module is native

Gatsby-js client side javascript inline in blog post

南楼画角 提交于 2019-12-06 12:39:40
I am trying to setup a Blog using Gatsby-JS. I have some posts in markdown that contain inline javascript. As an example: <script>window.alert("hello");</script> I test the site using the command "Gatsby serve" When I browse to my post via the index of the blog. The script is not executed. In the web console there are no errors. When on the post page itself. If I do F5 or ctrl-f5 then the "hello" alert is displayed. After uploading the site to github pages this behavior changes. I cannot get the script to execute by F5 or by navigating via the index. Only when I press ctrl+F5 the script is

Executing GraphQL queries on the result of another one

廉价感情. 提交于 2019-12-06 10:26:36
问题 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,

how to use the Google Tag Manager plugin for gatsby?

淺唱寂寞╮ 提交于 2019-12-06 06:28:58
问题 Please note that I'm still learning to use Gatsby & React. I have been trying to figure out how to properly use the Google Tag Manager Plugin for Gatsbyjs to insert tracking codes into my app. The official documentation of the plugin does not provide a lot of insights and examples, so I'm not sure if I understand it completely. What I want to do is to insert two GTM tracking codes into my app, one in <head> and one in <body> . With the static site approach, I could just copy and paste the GTM