Skip to content

Commit 5bdaadc

Browse files
committed
Fix build non-root path
1 parent 9aec043 commit 5bdaadc

File tree

3 files changed

+71
-27
lines changed

3 files changed

+71
-27
lines changed

assets/index.html

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,55 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<meta http-equiv="refresh" content="0; url=/docs/ru/index.html">
76
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>Redirect</title>
7+
<base href="./">
8+
<title>Redirect to /opensource/docs/ru/</title>
9+
<meta http-equiv="refresh" content="0; url=/opensource/docs/ru/">
10+
911
<style type="text/css">
12+
html,
1013
body {
14+
min-height: 100vh;
1115
height: 100vh;
1216
}
1317
</style>
14-
<link type="text/css" rel="stylesheet" href="_bundle/vendor.css">
15-
<link type="text/css" rel="stylesheet" href="_bundle/app.css">
1618

17-
<script type="text/javascript">
18-
window.location.replace("/docs/ru/index.html");
19+
<script type="application/javascript">
20+
window.location.replace("/opensource/docs/ru/");
1921
</script>
22+
23+
2024
<meta name="theme-color" content="#efefef">
21-
<meta itemprop="name" content="DataLens">
25+
<meta itemprop="name" content="DataLens OpenSource">
2226
<meta itemprop="description" content="">
23-
<meta property="og:title" content="DataLens">
27+
<meta itemprop="image" content="/opensource/docs/_assets/share-ru.png">
28+
<meta property="og:title" content="DataLens OpenSource">
2429
<meta property="og:description" content="">
2530
<meta property="og:type" content="website">
26-
<meta property="og:site_name" content="DataLens">
27-
<meta property="og:image" content="/docs/ru/_assets/share.png">
31+
<meta property="og:site_name" content="DataLens OpenSource">
32+
<meta property="og:locale" content="ru">
33+
<meta property="og:image" content="/opensource/docs/_assets/share-ru.png">
34+
<meta property="og:url" content="https://datalens.ru/opensource/docs/ru">
2835
<meta name="twitter:title" content="DataLens">
2936
<meta name="twitter:description" content="">
3037
<meta name="twitter:card" content="summary_large_image">
31-
<meta name="twitter:image" content="/docs/ru/_assets/share.png">
38+
<meta name="twitter:image" content="/opensource/docs/_assets/share-ru.png">
3239
<meta property="share:title" content="DataLens">
3340
<meta property="share:sharing_schema" content="default">
34-
<link rel="icon" href="/favicon.ico" sizes="any">
35-
<link type="image/x-icon" rel="shortcut icon" href="/favicon.ico">
36-
<link type="image/png" sizes="16x16" rel="icon" href="/favicon-16x16.png">
37-
<link type="image/png" sizes="32x32" rel="icon" href="/favicon-32x32.png">
38-
<link type="image/png" sizes="64x64" rel="icon" href="/favicon-64x64.png">
39-
<link type="image/png" sizes="76x76" rel="icon" href="/favicon-76x76.png">
40-
<link type="image/png" sizes="120x120" rel="icon" href="/favicon-120x120.png">
41-
<link type="image/png" sizes="152x152" rel="icon" href="/favicon-152x152.png">
42-
<link type="image/png" sizes="180x180" rel="icon" href="/favicon-180x180.png">
43-
<link type="image/png" sizes="192x192" rel="icon" href="/favicon-192x192.png">
44-
<link rel="apple-touch-icon" href="/favicon-192x192.png">
45-
<link rel="manifest" href="/manifest.json">
41+
42+
<link rel="icon" sizes="any" href="/opensource/docs/favicon.ico">
43+
<link type="image/x-icon" rel="shortcut icon" href="/opensource/docs/favicon.ico">
44+
<link type="image/png" sizes="16x16" rel="icon" href="/opensource/docs/_assets/favicon/favicon-16x16.png">
45+
<link type="image/png" sizes="32x32" rel="icon" href="/opensource/docs/_assets/favicon/favicon-32x32.png">
46+
<link type="image/png" sizes="64x64" rel="icon" href="/opensource/docs/_assets/favicon/favicon-64x64.png">
47+
<link type="image/png" sizes="76x76" rel="icon" href="/opensource/docs/_assets/favicon/favicon-76x76.png">
48+
<link type="image/png" sizes="120x120" rel="icon" href="/opensource/docs/_assets/favicon/favicon-120x120.png">
49+
<link type="image/png" sizes="152x152" rel="icon" href="/opensource/docs/_assets/favicon/favicon-152x152.png">
50+
<link type="image/png" sizes="180x180" rel="icon" href="/opensource/docs/_assets/favicon/favicon-180x180.png">
51+
<link type="image/png" sizes="192x192" rel="icon" href="/opensource/docs/_assets/favicon/favicon-192x192.png">
52+
<link rel="apple-touch-icon" href="/opensource/docs/_assets/favicon/favicon-192x192.png">
53+
<link rel="manifest" href="/opensource/docs/manifest.json">
54+
4655
<style type="text/css">
4756
li.pc-navigation-item:first-child {
4857
display: flex;
@@ -53,7 +62,7 @@
5362
</head>
5463

5564
<body class="g-root g-root_theme_light">
56-
If you are not redirected automatically, follow this <a href="/docs/ru/">link to example</a>.
65+
If you are not redirected automatically, follow this <a href="/opensource/docs/ru/">link</a>.
5766
</body>
5867

5968
</html>

scripts/build-fix.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ li.pc-navigation-item:first-child {
127127

128128
const FILE_CHECK_MAP = [];
129129

130-
const fixFile = async (filePath, basePath) => {
130+
const fixHtmlFile = async (filePath, basePath) => {
131131
const trimPath = filePath.replace(basePath, '');
132132
const trimPathLog = trimPath.replace(/^\//g, '');
133133

@@ -208,6 +208,10 @@ const fixFile = async (filePath, basePath) => {
208208

209209
let html = $.html();
210210
html = html
211+
.replace(/("href":".+?\/)index\.html"/g, '$1"')
212+
.replace(/( href=".+?\/)index\.html"/g, '$1"')
213+
.replace(/("href":")index\.html"/g, '$1./"')
214+
.replace(/( href=")index\.html"/g, '$1./"')
211215
.replace(
212216
/ *?<link type="text\/css" rel="stylesheet" href="_assets\/cut-extension.css">\n/g,
213217
'',
@@ -228,6 +232,21 @@ const fixFile = async (filePath, basePath) => {
228232
await fs.writeFile(filePath, html);
229233
};
230234

235+
const fixTocFile = async (filePath, basePath) => {
236+
const trimPath = filePath.replace(basePath, '');
237+
const trimPathLog = trimPath.replace(/^\//g, '');
238+
239+
// eslint-disable-next-line no-console
240+
console.log('\x1b[33m%s\x1b[0m %s %s', 'POST-BUILD', 'Fixing TOC file', trimPathLog);
241+
242+
let fileToc = await fs.readFile(filePath, 'utf8');
243+
fileToc = fileToc
244+
.replace(/("href":".+?\/)index\.html"/g, '$1"')
245+
.replace(/("href":")index\.html"/g, '$1./"');
246+
247+
await fs.writeFile(filePath, fileToc);
248+
};
249+
231250
async function main() {
232251
const basePath = path.join(__dirname, '../build', BUILD_SETTINGS.docsPath);
233252

@@ -252,7 +271,14 @@ async function main() {
252271
});
253272
await fs.writeFile(path.join(basePath, '_bundle', vendorFile), vendorScript);
254273

255-
await Promise.all(paths.map((filePath) => fixFile(filePath, basePath)));
274+
await Promise.all(paths.map((filePath) => fixHtmlFile(filePath, basePath)));
275+
276+
const tocList = walkSync(basePath, {
277+
directories: false,
278+
globs: ['**/toc.js'],
279+
includeBasePath: true,
280+
});
281+
await Promise.all(tocList.map((filePath) => fixTocFile(filePath, basePath)));
256282

257283
const manifestPath = path.join(basePath, 'manifest.json');
258284
let manifest = fs.readFileSync(manifestPath, 'utf8');
@@ -263,7 +289,11 @@ async function main() {
263289
.replaceAll('{manifest.description}', BUILD_SETTINGS.manifest.description)
264290
.replaceAll('{manifest.themeColor}', BUILD_SETTINGS.manifest.themeColor)
265291
.replaceAll('{manifest.backgroundColor}', BUILD_SETTINGS.manifest.backgroundColor);
266-
fs.writeFile(manifestPath, manifest);
292+
await fs.writeFile(manifestPath, manifest);
293+
294+
await fs.cp(path.join(__dirname, '../assets/index.html'), path.join(basePath, 'index.html'), {
295+
force: true,
296+
});
267297

268298
if (Object.keys(FILE_CHECK_MAP).length > 0) {
269299
console.error(

scripts/build-prepare.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ const fixNestedPath = async (basePath, lang = null) => {
6464
const navigationYaml = (await fs.readFile('assets/navigation.yaml')).toString();
6565
tocYaml = tocYaml.replace('href: index.yaml', `href: index.yaml\n${navigationYaml}`);
6666
await fs.writeFile(path.join(basePath, lang, 'toc.yaml'), tocYaml);
67+
68+
let indexYaml = await fs.readFile(path.join(basePath, lang, 'index.yaml'), 'utf-8');
69+
indexYaml = indexYaml.replace(/(href:.+[^/])\n/g, '$1.md\n');
70+
await fs.writeFile(path.join(basePath, lang, 'index.yaml'), indexYaml);
71+
6772
await fs.copy(path.join(lang, 'presets.yaml'), path.join(basePath, lang, 'presets.yaml'));
6873

6974
const paths = walkSync(path.join(basePath, lang), {

0 commit comments

Comments
 (0)