Skip to content

Commit

Permalink
Fix GFM features in mdx
Browse files Browse the repository at this point in the history
Also turn on linting for mdx files and fix errors
  • Loading branch information
lukekarrys committed Oct 22, 2023
1 parent 641bb04 commit 5220b7e
Show file tree
Hide file tree
Showing 23 changed files with 1,907 additions and 44 deletions.
24 changes: 23 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const {getGlobals} = require('eslint-plugin-mdx/lib/helpers')

module.exports = {
root: true,
ignorePatterns: ['.cache/', 'public/'],
Expand All @@ -10,7 +12,6 @@ module.exports = {
'plugin:github/react',
'plugin:primer-react/recommended',
'plugin:react-hooks/recommended',
'plugin:import/recommended',
'prettier',
],
rules: {
Expand All @@ -19,11 +20,32 @@ module.exports = {
'primer-react/no-system-props': ['error', {includeUtilityComponents: true}],
},
overrides: [
{
files: ['*.js'],
extends: ['plugin:import/recommended'],
},
{
files: ['src/shared.js'],
rules: {
'react/no-unescaped-entities': 'off',
},
},
{
files: ['*.mdx'],
plugins: ['mdx', 'prettier'],
extends: ['plugin:mdx/recommended'],
parserOptions: {
sourceType: 'module',
},
globals: getGlobals(['Index', 'Note', 'Prompt', 'PromptReply', 'Screenshot', 'Link', 'YouTube']),
settings: {
'import/resolver': 'webpack',
},
rules: {
'no-irregular-whitespace': 'off',
'jsx-a11y/anchor-has-content': 'off',
'react/jsx-no-target-blank': 'off',
},
},
],
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
!/content/
!/CONTRIBUTING.md
!/docs/
!/gatsby-*.js
!/gatsby-*
!/jest*.js
!/lib/
!/LICENSE*
Expand All @@ -38,4 +38,5 @@
!/static/
!/tap-snapshots/
!/test/
!/webpack.config.js
!/cli/
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Files: content/* static/*
Copyright: 2020 GitHub
License: CC-BY-4.0

Files: scripts/* cli/* theme/* src/* .github/* *.md *.js *.json .*
Files: scripts/* cli/* theme/* src/* .github/* *.md *.js *.mjs *.json .*
Copyright: 2020 GitHub
License: MIT
3 changes: 2 additions & 1 deletion cli/lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const whackAMoleReplace = (s, replacements) => {
// a bit of whack-a-mole but is necessary since markdown in the CLI is
// different from the mdx v2 we parse for the docs site
for (const rep of replacements) {
s = s.replace(rep, rep.replace(/([<>])/g, '\\$1').replace(/([{}])/g, '\\$1'))
s = s.replace(rep, rep.replace(/([<>{}])/g, '\\$1'))
}
return s
}
Expand All @@ -29,6 +29,7 @@ const unpackTarball = async ({release, cwd, dir}) => {
return (
whackAMoleReplace(s, [
'{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}',
'node/{process.version} {process.platform} {process.arch}',
'Default: {prefix}/etc/npmrc',
])
// we cant remove all emails since all except this one are in code blocks
Expand Down
2 changes: 1 addition & 1 deletion content/cli/v6/using-npm/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ Folders and executables are given a mode which is `0777` masked against this val

#### user-agent

- Default: node/{process.version} {process.platform} {process.arch}
- Default: node/\{process.version\} \{process.platform\} \{process.arch\}
- Type: String

Sets a User-Agent to the request header
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Changing your npm username
---
import shared from '~/shared.js'

It is not currently possible to change your npm username. You'll need to
create a new account and migrate the data to the new account manually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: Generating and locating npm-debug.log files
redirect_from:
- /generating-and-locating-npm-debug-log-files
---
import shared from '~/shared.js'

When a package fails to install or publish, the npm CLI will generate an `npm-debug.log` file. This log file can help you figure out what went wrong.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: Configuring your npm client with your organization settings
redirect_from:
- /configuring-your-npm-client-with-your-org-settings
---
import shared from '~/shared.js'

As an organization member, you can configure your npm client to:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For more information on semantic versioning syntax, see the [npm semver calculat

## Resources

<iframe src="https://www.youtube.com/embed/kK4Meix58R4" frameborder="0" allowfullscreen></iframe>
<YouTube id="kK4Meix58R4" />


[semver-calc]: https://semver.npmjs.com/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.printMsg = function() {

## Resources

<iframe src="https://www.youtube.com/embed/3I78ELjTzlQ" frameborder="0" allowfullscreen></iframe>
<YouTube id="3I78ELjTzlQ" />


[about-pkgs]: about-packages-and-modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ npm install example-package@beta

## Resources

<iframe src="https://www.youtube.com/embed/JDSfqFFbNYQ" frameborder="0" allowfullscreen></iframe>
<YouTube id="JDSfqFFbNYQ" />


[scoped-public-pkg]: about-scopes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ npm uninstall -g jshint

### Uninstalling local packages

<iframe src="https://www.youtube.com/embed/Z-BpYj6cSoQ" frameborder="0" allowfullscreen></iframe>
<YouTube id="Z-BpYj6cSoQ" />

### Uninstalling global packages

<iframe src="https://www.youtube.com/embed/XbvjZxUZJGg" frameborder="0" allowfullscreen></iframe>
<YouTube id="XbvjZxUZJGg" />


[cli-uninstall]: /cli/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ npm update -g

## Resources

<iframe src="https://www.youtube.com/embed/HRudtPGcOt4" frameborder="0" allowfullscreen></iframe>
<YouTube id="HRudtPGcOt4" />

### CLI commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Private packages always have a scope, and scoped packages are private by default

## Resources

<iframe src="https://www.youtube.com/embed/O6JoXGnHK_Y" frameborder="0" allowfullscreen></iframe>
<YouTube id="O6JoXGnHK_Y" />

[paid-acct]: https://www.npmjs.com/pricing
[user-pkg-add]: adding-collaborators-to-private-packages-owned-by-a-user-account
Expand Down
14 changes: 10 additions & 4 deletions gatsby-config.js → gatsby-config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const path = require('path')
const fs = require('fs')
import path from 'path'
import fs from 'fs'
import remarkGfm from 'remark-gfm'
import remarkFm from 'remark-frontmatter'

const {NODE_ENV, GATSBY_CONTENT_ALLOW, GATSBY_CONTENT_IGNORE, GATSBY_CONTENT_DIR = 'content'} = process.env
const DEV = NODE_ENV === 'development'
Expand Down Expand Up @@ -50,7 +52,7 @@ const getContentOptions = () => {
}
}

module.exports = {
const config = {
trailingSlash: 'never',
siteMetadata: {
title: 'npm Docs',
Expand All @@ -69,7 +71,9 @@ module.exports = {
{
resolve: 'gatsby-plugin-mdx',
options: {
extensions: ['.mdx', '.md'],
mdxOptions: {
remarkPlugins: [remarkGfm, remarkFm],
},
},
},
{
Expand All @@ -89,3 +93,5 @@ module.exports = {
'gatsby-plugin-meta-redirect',
],
}

export default config
24 changes: 10 additions & 14 deletions gatsby-node.js → gatsby-node.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const {join, relative} = require('path')
const {Octokit: CoreOctokit} = require('@octokit/rest')
const {throttling} = require('@octokit/plugin-throttling')
const {retry} = require('@octokit/plugin-retry')
import {join, relative} from 'path'
import {Octokit as CoreOctokit} from '@octokit/rest'
import {throttling} from '@octokit/plugin-throttling'
import {retry} from '@octokit/plugin-retry'
import webpackConfig from './webpack.config.js'

const CI = !!process.env.CI
const CWD = process.cwd()
Expand Down Expand Up @@ -42,7 +43,7 @@ const createOctokit = ({reporter}) => {
})
}

exports.onCreateNode = ({node, actions, getNode}) => {
export const onCreateNode = ({node, actions, getNode}) => {
if (node.internal.type === 'Mdx') {
const {name, relativeDirectory: dir} = getNode(node.parent)

Expand All @@ -63,14 +64,9 @@ exports.onCreateNode = ({node, actions, getNode}) => {
}
}

exports.onCreateWebpackConfig = ({stage, actions}) => {
export const onCreateWebpackConfig = ({stage, actions}) => {
actions.setWebpackConfig({
resolve: {
alias: {
'~': SRC,
},
extensions: ['.js'],
},
...webpackConfig,
})

if (stage === `build-javascript`) {
Expand All @@ -80,7 +76,7 @@ exports.onCreateWebpackConfig = ({stage, actions}) => {
}
}

exports.createSchemaCustomization = ({actions: {createTypes}}) => {
export const createSchemaCustomization = ({actions: {createTypes}}) => {
createTypes(`
type Mdx implements Node {
frontmatter: MdxFrontmatter
Expand All @@ -101,7 +97,7 @@ exports.createSchemaCustomization = ({actions: {createTypes}}) => {
`)
}

exports.createPages = async ({graphql, actions, reporter}) => {
export const createPages = async ({graphql, actions, reporter}) => {
const response = await graphql(`
{
allMdx {
Expand Down
Loading

0 comments on commit 5220b7e

Please sign in to comment.