From 1bcaf6695dff358687709bd4908d8cc9551d4a1f Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Mon, 12 Aug 2019 15:35:07 -0700 Subject: [PATCH] Remove lib directory --- lib/config.js | 43 ------------------------------ lib/mdx-loader.js | 47 --------------------------------- lib/rehype-prism.js | 62 -------------------------------------------- lib/search-loader.js | 13 ---------- 4 files changed, 165 deletions(-) delete mode 100644 lib/config.js delete mode 100644 lib/mdx-loader.js delete mode 100644 lib/rehype-prism.js delete mode 100644 lib/search-loader.js diff --git a/lib/config.js b/lib/config.js deleted file mode 100644 index 6ca997ad..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'), require.resolve('./search-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 835c8434..00000000 --- a/lib/mdx-loader.js +++ /dev/null @@ -1,47 +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) - } - - const code = ` -import React from 'react' -import {MDXTag} from '@mdx-js/tag' -${result} -` - - return callback(null, code) -} 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 -} diff --git a/lib/search-loader.js b/lib/search-loader.js deleted file mode 100644 index ac07d4cc..00000000 --- a/lib/search-loader.js +++ /dev/null @@ -1,13 +0,0 @@ -const grayMatter = require('gray-matter') -const fs = require('fs') -const {join} = require('path') - -const searchIndex = {} -const searchIndexPath = join(process.cwd(), 'searchIndex.js') - -module.exports = function(source) { - const {data, content} = grayMatter(source) - searchIndex[data.path] = Object.assign({title: data.title, path: data.path, keywords: data.keywords}, {content}) - fs.writeFileSync(searchIndexPath, `export default ${JSON.stringify(searchIndex, null, 2)}`, 'utf8') - return source -}