Skip to content

Commit 7014d9d

Browse files
authored
feat(docs): introduced initial version of api docs system (nodejs#2680)
1 parent 62403e6 commit 7014d9d

File tree

127 files changed

+8194
-10692
lines changed

Some content is hidden

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

127 files changed

+8194
-10692
lines changed

.babelrc

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"generatorOpts": {
3+
"compact": true,
4+
"comments": false
5+
},
6+
"overrides": [
7+
{
8+
"test": "**/**.md",
9+
"compact": true
10+
}
11+
],
12+
"plugins": [
13+
[
14+
"prismjs",
15+
{
16+
"languages": ["js", "css", "jsx", "bash", "ts", "markup", "cpp", "c"],
17+
"plugins": [],
18+
"css": false
19+
}
20+
]
21+
],
22+
"presets": [
23+
[
24+
"babel-preset-gatsby",
25+
{
26+
"targets": {
27+
"browsers": ["last 3 versions", "not ie <= 11", "not android 4.4.3"]
28+
}
29+
}
30+
]
31+
]
32+
}

apiUrls.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
apiReleaseContents: releaseVersion =>
3+
`https://api.github.com/repos/nodejs/node/contents/doc/api?ref=${releaseVersion}`,
4+
nvmTags: 'https://api.github.com/repos/nvm-sh/nvm/tags',
5+
nodeReleaseSchedule:
6+
'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json',
7+
nodeReleaseData: 'https://nodejs.org/dist/index.json',
8+
nodeBannersData:
9+
'https://raw.githubusercontent.com/nodejs/nodejs.org/main/locale/en/site.json',
10+
};

content/learn/node-introduction.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The most common example Hello World of Node.js is a web server:
3535
style="height: 400px; width: 100%; border: 0;">
3636
</iframe>
3737

38-
<!--```js
38+
```js
3939
const http = require('http')
4040

4141
const hostname = '127.0.0.1'

