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.pswp.cn/news/393923.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393923.shtml
英文地址,請注明出處:http://en.pswp.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…