gatsby

I have been a Gatsby user since around version 0 back in May 2017.

自2017年5月左右发布第0版以来,我一直是Gatsby用户。

Back then, I was using a template called Lumen. It was just what I needed at the time. Since then I have gone from using a template to creating my blog.

那时,我使用的模板叫做Lumen 。 当时正是我所需要的。 从那以后,我从使用模板转到了创建博客。

Over the years I have built my own Progressive Disclosure of Complexity with Gatsby to where I am now.

多年来,我已经与盖茨比建立了自己的渐进式复杂度披露体系 ,直至现在。

那是什么意思? (What does that mean?)

It means that although there are an awesome amount of Gatsby starters and themes out there to get you up and running in minutes, this post is going to focus on what you need to do to build your own blog. Starting with the most basic “Hello World!” to deploying your code to production.

这意味着,尽管那里有大量的盖茨比启动器和主题可以让您在数分钟内启动并运行,但本文将着重于构建自己的博客所需的工作。 从最基本的“ Hello World!”开始 将代码部署到生产中。

你要建造什么 (What you’re going to build)

You’re going to build a developer blog with MDX support (for some React components in Markdown goodness), so you will be able to add your own React components into your Markdown posts.

您将建立一个具有MDX支持的开发者博客(针对Markdown的一些React组件),因此您将能够在Markdown帖子中添加自己的React组件。

There’ll be:

将会有:

  • Adding a Layout添加布局
  • Basic styling with styled-components具有样式化组件的基本样式
  • Code blocks with syntax highlighting带有语法突出显示的代码块
  • Copy code snippet to clipboard将代码段复制到剪贴板
  • Cover images for the posts帖子的封面图片
  • Configuring an SEO component配置SEO组件
  • Deploying it to Netlify部署到Netlify

此操作方法适用于谁? (Who is this how-to for?)

People that may have used Gatsby before as a template and now want to get more involved in how to make changes.

以前可能使用Gatsby作为模板的人,现在希望更多地参与如何进行更改。

If you want to have code syntax highlighting.

如果要突出显示代码语法。

If you want to use styled-components in an app.

如果要在应用程序中使用样式化组件。

I really want to avoid this!

我真的很想避免这种情况!

要求 (Requirements)

You’re going to need a basic web development setup: node, terminal (bash, zsh or fish) and a text editor.

您将需要一个基本的Web开发设置:节点,终端(bash,zsh或fish)和文本编辑器。

I do like to use codesandbox.io for these sort of guides to reduce the barrier to entry but in this case I have found there are some limitations with starting out from scratch on codesandbox.io which doesn’t make this possible.

我确实喜欢将codesandbox.io用于此类指南,以减少进入的障碍,但是在这种情况下,我发现从codesandbox.io的白手起家存在一定的局限性,这无法实现。

I have made a guide on getting set up for web development with Windows Web-Dev Bootstrap and covered the same process in Ubuntu as well.

我已经为使用Windows Web-Dev Bootstrap进行Web开发设置做了一个指南,并且也介绍了Ubuntu中的相同过程。

Ok? Time to get started!

好? 是时候开始了!

你好,世界 (Hello World)

To kick this off with the Gatsby ‘hello world’, you’ll need to initialise the project with:

要使用盖茨比“ hello world”开始这一工作,您需要使用以下代码初始化该项目:

npm init -y
git init

I suggest that you commit this code to a git repository, so you should start with a .gitignore file.

我建议您将此代码提交到git存储库,因此您应该以.gitignore文件开头。

touch .gitignoreecho "# Project dependencies
.cache
node_modules# Build directory
public# Other
.DS_Store
yarn-error.log" > .gitignore

Ok now is a good time to do a git init and if you’re using VSCode you’ll see the changes reflected in the sidebar.

好了,现在是进行git init的好时机,如果您使用的是VSCode,您会在侧边栏中看到更改。

基本的问候世界 (basic hello world)

Ok a Gatsby hello world, get started with the bare minimum! Install the following:

好的,盖茨比世界你好,请从最低限度开始! 安装以下内容:

yarn add gatsby react react-dom

You’re going to need to create a pages directory and add an index file. You can do that in the terminal by typing the following:

您将需要创建一个页面目录并添加一个索引文件。 您可以在终端中输入以下命令来执行此操作:

# -p is to create parent directories too if needed
mkdir -p src/pages
touch src/pages/index.js

Now you can commence the hello word incantation! In the newly created index.js enter the following:

现在您可以开始打招呼了! 在新创建的index.js输入以下内容:

import React from 'react';export default () => {return <h1>Hello World!</h1>;
};

Now you need to add the Gatsby develop script to the package.json file, -p specifies what port you want to run the project on and -o opens a new tab on your default browser, so in this case localhost:9988:

