@@ -36,7 +36,7 @@ const constructRedirectPage = (href) =>
36
36
* Those redirects are essentially a diff of the current structure and the previous one on this commit:
37
37
* https://github.com/tact-lang/tact-docs/tree/17176cb5e8bac84163bfa4c7b1bd94c0dc917bea/pages
38
38
*
39
- * @returns {{source: string, subSources: string[] | undefined, destination : string}[] }
39
+ * @returns {{source: string, subSources? : string[], destination: string, destPrefix?: string, destSuffix? : string}[] }
40
40
*/
41
41
const getRedirects = ( ) => [
42
42
// Language→Guides pages are moved under Book section
@@ -52,7 +52,6 @@ const getRedirects = () => [
52
52
// Getting Started is now a part of Book→Guides sub-section
53
53
{
54
54
source : '/start' ,
55
- subSources : undefined ,
56
55
destination : '/book/guides/getting-started' ,
57
56
} ,
58
57
{
@@ -64,14 +63,12 @@ const getRedirects = () => [
64
63
// Language→Guides→Grammar is now under Language section as a Specification page
65
64
{
66
65
source : '/book/grammar' ,
67
- subSources : undefined ,
68
66
destination : '/language/spec' ,
69
67
} ,
70
68
71
69
// Evolution section is moved under Language section
72
70
{
73
71
source : '/evolution' ,
74
- subSources : undefined ,
75
72
destination : '/language/evolution/overview' ,
76
73
} ,
77
74
{
@@ -83,7 +80,6 @@ const getRedirects = () => [
83
80
// Language→Guides→Changelog is merged with the Evolution page
84
81
{
85
82
source : '/language/guides/changelog' ,
86
- subSources : undefined ,
87
83
destination : '/language/evolution/overview' ,
88
84
} ,
89
85
@@ -97,39 +93,69 @@ const getRedirects = () => [
97
93
// Small updates in naming of pages or sub-sections
98
94
{
99
95
source : '/book/message-modes' ,
100
- subSources : undefined ,
101
96
destination : '/book/message-mode' ,
102
97
} ,
103
98
{
104
99
source : '/ecosystem/tools/vs' ,
105
- subSources : undefined ,
106
100
destination : '/ecosystem/tools/vscode' ,
107
101
} ,
108
102
{
109
103
source : '/book/ints' ,
110
- subSources : undefined ,
111
104
destination : '/book/integers' ,
112
105
} ,
113
106
{
114
107
source : '/book/numbers' ,
115
- subSources : undefined ,
116
108
destination : '/book/integers' ,
117
109
} ,
118
110
{
119
111
source : '/book/defining-types' ,
120
- subSources : undefined ,
121
112
destination : '/book/types#composite-types' ,
122
113
} ,
123
114
{
124
115
source : '/book/composite-types' ,
125
- subSources : undefined ,
126
116
destination : '/book/types#composite-types' ,
127
117
} ,
128
118
{
129
119
source : '/book/cookbook' ,
130
- subSources : undefined ,
131
120
destination : '/cookbook' ,
132
121
} ,
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
+ } ,
133
159
] ;
134
160
135
161
/**
@@ -139,48 +165,48 @@ const getRedirects = () => [
139
165
* @returns bool
140
166
*/
141
167
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
+ }
146
172
147
- return false ;
173
+ return false ;
148
174
} ;
149
175
150
176
/**
151
177
* Creates the redirect file, unless there exists a regular page/file under source path already.
152
178
* Returns true if the redirect file was created and false otherwise.
153
179
*
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
156
182
* @returns bool
157
183
*/
158
184
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 ) ;
161
187
162
- // full path with extension
163
- const pathWithExt = pathUntilExt + '.html' ;
188
+ // full path with extension
189
+ const pathWithExt = pathUntilExt + '.html' ;
164
190
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
+ }
170
196
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
+ }
178
204
179
- // create the redirect file
180
- fs . writeFileSync ( pathWithExt , constructRedirectPage ( destination ) ) ;
205
+ // create the redirect file
206
+ fs . writeFileSync ( pathWithExt , constructRedirectPage ( destination ) ) ;
181
207
182
- // report success
183
- return true ;
208
+ // report success
209
+ return true ;
184
210
} ;
185
211
186
212
/* ---------------- */
@@ -218,15 +244,21 @@ let count = 0;
218
244
for ( const redirect of redirects ) {
219
245
// 1. have no nested sub-sources
220
246
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
+ ) ) {
222
251
count += 1 ;
223
252
}
224
253
continue ;
225
254
}
226
255
227
256
// 2. have some nested structure
228
257
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
+ ) ) {
230
262
count += 1 ;
231
263
}
232
264
}
0 commit comments