gatsby

by Pav Sidhu

通过帕夫·西杜(Pav Sidhu)

我如何使用Gatsby和Netlify建立博客 (How I Built My Blog Using Gatsby and Netlify)

您能说出更具标志性的二人​​组合吗? ? (Can you name a more iconic duo? ?)

Years ago, whenever I built a static website, I didn’t use any fancy frameworks or build tools. The only thing I brought into my projects was jQuery, or if I was feeling extra fancy, I used Sass.

多年前,每当我建立一个静态网站时,我就没有使用任何精美的框架或工具。 我带到项目中的唯一东西是jQuery,或者如果我觉得自己很花哨,可以使用Sass。

Nowadays, we have tools like Gatsby and Netlify, which greatly improve the experience of building static websites. Rather than thinking about boilerplate and configuration (looking at you Webpack), you can just focus on your application.

如今,我们拥有Gatsby和Netlify等工具,这些工具极大地改善了构建静态网站的体验。 无需考虑样板和配置(看着Webpack),您只需专注于您的应用程序即可。

I wouldn’t hesitate to say that the Gatsby and Netlify flow is the best programming experience I’ve ever had. Let me explain why.

我会毫不犹豫地说Gatsby和Netlify流程是我所拥有的最佳编程体验。 让我解释一下原因。

盖茨比 (Gatsby)

Gatsby is a static site generator that uses React. Everything is configured out of the box including React, Webpack, Prettier, and more.

Gatsby是使用React的静态站点生成器。 开箱即用地配置了所有内容,包括React,Webpack,Prettier等。

Since Gatsby builds on top of React, you get all the benefits of React, such as its performance, components, JSX, React library ecosystem, and a large community (React is nearing 100,000 stars on GitHub ?).

由于Gatsby建立在React之上,因此您可以获得React的所有优势,例如其性能,组件,JSX,React库生态系统和一个大型社区(GitHub上的React接近100,000个星?)。

If you haven’t used React before, there is a learning curve. But there are plenty of well-written tutorials that make React very accessible. The official React documentation is also very well written.

如果您以前没有使用过React,那将是一条学习曲线。 但是有很多写得很好的教程使React非常易于访问。 官方的React文档也写得很好。

For many static websites like my blog, I need to use external data sources (my actual blog posts) during the build process. Gatsby provides support for many forms of data, including Markdown, APIs, Databases, and CMSs like WordPress. To access this data, Gatsby uses GraphQL.

对于像我的博客这样的许多静态网站,我需要在构建过程中使用外部数据源(我的实际博客文章)。 Gatsby支持多种形式的数据,包括Markdown,API,数据库和WordPress之类的CMS。 要访问此数据,Gatsby使用GraphQL。

All my blog posts are in Markdown, so I’m using a Gatsby plugin (gatsby-transformer-remark) that lets me query my Markdown files using GraphQL. It also converts a Markdown file to HTML straight out of the box like magic. I simply need to use the following GraphQL query to access a specific post:

我所有的博客文章都在Markdown中,所以我使用的是Gatsby插件( gatsby-transformer-remark ),该插件使我可以使用GraphQL查询Markdown文件。 它还像魔术一样直接将Markdown文件转换为HTML。 我只需要使用以下GraphQL查询来访问特定的帖子:

query BlogPostByPath($path: String!) {  markdownRemark(frontmatter: { path: { eq: $path } }) {    frontmatter {      title      date(formatString: "Do MMMM YYYY")    }    html  }}

Using this query, I access the data through my props like so:

使用此查询,我可以通过自己的道具访问数据,如下所示:

const BlogPost = ({ props: { data: { markdownRemark } } }) => (  <div>    <h1>{markdownRemark.title}</h1>    <p>{markdownRemark.date}<p>    <div dangerouslySetInnerHTML={{ __html: markdownRemark.html }} />  </div>)

If you understand GraphQL, accessing data from Markdown using Gatsby feels right at home. If GraphQL is new to you, it does add yet another thing to learn. But the documentation on using GraphQL with Gatsby has plenty of information and code snippets that you can use.

如果您了解GraphQL,则可以使用Gatsby从Markdown访问数据。 如果GraphQL对您来说是新手,它确实增加了另一件事要学习。 但是,将GraphQL与Gatsby一起使用的文档中有大量信息和代码片段可供您使用。

If you are building a simple blog with only one or two queries, there are Gatsby starter kits that set up gatsby-transformer-remark and all the querying for you. To speed up development, I used one called gatsby-starter-blog-no-styles.

如果您要建立一个仅包含一个或两个查询的简单博客,则可以使用Gatsby入门套件来设置gatsby-transformer-remark以及所有查询。 为了加快开发速度,我使用了一种称为gatsby-starter-blog-no-styles的方法 。

I am a huge fan of styled-components, so I tried to use it when building this blog. I did encounter an issue, since there was no way for me to specify to gatsby-transformer-remark how to style my components. Instead I had to use plain CSS for styling. I would love to see something like the following in gatsby-config.js :

