Skip to content

Commit f293b1d

Browse files
authored
feat(navigation): better navigation components (nodejs#2910)
1 parent f211bd2 commit f293b1d

File tree

104 files changed

+2374
-2429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2374
-2429
lines changed

content/blog/vulnerabilities/2022-01-11-jan-2022-security-releases.md renamed to content/blog/vulnerability/2022-01-11-jan-2022-security-releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: January 10th 2022 Security Releases
33
blogAuthors: ['node-js-website']
4-
category: 'vulnerabilities'
4+
category: vulnerability
55
---
66

77
## _(Update 10-Jan-2022)_ Security releases available

content/blog/vulnerabilities/2022-03-18-mar-2022-security-releases.md renamed to content/blog/vulnerability/2022-03-18-mar-2022-security-releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: OpenSSL security releases require Node.js security releases
33
blogAuthors: ['node-js-website']
4-
category: 'vulnerabilities'
4+
category: vulnerability
55
---
66

77
# _(Update 18-Mar-2022)_ Security releases available

content/blog/vulnerabilities/2022-05-05-openssl-fixes-in-regular-releases-may2022.md renamed to content/blog/vulnerability/2022-05-05-openssl-fixes-in-regular-releases-may2022.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: OpenSSL update assessment, and Node.js project plans
33
blogAuthors: ['node-js-website']
4-
category: 'vulnerabilities'
4+
category: vulnerability
55
---
66

77
## Summary

content/blog/vulnerabilities/2022-06-21-openssl-fixes-in-regular-releases-jun2022.md renamed to content/blog/vulnerability/2022-06-21-openssl-fixes-in-regular-releases-jun2022.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: OpenSSL update assessment, and Node.js project plans
33
blogAuthors: ['node-js-website']
4-
category: 'vulnerabilities'
4+
category: vulnerability
55
---
66

77
## Summary

gatsby-config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const gatsbyFsMarkdownSources = markdownSources.map(name => ({
2424
}));
2525

2626
const gatsbyConfig = {
27-
flags: { FAST_DEV: true },
2827
pathPrefix: process.env.PATH_PREFIX,
2928
siteMetadata: {
3029
title: config.title,

gatsby-node.js

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const createSlug = require('./util-node/createSlug');
88
const getNodeReleasesData = require('./util-node/getNodeReleasesData');
99
const getBannersData = require('./util-node/getBannersData');
1010
const getNvmData = require('./util-node/getNvmData');
11-
const createBlogQuery = require('./util-node/createBlogQuery');
12-
const createLearnQuery = require('./util-node/createLearnQuery');
13-
const createApiQuery = require('./util-node/createApiQuery');
11+
const createBlogQuery = require('./util-node/queries/createBlogQuery');
12+
const createLearnQuery = require('./util-node/queries/createLearnQuery');
13+
const createApiQuery = require('./util-node/queries/createApiQuery');
1414
const createBlogPages = require('./util-node/createBlogPages');
1515
const createLearnPages = require('./util-node/createLearnPages');
1616
const createApiPages = require('./util-node/createApiPages');
@@ -47,12 +47,27 @@ const getMessagesForLocale = locale =>
4747
const getRedirectForLocale = (locale, url) =>
4848
/^\/\/|https?:\/\//.test(url) ? url : `/${locale}${url}`;
4949

50-
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
50+
exports.onCreateWebpackConfig = ({ plugins, actions, stage, getConfig }) => {
5151
actions.setWebpackConfig({
5252
plugins: [
5353
plugins.ignore({ resourceRegExp: /canvas/, contextRegExp: /jsdom$/ }),
5454
],
5555
});
56+
57+
if (stage === 'develop' || stage === 'build-javascript') {
58+
const config = getConfig();
59+
60+
const miniCssExtractPlugin = config.plugins.find(
61+
plugin => plugin.constructor.name === 'MiniCssExtractPlugin'
62+
);
63+
64+
if (miniCssExtractPlugin) {
65+
// We don't care about the order of CSS imports as we use CSS Modules
66+
miniCssExtractPlugin.options.ignoreOrder = true;
67+
}
68+
69+
actions.replaceWebpackConfig(config);
70+
}
5671
};
5772

5873
exports.createSchemaCustomization = ({ actions }) => {
@@ -103,7 +118,8 @@ exports.createPages = async ({ graphql, actions }) => {
103118
nodeReleases: { nodeReleasesData, apiAvailableVersions },
104119
} = apiResult.data;
105120

106-
const { blogPages } = createBlogPages(blogEdges);
121+
const { blogPages, blogPosts, getPaginatedPosts } =
122+
createBlogPages(blogEdges);
107123

108124
const { learnPages, navigationData: learnNavigationData } = createLearnPages(
109125
learnEdges,
@@ -123,12 +139,6 @@ exports.createPages = async ({ graphql, actions }) => {
123139
context: { ...learnPages[0], navigationData: learnNavigationData },
124140
});
125141

126-
createPage({
127-
path: blogPath,
128-
component: blogTemplate,
129-
context: { categories: categoryEdges, posts: blogEdges },
130-
});
131-
132142
learnPages.forEach(page => {
133143
createPage({
134144
path: page.slug,
@@ -141,20 +151,40 @@ exports.createPages = async ({ graphql, actions }) => {
141151
createPage({
142152
path: page.slug,
143153
component: postTemplate,
144-
// Get the latest 10 blog posts
145-
context: { ...page, recent: blogEdges.slice(0, 10) },
154+
// Get the latest 10 blog posts for the Recent Posts section
155+
context: { ...page, recent: blogPosts.slice(0, 10) },
146156
});
147157
});
148158

149-
categoryEdges.forEach(({ node }) => {
150-
const posts = blogEdges.filter(
151-
({ node: item }) => item.fields.categoryName === node.name
152-
);
159+
// This default category acts as a "hack" for creating the default
160+
// `/blog` page (aka the "Everything" category)
161+
const defaultCategory = { node: { name: null } };
153162

154-
createPage({
155-
path: `${blogPath}${node.name}/`,
156-
component: blogTemplate,
157-
context: { categories: categoryEdges, category: node, posts },
163+
[defaultCategory, ...categoryEdges].forEach(({ node }) => {
164+
const paginatedPosts = getPaginatedPosts(node.name);
165+
166+
const getPaginationData = current => ({
167+
current: current + 1,
168+
total: paginatedPosts.length,
169+
});
170+
171+
const getBlogPagePath = index => {
172+
const categoryPath = node.name ? `${blogPath}${node.name}/` : blogPath;
173+
174+
return index === 0 ? categoryPath : `${categoryPath}page/${index + 1}/`;
175+
};
176+
177+
paginatedPosts.forEach((currentPagePosts, index) => {
178+
createPage({
179+
path: getBlogPagePath(index),
180+
component: blogTemplate,
181+
context: {
182+
category: node.name ? node : null,
183+
categories: categoryEdges,
184+
posts: currentPagePosts,
185+
pagination: getPaginationData(index),
186+
},
187+
});
158188
});
159189
});
160190

package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"react-helmet": "^6.1.0",
5656
"react-icons": "^4.4.0",
5757
"react-intl": "^6.1.1",
58+
"react-scroll": "^1.8.7",
5859
"react-tabs": "5.1.0",
5960
"reading-time": "^1.5.0",
6061
"string-similarity": "^4.0.4",
@@ -106,6 +107,7 @@
106107
"@types/react-click-outside-hook": "^1.0.0",
107108
"@types/react-dom": "^18.0.6",
108109
"@types/react-helmet": "^6.1.5",
110+
"@types/react-scroll": "^1.8.4",
109111
"@types/string-similarity": "^4.0.0",
110112
"@types/throttle-debounce": "^5.0.0",
111113
"@typescript-eslint/eslint-plugin": "^5.36.2",

src/__fixtures__/page.tsx

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
PaginationInfo,
33
LearnTemplateContext,
4-
NavigationSectionData,
4+
NavigationData,
55
PostTemplateData,
66
PostTemplateContext,
77
NodeReleaseData,
@@ -25,39 +25,29 @@ export const createPaginationInfo = (): PaginationInfo =>
2525
title: 'test-title',
2626
} as PaginationInfo);
2727

28-
export const createNavigationSectionData = (): NavigationSectionData =>
28+
export const createNavigationSectionData = (): NavigationData =>
2929
({
30-
'test-section': {
31-
data: [
32-
{
33-
slug: 'test-slug-1',
34-
title: 'test-title-1',
35-
category: 'test1',
36-
},
37-
{
38-
title: 'test-title-2',
39-
slug: 'test-slug-2',
40-
category: 'test1',
41-
},
42-
],
43-
category: 'test1',
44-
},
45-
'test-section2': {
46-
data: [
47-
{
48-
slug: 'test-slug-3',
49-
title: 'test-title-3',
50-
category: 'test2',
51-
},
52-
{
53-
title: 'test-title-4',
54-
slug: 'test-slug-4',
55-
category: 'test2',
56-
},
57-
],
58-
category: 'test2',
59-
},
60-
} as NavigationSectionData);
30+
'test-section': [
31+
{
32+
slug: 'test-slug-1',
33+
title: 'test-title-1',
34+
},
35+
{
36+
title: 'test-title-2',
37+
slug: 'test-slug-2',
38+
},
39+
],
40+
'test-section2': [
41+
{
42+
slug: 'test-slug-3',
43+
title: 'test-title-3',
44+
},
45+
{
46+
title: 'test-title-4',
47+
slug: 'test-slug-4',
48+
},
49+
],
50+
} as NavigationData);
6151

6252
export const createLearnPageData = () => ({
6353
data: {
@@ -134,7 +124,7 @@ export const createBlogPageContext = (): PostTemplateContext => ({
134124
title: 'title-mock',
135125
category: {
136126
name: 'category-mock',
137-
slug: 'category-mock-slug',
127+
slug: 'blog.title',
138128
},
139129
blogAuthors: [
140130
{

0 commit comments

Comments
 (0)