firebase.json

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
}
2121
],
2222
"redirects": [
23-
{
24-
"source": "/en/get-involved/",
25-
"destination": "/community/",
26-
"type": "301"
27-
},
2823
{
2924
"source": "/get-involved/",
3025
"destination": "/community/",

gatsby-config.js

+56-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path');
2+
13
require('dotenv').config();
24

35
const config = require('./src/config.json');
@@ -21,7 +23,6 @@ const gatsbyConfig = {
2123
'gatsby-plugin-catch-links',
2224
'@skagami/gatsby-plugin-dark-mode',
2325
'gatsby-transformer-yaml',
24-
'gatsby-remark-images',
2526
'gatsby-plugin-sharp',
2627
{
2728
resolve: 'gatsby-plugin-canonical-urls',
@@ -44,68 +45,65 @@ const gatsbyConfig = {
4445
resolve: 'gatsby-source-filesystem',
4546
options: {
4647
name: 'learn',
47-
path: `${__dirname}/content/learn`,
48+
path: path.resolve('./content/learn'),
4849
},
4950
},
5051
{
5152
resolve: 'gatsby-source-filesystem',
5253
options: {
5354
name: 'sites',
54-
path: `${__dirname}/src/pages/`,
55+
path: path.resolve('./src/pages'),
5556
},
5657
},
5758
{
5859
resolve: 'gatsby-source-filesystem',
5960
options: {
6061
name: 'homepage',
61-
path: `${__dirname}/content/homepage`,
62+
path: path.resolve('./content/homepage'),
6263
},
6364
},
6465
{
6566
resolve: 'gatsby-source-filesystem',
6667
options: {
6768
name: 'community',
68-
path: `${__dirname}/content/community`,
69+
path: path.resolve('./content/community'),
6970
},
7071
},
7172
{
7273
resolve: 'gatsby-source-filesystem',
7374
options: {
7475
name: 'blog',
75-
path: `${__dirname}/content/blog`,
76+
path: path.resolve('./content/blog'),
7677
},
7778
},
7879
{
7980
resolve: 'gatsby-source-filesystem',
8081
options: {
8182
name: 'data',
82-
path: `${__dirname}/src/data`,
83+
path: path.resolve('./src/data'),
8384
},
8485
},
8586
{
8687
resolve: 'gatsby-source-filesystem',
8788
options: {
8889
name: 'about',
89-
path: `${__dirname}/content/about`,
90+
path: path.resolve('./content/about'),
9091
},
9192
},
9293
{
9394
resolve: 'gatsby-source-filesystem',
9495
options: {
9596
name: 'download',
96-
path: `${__dirname}/content/download`,
97+
path: path.resolve('./content/download'),
9798
},
9899
},
99100
'gatsby-plugin-typescript',
100101
{
101102
resolve: 'gatsby-plugin-mdx',
102103
options: {
103104
extensions: ['.mdx', '.md'],
104-
defaultLayouts: {
105-
default: require.resolve(`./src/components/Layout/index.tsx`),
106-
},
107105
gatsbyRemarkPlugins: [
108-
'gatsby-remark-copy-linked-files',
106+
{ resolve: 'gatsby-remark-copy-linked-files' },
109107
{
110108
resolve: 'gatsby-remark-autolink-headers',
111109
options: {
@@ -138,17 +136,30 @@ const gatsbyConfig = {
138136
{
139137
resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
140138
options: {
141-
fields: [`title`, `body`, `description`, `slug`],
139+
fields: [
140+
'slug',
141+
'title',
142+
'displayTitle',
143+
'description',
144+
'category',
145+
'tableOfContents',
146+
],
142147
resolvers: {
143148
Mdx: {
144149
id: node => node.id,
145150
title: node => node.frontmatter.title,
146-
body: node => node.rawBody,
151+
displayTitle: node => node.frontmatter.displayTitle,
147152
description: node => node.frontmatter.description,
148153
slug: node => node.fields.slug,
154+
category: node => node.fields.categoryName,
155+
tableOfContents: node => {
156+
return [...node.rawBody.matchAll(/^#{2,5} .*/gm)]
157+
.map(match => match[0].replace(/^#{2,5} /, ''))
158+
.join('\n');
159+
},
149160
},
150161
},
151-
filter: node => node.frontmatter.category === 'learn',
162+
filter: node => ['api', 'learn'].includes(node.frontmatter.category),
152163
},
153164
},
154165
{
@@ -158,11 +169,39 @@ const gatsbyConfig = {
158169
resolve: `gatsby-theme-i18n`,
159170
options: {
160171
defaultLang: defaultLanguage,
161-
configPath: `${__dirname}/src/i18n/config.json`,
172+
configPath: path.resolve('./src/i18n/config.json'),
162173
prefixDefault: true,
163174
locales: localesAsString,
164175
},
165176
},
177+
{
178+
resolve: `gatsby-plugin-webfonts`,
179+
options: {
180+
fonts: {
181+
google: [
182+
{
183+
family: 'Open Sans',
184+
variants: [
185+
'300',
186+
'300i',
187+
'400',
188+
'400i',
189+
'600',
190+
'600i',
191+
'900',
192+
'900i',
193+
],
194+
fontDisplay: 'swap',
195+
strategy: 'selfHosted',
196+
},
197+
],
198+
},
199+
formats: ['woff2'],
200+
useMinify: true,
201+
usePreload: true,
202+
usePreconnect: true,
203+
},
204+
},
166205
{
167206
resolve: 'gatsby-plugin-manifest',
168207
options: {
@@ -191,13 +230,6 @@ if (!gatsbyConfig.pathPrefix) {
191230
// So we are able to use the official service worker again. This service worker supports latest Workbox
192231
resolve: 'gatsby-plugin-offline-next',
193232
options: {
194-
precachePages: [
195-
'/',
196-
'/*/learn/*',
197-
'/*/about/*',
198-
'/*/download/*',
199-
'/*/blog/*',
200-
],
201233
globPatterns: ['**/icon-path*'],
202234
},
203235
});

0 commit comments

Comments
 (0)