我非常喜欢样式化组件,因此在构建此博客时尝试使用它。 我确实遇到了一个问题,因为我无法指定gatsby-transformer-remark如何设置组件样式。 相反,我不得不使用普通CSS进行样式设计。 我希望在gatsby-config.js看到类似以下内容:

import styled from 'styled-components'
const Header = styled.h1`  font-size: 24px;  color: #333333;`
module.exports = {  plugins: [    {      resolve: 'gatsby-transformer-remark',      options: {        h1: Header      }    }  ]}

In addition to the ease of actually using Gatsby, the official documentation is very well written and up to date. Each guide in the docs explain concepts of Gatsby so well, it’s likely that in most cases you won’t need to check any third party source of information.

除了实际使用Gatsby的便利性之外, 官方文档的书写方式也很好,并且是最新的。 文档中的每本指南都很好地解释了盖茨比的概念,在大多数情况下,您可能不需要检查任何第三方信息源。

The only difficulty I had with Gatbsy was when I deployed my website. I had a FOUC (flash of unstyled content). I found that upgrading Gatsby from 1.8.12 to 1.9.250 fixed the issue. I’m not too sure why this fixed it, and I assume it must have been an internal issue with Gatsby.

我对Gatbsy的唯一困难是在部署网站时。 我有一个FOUC(未样式化内容的闪烁)。 我发现将盖茨比从1.8.12升级到1.9.250可以解决此问题。 我不太确定为什么要解决此问题,并且我认为它一定是盖茨比的内部问题。

Netlify (Netlify)

Usually, when building a static website, I’ll use GitHub pages because it’s free and fairly easy to set up. Although I still think GitHub pages is a great tool, Netlify takes the process one step further to make the developer experience even more efficient.

通常,在构建静态网站时,我会使用GitHub页面,因为它是免费的,而且设置起来也很容易。 尽管我仍然认为GitHub页面是一个很好的工具,但Netlify进一步将这一过程进一步提高了开发人员的体验效率。

Once you’ve hooked up Netlify to your repo, each push to your GitHub repository automatically builds your website, according to the static site generator you’re using, and deploys it to production.

将Netlify连接到仓库后 ,每次推送到GitHub存储库都会根据您使用的静态站点生成器自动构建您的网站,并将其部署到生产环境中。

I currently only use Netlify for static site hosting. But it also supports cloud functions, domain management (with SSL), form submissions, a/b testing, and more.

我目前仅将Netlify用于静态站点托管。 但它也支持云功能,域管理(使用SSL),表单提交,A / B测试等。

Netlify’s web interface is also clean and easy to use. The difference from AWS is night and day. While AWS is highly configurable, many developers don’t use this functionality. When I first used S3 or Lambda (Amazon’s static file and cloud function services), I spent a considerable amount of time looking up Amazon’s difficult and sometimes out-of-date documentation. There is a whole lot of unneeded complexity and Amazon jargon when using AWS. In comparison, Netlify is a breath of fresh air. It’s one of those services that just works.

Netlify的Web界面也干净且易于使用。 与AWS的区别是白天和黑夜。 尽管AWS具有高度可配置性,但许多开发人员并未使用此功能。 当我第一次使用S3或Lambda(Amazon的静态文件和云功能服务)时,我花费了大量时间查找Amazon的困难文档,有时甚至是过时的文档。 使用AWS时,有很多不必要的复杂性和Amazon行话。 相比之下,Netlify则是新鲜空气。 这只是其中的一项服务 作品

The best part about Netlify is that it’s free. If you’re in a large team or need more resources for cloud functions, form submissions, and more, they do have paid options. If you plan on building a small blog like I am, it’s unlikely you’ll need to pay for anything.

关于Netlify的最好的部分是它是免费的。 如果您是一个大型团队,或者需要更多资源用于云功能,表单提交等等,那么他们确实有付费选择。 如果您打算建立像我这样的小型博客,那么您就不必为任何事情付费。

TL; DR (TL;DR)

Gatsby and Netlify are the easiest way to build and publish a static website. Period.

Gatsby和Netlify是构建和发布静态网站的最简单方法。 期。

If you would like an example of how to build a blog using Gatsby, the code for my blog is available on GitHub.

如果您想使用Gatsby构建博客的示例, 可以在GitHub上找到我的博客的代码。

This post was originally published on my blog: How I Built My Blog Using Gatsby and Netlify

这篇文章最初发布在我的博客上: 我如何使用Gatsby和Netlify建立我的博客

Thanks for reading, please ? if you found this useful! I’d love to hear your thoughts on Gatsby and Netlify in the comments.

谢谢阅读,好吗? 如果您觉得这有用! 我很乐意在评论中听到您对盖茨比和Netlify的看法。

