Skip to content

Commit 2d42d2f

Browse files
committed
feat(ci): add script to prepare hidden pages
1 parent 1cf2c2d commit 2d42d2f

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

.teamcity/builds/kotlinlang/buidTypes/BuildReferenceDocs.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import jetbrains.buildServer.configs.kotlin.BuildType
55
import jetbrains.buildServer.configs.kotlin.*
66
import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep
77
import jetbrains.buildServer.configs.kotlin.buildSteps.script
8+
import java.io.File
9+
import java.nio.file.Paths
10+
11+
private fun readScript(name: String): String {
12+
val file = File(Paths.get("scripts/$name.mjs").toAbsolutePath().toString())
13+
return file.readText()
14+
}
815

916
object BuildReferenceDocs : BuildType({
1017
name = "Reference Docs"
@@ -35,6 +42,21 @@ object BuildReferenceDocs : BuildType({
3542
dockerImage = "alpine"
3643
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
3744
}
45+
46+
script {
47+
name = "Prepare page views"
48+
scriptContent = """
49+
#!/usr/bin/env bash
50+
npm i cheerio
51+
52+
":" //# comment; exec /usr/bin/env node --input-type=module - "${'$'}@" < "${'$'}0"
53+
54+
${readScript("fix-wrs/index")}
55+
""".trimIndent()
56+
dockerImage = "node:22-slim"
57+
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
58+
dockerPull = true
59+
}
3860
}
3961

4062
dependencies {

.teamcity/scripts/fix-wrs/index.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { load } from 'cheerio';
2+
import { readFile, writeFile } from 'node:fs/promises';
3+
import { join, resolve } from 'node:path';
4+
5+
const ROOT_DIR = resolve('.');
6+
const DATA_DIR = join(ROOT_DIR, 'kr.tree');
7+
8+
const text = (await readFile(DATA_DIR));
9+
const $ = await load(text, { xml: true });
10+
11+
const ids = (await $('toc-element[hidden="true"]'))
12+
.map((i, e) => $(e).attr('id')).get();
13+
14+
const dels = ids
15+
.map(async id => {
16+
const file = `${ROOT_DIR}/pages/${id.replace(/.md$/g, '.html')}`;
17+
const text = await readFile(file);
18+
const patched = text.toString().replace(/(<head>)/g, '$1<meta name="robots" content="noindex">');
19+
console.log('exclude', file);
20+
await writeFile(file, patched);
21+
});
22+
23+
await Promise.all(dels);

docs/kr.tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<toc-element toc-title="Language features and proposals" topic="kotlin-language-features-and-proposals.md"/>
5252
<toc-element toc-title="Language evolution principles" accepts-web-file-names="kotlin-evolution.html" topic="kotlin-evolution-principles.md"/>
5353
<toc-element topic="components-stability.md"/>
54-
<toc-element hidden="true" topic="components-stability-pre-1.4.md"/>
54+
<toc-element hidden="true" topic="components-stability-pre-1-4.md"/>
5555
<toc-element accepts-web-file-names="plugin-releases.html" topic="releases.md"/>
5656
</toc-element>
5757
<toc-element toc-title="Basics">

0 commit comments

Comments
 (0)