Hiển thị các bài đăng có nhãn Gatsby. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Gatsby. Hiển thị tất cả bài đăng

How to use _embed when using _fields?

 https://wordpress.stackexchange.com/questions/363868/how-to-use-embed-when-using-fields

It is not clear in the documentation, but you need to include the "_links" and "_embedded" as fields to be returned. In addition, I include the _embed parameter, as it does not require a value. As of WordPress 5.4, the resources to embed can be limited by passing a list of link relation names to the _embed parameter, though I have not had success with that when using _fields

Example:

domain.com/wp-json/wp/v2/posts?_fields=link,title,featured_media,_links,_embedded&_embed

Gatsby Tip on Running Multiple Queries

 https://medium.com/analytics-vidhya/gatsby-tip-on-running-multiple-queries-graphql-aliases-dc978fe481da

Gatsby Tip on Running Multiple Queries (GraphQL Aliases)

Say you want to fetch specific data in one page based on an argument or a condition which can’t be run using one query as you can’t query the same field with different condition or argument. One way of doing that by using GraphQL aliases which you can use to rename the returned dataset to anything you want.

Example

export const query = graphql`
query {
post: allMarkdownRemark(
limit: 3
sort: { order: DESC, fields: [frontmatter___date] }
filter: { frontmatter: { type: { ne: "portfolio" } } }
) {
edges {
node {
timeToRead
frontmatter {
title
path
date(formatString: "DD MMMM YYYY")
summary
images
tags
type
}
}
}
}
portfolio: allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] }
filter: { frontmatter: { type: { eq: "portfolio" } } }
) {
edges {
node {
frontmatter {
title
path
images
tags
type
}
}
}
}
siteMetaData: site {
siteMetadata {
title
}
}
}
`;

Looking at the above example, we can see the query I made will return multiple datasets by giving it an alias which allowed me to run multiple queries with different arguments and conditions to get the specific data object I needed as you can see in the screenshot.

graphql aliases

How do I create subpages for urls?

 https://spectrum.chat/gatsby-js/general/how-do-i-create-subpages-for-urls~d9511651-a91f-4a0f-8c13-4e5c6e186350

For example, If I have a page anesthesiologists, and I want to have a page with the url with "anesthesiologists/more-time", how do I preface the link? These are all files in the pages folder.


Put them inside a folder anesthesiologists

GatsbyJs - Add environment variables

 https://dev.to/kapilgorve/gatsbyjs-add-environment-variables-1io5

Development Environment

  • Create a new file named as .env.development at the root of your project.
  • Add your variable to the newly created file. Example - TEST_KEY=123
  • Change your npm run develop command to set environment.

For Windows -

    "develop": "set GATSBY_ENV=development && gatsby develop"

For Linux -

    "develop": "GATSBY_ENV=development gatsby develop"
  • Restart your dev environment. So Gatsby will load your new env file.
  • You should be able to access your env variables using process.env.TEST_KEY in any js file.

Production Environment

  • Create a new file named as .env.production at the root of your project.
  • Add your variable to the newly created file. Example - TEST_KEY=123
  • Change your npm run build command to set environment.

For Windows -

    "develop": "set GATSBY_ENV=production && gatsby develop"

For Linux -

    "build": "GATSBY_ENV=production gatsby build",

This is only if you want to build on local.

If you are using any providers like Netlify use the Linux version. You will also need to add environment variables in the service provider.

For Netlify it is in Site Settings > Build&Deploy > Environment

This post was originally published at https://www.jskap.com/blog/gatsby-add-environment-variables/

Renewing Facebook Graph API token automatically?

  Mã truy cập dài hạn https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived/ https://community.n8n.io/t/re...