翻译自: https://www.freecodecamp.org/news/how-i-built-my-blog-using-gatsby-and-netlify-f921f1a9f33c/

gatsby

gatsby_我如何使用Gatsby和Netlify建立博客相关推荐

  1. 宝塔linux_宝塔面板建站基础教程:如何安装宝塔面板及建立博客网站

    大多数站长购买服务器特别是 Linux 服务器后一般都会选择安装宝塔面板来管理和维护服务器,但是有些新手站长总是担心自己不懂得如何在云服务器上安装宝塔面板,又或者成功安装了宝塔面板之后不懂得如何通过面 ...

  2. 使用 Gatsby.js 搭建静态博客 2 实现分页

    原文地址:https://ssshooter.com/2018-12... 使用 Gatsby.js 搭建静态博客 1 关键文件 <- 本文将会介绍如何为初始项目添加分页功能. 理解页面创建原理 ...

  3. 宝塔面板windows建站教程_宝塔Windows面板IIS环境如何建立博客网站

    摘要: 简介Windows系统服务器一般都是安装 IIS环境,其他两个环境(Apache 和 Nginx)一般是在 Linux 服务器上运行会比windows更稳定,windows系统推荐... 简介 ...

  4. 关于github page 建立博客访问404

    自己在建立博客时,遇到了访问地址出现404的情况,我相信很多人都会遇到过吧 我找了好久发现找到了一篇  ,经过自己的实践证实,是正确的.(截取自网友的博客内容) 创建GitHub Pages 我们托管 ...

  5. 运用hexo建立博客的几个坑

    欢迎访文我的博客YangChen's Blog 经过差不多4个多小时的折腾终于完成了hexo+github pages的建站,申请的域名还在审核所以先暂用github上的域名吧. 建立博客的过程十分曲 ...

  6. 重新建立博客的一段话

    很早就玩了搜狐博客,但是就像其他的网络应用一样,时间久了就没了兴趣,原来的搜狐博客一直当日记,当回忆录写,写了一年多,后来发现写的私密的东西太多,就把权限全给封了,也不再写了,当然现在搜狐博客的服务也 ...

  7. 如何使用Gatsby创建自己的博客

    首发于Enaium的个人博客 首先使用npm安装gatsby,使用gatsby –version命令可以查看是否安装 npm install -g gatsby-cli 使用new命令后面跟着目录名, ...

  8. 使用 Gatsby.js 搭建静态博客 EX 使用语雀发布到博客

    原文链接:https://ssshooter.com/2019-01... 偶然看到通过语雀 webhook 发布文章到 Hexo 静态博客,很方便,实现过程也很有意思.同样的原理可以运用到 Gats ...

  9. z-blog建立博客网站SEO优化细节教程

    z-blog博客系统深受广大个人站长喜爱,于是我也跟风做了一个个人博客网站,看人家权重达到权重6,看的实在眼红,于是自己操刀做了一个,但是SEO优化了很久,不尽人意,正好印证了"思想很饱满, ...

最新文章

  1. 乐视视频 App 图标改为“欠 122 亿”,网友:我在别家分红包,却在你家随份子!...
  2. 修改上传附件大小限制方法
  3. 量子计算机模型取,Grover算法在单道量子计算模型下的实现
  4. printf()详解
  5. Python—实训day7上—Nmupy数值计算基础
  6. nms python代码_?标检测中的?极?值抑制算法(nms):python代码解析
  7. Titanium快速开发app
  8. 【模拟电路知识】运算放大器没有反馈电路——做电压比较器应用
  9. SpringCloud-服务网关
  10. css3中transition过渡和animation动画的区别
  11. 真正“透明”的PNG图片
  12. 深信服设备连接linux,deepin官方论坛-深度科技官网旗下网站
  13. proxy代理解决跨域问题
  14. Http 3840 错误
  15. win7更新_微软最新累积更新导致Win7及以上版本VB6/VBA/VBS运行异常
  16. 公路平曲线及主点桩号计算
  17. Tensorboard打开方式
  18. 【名家名作】写意里有工笔 婉约中透豪气
  19. hashmap中的key是有序的么_HashMap是无序的
  20. [Visual Studio 2022 C#]使用SplitContainer拆分器让一个Windows窗口秒变多个

热门文章

  1. cloudera-quickstart-vm-5.13.0-0-virtualbox 中文显示乱码
  2. 萌新向Python数据分析及数据挖掘 第三章 机器学习常用算法 第四节 PCA与梯度上升 (上)理解篇...
  3. 第4章 springboot热部署 4-1 SpringBoot 使用devtools进行热部署
  4. 测试工具之badboy
  5. [BZOJ2599][IOI2011]Race 点分治
  6. QT连接多种数据库f方法及测试
  7. WPF自定义控件之列表滑动特效 PowerListBox
  8. RDLC系列之五 初试XAML
  9. nginx编译安装时添加echo模块
  10. [编程题] 按照左右半区的方式重新组合单链表