Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit ee7fe04

Browse files
committed
chore: Update redirects
1 parent 65fb5d4 commit ee7fe04

File tree

1 file changed

+73
-41
lines changed

1 file changed

+73
-41
lines changed

scripts/redirects-generate.js

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const constructRedirectPage = (href) =>
3636
* Those redirects are essentially a diff of the current structure and the previous one on this commit:
3737
* https://github.com/tact-lang/tact-docs/tree/17176cb5e8bac84163bfa4c7b1bd94c0dc917bea/pages
3838
*
39-
* @returns {{source: string, subSources: string[] | undefined, destination: string}[]}
39+
* @returns {{source: string, subSources?: string[], destination: string, destPrefix?: string, destSuffix?: string}[]}
4040
*/
4141
const getRedirects = () => [
4242
// Language→Guides pages are moved under Book section
@@ -52,7 +52,6 @@ const getRedirects = () => [
5252
// Getting Started is now a part of Book→Guides sub-section
5353
{
5454
source: '/start',
55-
subSources: undefined,
5655
destination: '/book/guides/getting-started',
5756
},
5857
{
@@ -64,14 +63,12 @@ const getRedirects = () => [
6463
// Language→Guides→Grammar is now under Language section as a Specification page
6564
{
6665
source: '/book/grammar',
67-
subSources: undefined,
6866
destination: '/language/spec',
6967
},
7068

7169
// Evolution section is moved under Language section
7270
{
7371
source: '/evolution',
74-
subSources: undefined,
7572
destination: '/language/evolution/overview',
7673
},
7774
{
@@ -83,7 +80,6 @@ const getRedirects = () => [
8380
// Language→Guides→Changelog is merged with the Evolution page
8481
{
8582
source: '/language/guides/changelog',
86-
subSources: undefined,
8783
destination: '/language/evolution/overview',
8884
},
8985

@@ -97,39 +93,69 @@ const getRedirects = () => [
9793
// Small updates in naming of pages or sub-sections
9894
{
9995
source: '/book/message-modes',
100-
subSources: undefined,
10196
destination: '/book/message-mode',
10297
},
10398
{
10499
source: '/ecosystem/tools/vs',
105-
subSources: undefined,
106100
destination: '/ecosystem/tools/vscode',
107101
},
108102
{
109103
source: '/book/ints',
110-
subSources: undefined,
111104
destination: '/book/integers',
112105
},
113106
{
114107
source: '/book/numbers',
115-
subSources: undefined,
116108
destination: '/book/integers',
117109
},
118110
{
119111
source: '/book/defining-types',
120-
subSources: undefined,
121112
destination: '/book/types#composite-types',
122113
},
123114
{
124115
source: '/book/composite-types',
125-
subSources: undefined,
126116
destination: '/book/types#composite-types',
127117
},
128118
{
129119
source: '/book/cookbook',
130-
subSources: undefined,
131120
destination: '/cookbook',
132121
},
122+
123+
// Language→Libs pages are moved under Reference section
124+
{
125+
source: '/language',
126+
destination: '/ref',
127+
},
128+
{
129+
source: '/language/ref',
130+
subSources: [
131+
'common', 'strings', 'random', 'math', 'cells', 'advanced'
132+
],
133+
destination: '/ref',
134+
destPrefix: 'api-', // /ref/api-common, etc.
135+
},
136+
{
137+
source: '/language/libs/overview',
138+
destination: '/ref/standard-libraries',
139+
},
140+
{
141+
source: '/language/libs',
142+
subSources: [
143+
'config', 'content', 'deploy', 'dns', 'ownable', 'stoppable',
144+
],
145+
destination: '/ref',
146+
destPrefix: 'stdlib-', // /ref/stdlib-config, etc.
147+
},
148+
{
149+
source: '/language/spec',
150+
destination: '/ref/spec',
151+
},
152+
{
153+
source: '/language/evolution',
154+
subSources: [
155+
'overview', 'OTP-001', 'OTP-002', 'OTP-003', 'OTP-004', 'OTP-005', 'OTP-006',
156+
],
157+
destination: '/ref/evolution',
158+
},
133159
];
134160

135161
/**
@@ -139,48 +165,48 @@ const getRedirects = () => [
139165
* @returns bool
140166
*/
141167
const isRegularFile = (filePathWithExt) => {
142-
if (fs.existsSync(filePathWithExt)
143-
&& !(fs.readFileSync(filePathWithExt, 'utf8').includes('<title>Redirecting...</title>'))) {
144-
return true;
145-
}
168+
if (fs.existsSync(filePathWithExt)
169+
&& !(fs.readFileSync(filePathWithExt, 'utf8').includes('<title>Redirecting...</title>'))) {
170+
return true;
171+
}
146172

147-
return false;
173+
return false;
148174
};
149175

150176
/**
151177
* Creates the redirect file, unless there exists a regular page/file under source path already.
152178
* Returns true if the redirect file was created and false otherwise.
153179
*
154-
* @param source {string}
155-
* @param destination {string}
180+
* @param source {string} - path to the file
181+
* @param destination {string} - link to the new page
156182
* @returns bool
157183
*/
158184
const createRedirectFile = (source, destination) => {
159-
// full path, minus the extension
160-
const pathUntilExt = path.join(cwd, '/out', source);
185+
// full path, minus the extension
186+
const pathUntilExt = path.join(cwd, '/out', source);
161187

162-
// full path with extension
163-
const pathWithExt = pathUntilExt + '.html';
188+
// full path with extension
189+
const pathWithExt = pathUntilExt + '.html';
164190

165-
// if file exists, but doesn't include the line from the redirect page
166-
if (isRegularFile(pathWithExt)) {
167-
console.log(`Warning: such path (${pathWithExt}) already exists in the docs, so redirect from it was NOT created`);
168-
return false;
169-
}
191+
// if file exists, but doesn't include the line from the redirect page
192+
if (isRegularFile(pathWithExt)) {
193+
console.log(`Warning: such path (${pathWithExt}) already exists in the docs, so redirect from it was NOT created`);
194+
return false;
195+
}
170196

171-
// need to create additional dirs
172-
if (source.split('/').length > 1) {
173-
const nestedDir = path.dirname(pathUntilExt);
174-
// NOTE: debug output
175-
// console.log(nestedDir, redirect.source);
176-
fs.mkdirSync(nestedDir, { recursive: true });
177-
}
197+
// need to create additional dirs
198+
if (source.split('/').length > 1) {
199+
const nestedDir = path.dirname(pathUntilExt);
200+
// NOTE: debug output
201+
// console.log(nestedDir, redirect.source);
202+
fs.mkdirSync(nestedDir, { recursive: true });
203+
}
178204

179-
// create the redirect file
180-
fs.writeFileSync(pathWithExt, constructRedirectPage(destination));
205+
// create the redirect file
206+
fs.writeFileSync(pathWithExt, constructRedirectPage(destination));
181207

182-
// report success
183-
return true;
208+
// report success
209+
return true;
184210
};
185211

186212
/* ---------------- */
@@ -218,15 +244,21 @@ let count = 0;
218244
for (const redirect of redirects) {
219245
// 1. have no nested sub-sources
220246
if (redirect.subSources === undefined) {
221-
if (createRedirectFile(redirect.source, redirect.destination) === true) {
247+
if (createRedirectFile(
248+
redirect.source,
249+
(redirect.destPrefix ?? '') + redirect.destination + (redirect.destSuffix ?? ''),
250+
)) {
222251
count += 1;
223252
}
224253
continue;
225254
}
226255

227256
// 2. have some nested structure
228257
for (const subSource of redirect.subSources) {
229-
if (createRedirectFile(redirect.source + '/' + subSource, redirect.destination + '/' + subSource)) {
258+
if (createRedirectFile(
259+
redirect.source + '/' + subSource,
260+
redirect.destination + '/' + (redirect.destPrefix ?? '') + subSource + (redirect.destSuffix ?? ''),
261+
)) {
230262
count += 1;
231263
}
232264
}

0 commit comments

Comments
 (0)