-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnext.config.js
More file actions
67 lines (63 loc) · 1.58 KB
/
next.config.js
File metadata and controls
67 lines (63 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const readingTime = require('reading-time');
const withPlugins = require('next-compose-plugins');
const withVideos = require('next-videos');
const withOptimizedImages = require('next-optimized-images');
const withMdxEnhanced = require('next-mdx-enhanced');
module.exports = withPlugins(
[
withMdxEnhanced({
layoutPath: 'layouts',
defaultLayout: true,
rehypePlugins: [require('mdx-prism')],
extendFrontMatter: {
process: (mdxContent, frontMatter) => {
return {
id: makeIdFromPath(frontMatter.__resourcePath),
wordCount: mdxContent.split(/\s+/g).length,
readingTime: readingTime(mdxContent),
};
},
},
})({
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
}),
withOptimizedImages,
withVideos,
],
{
// Next.js config
async redirects() {
return [
{
source: '/styleguide',
destination: '/',
permanent: true,
},
];
},
}
);
/**
*
* @param {string} resourcePath
*
* Make an ID from a path
*
* Currently, `resourcePath` is formatted like this:
* - "blog/name-of-file.mdx"
* - "blog/name-of-folder/index.mdx"
*
* This function will make the following IDs:
* - "name-of-file"
* - "name-of-folder"
*
*/
function makeIdFromPath(resourcePath) {
const parts = resourcePath.split('/');
const articleType = parts[0];
let lastPart = parts[parts.length - 1];
if (lastPart.includes('index')) {
lastPart = parts[parts.length - 2];
}
return `${articleType}/${lastPart.replace('.mdx', '')}`;
}