From 165d4a5961624e0d532fc977041ae76eb27c3164 Mon Sep 17 00:00:00 2001 From: emplums Date: Tue, 2 Apr 2019 22:36:44 -0700 Subject: [PATCH] remove old lib --- lib/config.js | 43 ------------------------------- lib/mdx-loader.js | 48 ----------------------------------- lib/rehype-prism.js | 62 --------------------------------------------- 3 files changed, 153 deletions(-) delete mode 100644 lib/config.js delete mode 100644 lib/mdx-loader.js delete mode 100644 lib/rehype-prism.js diff --git a/lib/config.js b/lib/config.js deleted file mode 100644 index b2a3ace4..00000000 --- a/lib/config.js +++ /dev/null @@ -1,43 +0,0 @@ -/* eslint-disable no-console */ -const {NODE_ENV, NOW_URL} = process.env - -module.exports = (nextConfig = {}) => { - const {assetPrefix = NOW_URL || ''} = nextConfig - - return Object.assign({}, nextConfig, { - assetPrefix, - pageExtensions: ['js', 'jsx', 'md', 'mdx'], - - publicRuntimeConfig: Object.assign( - { - assetPrefix, - production: NODE_ENV === 'production' - }, - nextConfig.publicRuntimeConfig - ), - - webpack(config, options) { - if (!options.defaultLoaders) { - throw new Error( - 'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade' - ) - } - - config.module.rules.push({ - test: /\.svg$/, - use: '@svgr/webpack' - }) - - config.module.rules.push({ - test: /\.mdx?$/, - use: [options.defaultLoaders.babel, require.resolve('./mdx-loader')] - }) - - if (typeof nextConfig.webpack === 'function') { - return nextConfig.webpack(config, options) - } - - return config - } - }) -} diff --git a/lib/mdx-loader.js b/lib/mdx-loader.js deleted file mode 100644 index 8072d69f..00000000 --- a/lib/mdx-loader.js +++ /dev/null @@ -1,48 +0,0 @@ -const {getOptions} = require('loader-utils') -const mdx = require('@mdx-js/mdx') - -const emoji = require('remark-emoji') -const images = require('remark-images') -const rehypePrism = require('./rehype-prism') -const textr = require('remark-textr') -const toc = require('remark-toc') - -const mdxExportJSONByDefault = require('mdx-constant') -const grayMatter = require('gray-matter') -const typographicBase = require('typographic-base') - -module.exports = async function(source) { - let result - const {data, content: mdxContent} = grayMatter(source) - const callback = this.async() - - const options = Object.assign( - { - mdPlugins: [ - [toc, {heading: '(table of|section)? contents'}], - images, - emoji, - [textr, {plugins: [typographicBase]}] - ], - hastPlugins: [rehypePrism], - compilers: [mdxExportJSONByDefault('frontMatter', data)] - }, - getOptions(this), - {filepath: this.resourcePath} - ) - - try { - result = await mdx(mdxContent, options) - } catch (err) { - return callback(err) - } - - return callback( - null, - ` -import React from 'react' -import {MDXTag} from '@mdx-js/tag' -${result} -` - ) -} diff --git a/lib/rehype-prism.js b/lib/rehype-prism.js deleted file mode 100644 index 4290825b..00000000 --- a/lib/rehype-prism.js +++ /dev/null @@ -1,62 +0,0 @@ -const visit = require('unist-util-visit') -const nodeToString = require('hast-util-to-string') -const nodeToHTML = require('hast-util-to-html') -const refractor = require('refractor') - -const aliases = { - js: 'jsx', - html: 'markup' -} - -module.exports = options => { - options = options || {} - - return tree => visit(tree, 'element', visitor) - - function visitor(node, index, parent) { - if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') { - return - } - - const lang = getLanguage(node, options.aliases || aliases) - - if (lang === null) { - return - } - - let result = node - const source = nodeToString(node) - try { - parent.properties.className = (parent.properties.className || []).concat(`language-${lang}`) - result = refractor.highlight(source, lang) - } catch (err) { - if (/Unknown language/.test(err.message)) { - return - } - throw err - } - - node.children = [] - node.properties.source = source - node.properties.dangerouslySetInnerHTML = { - __html: nodeToHTML({ - type: 'root', - children: result - }) - } - } -} - -function getLanguage(node, aliases) { - const className = node.properties.className || [] - - for (const classListItem of className) { - if (classListItem.slice(0, 9) === 'language-') { - const language = classListItem.slice(9).replace(/{.*/, '') - const alias = aliases[language] - return alias || language - } - } - - return null -}