gatsby_我如何使用Gatsby和Netlify建立博客

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393923.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

交叉熵与相对熵

熵的本质是香农信息量()的期望。 现有关于样本集的2个概率分布p和q&#xff0c;其中p为真实分布&#xff0c;q非真实分布。 按照真实分布p来衡量识别一个样本的所需要的编码长度的期望(即平均编码长度)为&#xff1a;H(p)。 如果使用错误分布q来表示来自真实分布p的平均编码长度…

menustrip

在对应菜单上点击鼠标右键&#xff0c;插入&#xff0c;SEPARATOR 就可以了&#xff0c;然后可以选中拖动位置。转载于:https://www.cnblogs.com/Echo529/p/6382302.html

直接排序

题目&#xff1a;使用直接排序法将下列数组&#xff08;从小到大排序&#xff09;思路&#xff1a;第一次&#xff1a;使用索引值为0的元素与其他位置的元素挨个比较一次&#xff0c;如果发现比0号索引值的元素小的&#xff0c;那么交换位置&#xff0c;第一轮下来最小值被放在…

leetcode78. 子集(回溯)

给定一组不含重复元素的整数数组 nums&#xff0c;返回该数组所有可能的子集&#xff08;幂集&#xff09;。 说明&#xff1a;解集不能包含重复的子集。 示例: 输入: nums [1,2,3] 输出: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 代码 class Solution {pub…

php字符串综合作业,0418php字符串的操作

实例字符串函数(一):长度计算$siteName php中文网;//获取内部字符编码集$encoding mb_internal_encoding();//1、strlen($str):获取字节表示的字符串长度//utf8模式下&#xff0c;一个中文字符用三个字节表示echo strlen($siteName),; //12//2、mb_strlen($str,$encoding)&…

如何处理JavaScript中的事件处理(示例和全部)

In this blog, I will try to make clear the fundamentals of the event handling mechanism in JavaScript, without the help of any external library like Jquery/React/Vue.在此博客中&#xff0c;我将尝试在没有任何外部库(例如Jquery / React / Vue)的帮助下阐明JavaSc…

js 图片预览

//显示选择的图片缩略图function showImage(inputId,imageConfirmId,imageConfi){var imagedocument.getElementById(inputId).value.toLowerCase();if(!image){return;}var fileExtendimage.substr(image.lastIndexOf(".", image.length)1);if(!(fileExtend"jp…

什么是copyonwrite容器

2019独角兽企业重金招聘Python工程师标准>>> CopyOnWrite容器即写时复制的容器。通俗的理解是当往一个容器添加元素的时候&#xff0c;不直接往当前容器添加&#xff0c;而是先将当前容器进行Copy&#xff0c;复制出一个新的容器&#xff0c;然后新的容器里添加元素…

hystrix 源码 线程池隔离_Hystrix源码学习--线程池隔离

分析你的系统你所认识的分布式系统&#xff0c;哪些是可以进行垂直拆分的&#xff1f;拆分之后系统之间的依赖如何梳理&#xff1f;系统异构之后的稳定性调用如何保证&#xff1f;这些都是可能在分布式场景中面临的问题。说个比较常见的问题&#xff0c;大家都知道秒杀系统&…

P2341 [HAOI2006]受欢迎的牛 强连通

题目背景 本题测试数据已修复。 题目描述 每头奶牛都梦想成为牛棚里的明星。被所有奶牛喜欢的奶牛就是一头明星奶牛。所有奶 牛都是自恋狂&#xff0c;每头奶牛总是喜欢自己的。奶牛之间的“喜欢”是可以传递的——如果A喜 欢B&#xff0c;B喜欢C&#xff0c;那么A也喜欢C。牛栏…

oracle em agent,ORACLE 11G EM 配置命令及问题处理

11g装好以后&#xff0c;一直未用EM,昨天晚上和今天晚上终于抽时间把EM启动起来了&#xff0c;还遇到一点小问题&#xff0c;1.EM配置的一些命令创建一个EM资料库emca -repos create重建一个EM资料库emca -reposrecreate--------这个很主要&#xff0c;一般第一次不成功创建的时…

leetcode89. 格雷编码

格雷编码是一个二进制数字系统&#xff0c;在该系统中&#xff0c;两个连续的数值仅有一个位数的差异。 给定一个代表编码总位数的非负整数 n&#xff0c;打印其格雷编码序列。即使有多个不同答案&#xff0c;你也只需要返回其中一种。 格雷编码序列必须以 0 开头。 示例 1:…

注重代码效率_如何提升质量:注重态度

注重代码效率by Harshdeep S Jawanda通过Harshdeep S Jawanda 如何提升质量&#xff1a;注重态度 (How to skyrocket quality: focus on attitude) When it comes to discussing quality and how we can improve, the most common things that come to peoples minds are test…

spark mllib推荐算法使用

2019独角兽企业重金招聘Python工程师标准>>> 一、pom.xml <!-- 机器学习包 --><dependency><groupId>org.apache.spark</groupId><artifactId>spark-mllib_2.10</artifactId><version>${spark.version}</version>&…

Android仿QQ复制昵称效果2

本文同步自http://javaexception.com/archives/77 背景: 在上一篇文章中&#xff0c;给出了一种复制QQ效果的方案&#xff0c;今天就来讲讲换一种方式实现。主要依赖的是一个开源项目https://github.com/shangmingchao/PopupList。 解决办法: PopupList.java的代码封装的比较完…

R语言的自定义函数—字符组合

前两天写了几个函数&#xff0c;对里面收获到的一些东西做一些记录。 函数str_comb&#xff0c;用于输入一个字符串或数值向量&#xff0c;返回由向量中元素组成的不重复的长度小于向量长度的所有组合&#xff0c;结果用矩阵形式输出。 函数使用结果如下&#xff1a; 思路很简单…

oracle group by 两项,Oracle中group by 的扩展函数rollup、cube、grouping sets

Oracle的group by除了基本使用方法以外&#xff0c;还有3种扩展使用方法&#xff0c;各自是rollup、cube、grouping sets。分别介绍例如以下&#xff1a;1、rollup对数据库表emp。如果当中两个字段名为a&#xff0c;b,c。假设使用group by rollup(a,b)&#xff0c;首先会对(a,b…

leetcode1079. 活字印刷(回溯)

你有一套活字字模 tiles&#xff0c;其中每个字模上都刻有一个字母 tiles[i]。返回你可以印出的非空字母序列的数目。 注意&#xff1a;本题中&#xff0c;每个活字字模只能使用一次。 示例 1&#xff1a; 输入&#xff1a;“AAB” 输出&#xff1a;8 解释&#xff1a;可能的…

什么从什么写短句_从什么到从什么造句

从什么到从什么造句从什么到从什么怎么来造句呢?以下是小编为大家收集整理的从什么到从什么造句&#xff0c;希望对你有所帮助&#xff01;从什么到从什么造句&#xff1a;从闻到花香到看到花朵,从看到花朵到触摸到花瓣,真是一种美妙的感觉.从今天到明天&#xff0c;从明天到后…

如何开发一个hexo主题_如何确定一个强烈的主题可以使产品开发更有效

如何开发一个hexo主题by Cameron Jenkinson卡梅伦詹金森(Cameron Jenkinson) 如何确定一个强烈的主题可以使产品开发更有效 (How identifying a strong theme can make product development more effective) MVPs always seem easy to execute and build. The first version i…