项目作者: WebDevelopUa

项目描述 :
Pet-project Blog built with Gatsby v3 and MDX
高级语言: JavaScript
项目地址: git://github.com/WebDevelopUa/gatsby_03.git
创建时间: 2021-05-07T22:18:33Z
项目社区:https://github.com/WebDevelopUa/gatsby_03

开源协议:MIT License

下载


GatsbyJS 3 (Static site generator) + MDX

Pet-project Blog generated using gatsby-starter-default & MDX

  • Frontend deployed on Netlify => continuous integration from GitHub
  • Frontend deployed on Vercel => continuous integration from GitHub


Requirements:


Run in terminal

  1. npm i

Or install Gatsby project manually:

  1. npm i -g gatsby-cli
  2. gatsby --version
  3. npm install -g npm@7.10.0
  4. gatsby new gatsby-starter-default https://github.com/gatsbyjs/gatsby-starter-default
  5. gatsby clean
  6. gatsby develop

Check the result:


Netlify Newsletter

Code an HTML form into any page on your site, add a netlify attribute to the
<form>tag, and you’ll receive submissions in your Netlify dashboard.
HTML files are parsed directly at deploy time, so there’s no need for you to
make an API call or include extra JavaScript on your site.

  1. <form
  2. className="contact-form"
  3. name="newsletter-submission"
  4. netlify-honeypot="bot-field"
  5. method="POST"
  6. data-netlify="true"
  7. action="/success"
  8. >
  9. <input
  10. type="text"
  11. name="name"
  12. placeholder="Your name"
  13. className="form-control"
  14. required
  15. />
  16. <input
  17. type="email"
  18. name="email"
  19. placeholder="Your email"
  20. className="form-control"
  21. required
  22. />
  23. <input type="hidden" name="bot-field" />
  24. <input
  25. type="hidden"
  26. name="form-name"
  27. value="newsletter-submission"
  28. />
  29. <button type="submit" className="btn form-control submit-btn">
  30. Subscribe
  31. </button>
  32. </form>

Creating posts dynamically

  1. generate GraphQL query for posts
  1. query MyQuery {
  2. allMdx {
  3. nodes {
  4. frontmatter {
  5. slug
  6. }
  7. }
  8. }
  9. }
  1. paste query to gatsby-node.js
  2. create post template
  3. use import { MDXRenderer } from 'gatsby-plugin-mdx' for body content in template
  4. generate GraphQL query%0A%20%20%7D%0A%7D%0A&operationName=MyQuery>) for posts categories
  1. query MyQuery {
  2. categories: allMdx {
  3. distinct(field: frontmatter___category)
  4. }
  5. }
  1. paste query to gatsby-node.js
  2. create category template
  3. restart Gatsby server

Config Files

function wrapRootElement to wrap App in MDX Provider, that allows to intercept the elements typed in MDX

make changes in gatsby-browser & gatsby-ssr with logic in root-mdx

  1. import React from 'react'
  2. import { MDXProvider } from '@mdx-js/react'
  3. const components = {
  4. h2: props => {
  5. console.log(props)
  6. return <h2 {...props}>{props.children}</h2>
  7. },
  8. }
  9. export const wrapMDX = ({ element }) => (
  10. <MDXProvider components={components}>{element}</MDXProvider>
  11. )
  1. <h2 title="true">random h2</h2>

Errors

to avoid deployment errors => delete package-lock.json

Netlify => Published deploy => Stop auto publishing => Publish Deploy

npm i gatsby-plugin-offline

npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number
of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x ev
en if nothing is polyfilled.
Please, upgrade your dependencies to the actual version of core-js.

ERROR

(node:3700) [DEP0148] DeprecationWarning: Use of deprecated folder mapping “./“ in the “exports” field module
resolution of the package at D:\projects\gatsby_03\node_modules\postcss-js\package.json.
Update this package.json to use a subpath pattern like “./*“.

ERROR #98124 WEBPACK

Generating development JavaScript bundle failed

Can’t resolve ‘/srcpagespost.mdx?type=component’ in ‘D:\projects\gatsby_03\src\pages’

If you’re trying to use a package make sure that ‘/srcpagespost.mdx?type=component’ is installed.
If you’re trying to use a local file make sure that the path is correct.

File: src\pages\post.mdx:4:0

failed Re-building development bundle - 2.369s
ERROR in ./src/pages/post.mdx 4:0-60
Module not found: Error: Can’t resolve ‘/srcpagespost.mdx?type=component’
in ‘D:\projects\gatsby03\src\pages’
@ ./.cache/_this_is_virtual_fs_path
/$virtual/async-requires.js 31:11-33:5
@ ./.cache/app.js 17:0-52 30:0-86 32:27-40 30:0-86

webpack compiled with 1 error

Process finished with exit code 1


Markdown Cheat Sheet

Thanks for visiting The Markdown Guide!

This Markdown cheat sheet provides a quick overview of all the Markdown syntax elements.
It can’t cover every edge case, so if you need more information about any of these elements,
refer to the reference guides for basic syntax
and extended syntax.

Basic Syntax

These are the elements outlined in John Grubber’s original design document.
All Markdown applications support these elements.

Heading

H1

H2

H3

Bold

bold text

Italic

italicized text

Blockquote

blockquote

Ordered List

  1. First item
  2. Second item
  3. Third item

Unordered List

  • First item
  • Second item
  • Third item

Code

code

Horizontal Rule


title

Image

alt text

Extended Syntax

These elements extend the basic syntax by adding additional features. Not all Markdown applications support these elements.

Table

Syntax Description
Header Title
Paragraph Text

Fenced Code Block

  1. {
  2. "firstName": "John",
  3. "lastName": "Smith",
  4. "age": 25
  5. }

Footnote

Here’s a sentence with a footnote. [^1]

[^1]: This is the footnote.

Heading ID

My Great Heading {#custom-id}

Definition List

term
: definition

Strikethrough

The world is flat.

Task List

  • Write the press release
  • Update the website
  • Contact the media