现在,您需要将Gatsby开发脚本添加到package.json文件, -p指定要在其上运行项目的端口,并且-o在默认浏览器上打开一个新标签,因此在本例中为localhost:9988

"dev": "gatsby develop -p 9988 -o"

And now it’s time to run the code! From the terminal type the npm script command you just created:

现在该运行代码了! 在终端中,输入您刚刚创建的npm脚本命令:

yarn dev

Note I’m using Yarn for installing all my dependencies and running scripts. If you prefer you can use npm, just bear in mind that the content on here uses yarn, so swap out commands where needed.

注意我正在使用Yarn来安装我的所有依赖项并运行脚本。 如果愿意,可以使用npm,请记住这里的内容使用yarn,因此请在需要的地方换出命令。

And with that the “Hello World” incantation is complete

gatsby_如何使用Gatsby和MDX从头开始构建编码博客相关推荐

  1. so easy!从头教你用mkdocs构建个人博客系统~

    本文主要介绍如何使用mkdocs构建个人网站. 文章目录 1. mkdocs介绍 2. mkdocs安装 3. mkdocs简单使用 3.1 入门使用 3.2 Markdown语法 3.3 YAML语 ...

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

    gatsby by Pav Sidhu 通过帕夫·西杜(Pav Sidhu) 我如何使用Gatsby和Netlify建立博客 (How I Built My Blog Using Gatsby and ...

  3. gatsby_如何使用Gatsby.js来获取内容

    gatsby by Dimitri Ivashchuk 由Dimitri Ivashchuk 如何使用Gatsby.js来获取内容 (How to source content with Gatsby ...

  4. vue使用pwa_如何使用HTML,CSS和JavaScript从头开始构建PWA

    vue使用pwa Progressive web apps are a way to bring that native app feeling to a traditional web app. W ...

  5. 微软todo使用教程_Todo教程可能很有趣-但是,这是从头开始构建自己的项目的方法...

    微软todo使用教程 There are many great tutorials that walk you through creating apps, from simple todo list ...

  6. 数据分析从头学_数据新闻学入门指南:让我们从头开始构建故事

    数据分析从头学 by Mina Demian 由Mina Demian 数据新闻学入门指南:让我们从头开始构建故事 (A Beginner's Guide to Data Journalism: Le ...

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

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

  8. 9步教你用NumPy从头开始构建神经网络!

    https://www.toutiao.com/a6693296472533762574/ 动机 如果你是一个了解神经网络如何工作的初级数据科学家,或者只是对深度学习有所了解的机器学习爱好者,那么这篇 ...

  9. 深度学习表征的不合理有效性——从头开始构建图像搜索服务(二)

    摘要:还在为搜索引擎的工作原理感到困惑吗?看完本篇就可以自己动手构建搜图服务了. 接着上篇<深度学习表征的不合理有效性--从头开始构建图像搜索服务(一)>的内容,上次遇到的问题是搜索相似图 ...

最新文章

  1. 一些NLP的入门资料参考
  2. GDCM:gdcm::Object的测试程序
  3. php 如何快速判断一个数字属于什么范围
  4. 使用TensorFlow进行鬼写
  5. 五年级信息技术上册教案计算机主机探秘,第1课信息与信息技术探秘教案
  6. 【模板/经典题型】并查集维护生成树
  7. illegal utf8 encoding at (190)
  8. java valid payload_Spring Validation最佳实践及其实现原理,参数校验没那么简单!
  9. paip.编程压缩Access数据库
  10. 电机学重难点归纳(长期更新)
  11. 转载:IEEE1588 ( PTP ) 协议简介
  12. The PyTorch-Kaldi Speech Recognition Toolkit
  13. H3C交换机级联式堆叠配置方式
  14. MC最强辅助模组,有了它从此下矿再也不怕了
  15. GEE|在地图上显示传入的shp数据
  16. 话机按键音效——DTMF生成
  17. python excelwriter保存路径_从Excel中解救你!如何用Python实现报表自动化
  18. ubuntu22.04安装惠普激光打印机m30w记录
  19. C语言中文网-CPPSTL
  20. 200个Java必背词汇

热门文章

  1. 草稿 断开式数据连接
  2. flask-稿件-环境依赖包的生成与安装-flask虚拟环境的布局
  3. linux-基本权限UGO-读写执行权限
  4. jquey-jsonp-跨域请求数据
  5. TIDB2.1版本升级步骤
  6. linux禁用root登录
  7. 转载 实践与分享:Windows 7怎么获取TrustedInstaller权限【图文教程】
  8. vsftp 虚拟用户测试
  9. Matlab norm 用法小记
  10. ecshop操作数据库类