Fix SPA sample links and sample doc publishing

This commit is contained in:
Sergey Chernov 2026-04-25 16:46:51 +03:00
parent 66b8806b11
commit eba7158330
6 changed files with 108 additions and 11 deletions

View File

@ -190,7 +190,7 @@ assertThrows(RollbackException) {
## Runnable serialization sample ## Runnable serialization sample
A complete runnable example is in [examples/sqlite_serialization.lyng](/home/sergeych/dev/lyng/examples/sqlite_serialization.lyng). A complete runnable example is in [examples/sqlite_serialization.lyng](../examples/sqlite_serialization.lyng).
It uses: It uses:

View File

@ -4,7 +4,7 @@ Saved on April 4, 2026 before the `List<Int>` indexed-access follow-up fix.
Benchmark target: Benchmark target:
- [examples/pi-bench.py](/home/sergeych/dev/lyng/examples/pi-bench.py) - [examples/pi-bench.py](/home/sergeych/dev/lyng/examples/pi-bench.py)
- [examples/pi-bench.lyng](/home/sergeych/dev/lyng/examples/pi-bench.lyng) - [examples/pi-bench.lyng](../examples/pi-bench.lyng)
Execution path: Execution path:
- Python: `python3 examples/pi-bench.py` - Python: `python3 examples/pi-bench.py`

View File

View File

@ -78,18 +78,73 @@ kotlin {
} }
// Generate an index of markdown documents under project /docs as a JSON array // Generate an index of markdown documents under project /docs as a JSON array
val generateSampleDocPages by tasks.registering {
group = "documentation"
description = "Generates Markdown wrapper pages for Lyng sample files"
val examplesDir = rootProject.projectDir.resolve("examples")
val docsSamplesDir = rootProject.projectDir.resolve("docs/samples")
val outDir = layout.buildDirectory.dir("generated-sample-docs/docs")
inputs.dir(examplesDir)
inputs.dir(docsSamplesDir)
outputs.dir(outDir)
doLast {
val outRoot = outDir.get().asFile
outRoot.mkdirs()
fun generateFrom(sourceRoot: java.io.File, targetSubdir: String) {
if (!sourceRoot.exists()) return
sourceRoot.walkTopDown()
.filter { it.isFile && it.extension.equals("lyng", ignoreCase = true) }
.forEach { source ->
val rel = sourceRoot.toPath().relativize(source.toPath()).toString().replace('\\', '/')
val target = outRoot.resolve("$targetSubdir/$rel.md")
target.parentFile.mkdirs()
val title = source.name
val sourceText = source.readText()
val body = buildString {
append("# ").append(title).append("\n\n")
append("Generated from `")
append(
when (targetSubdir) {
"examples" -> "examples/$rel"
"samples" -> "docs/samples/$rel"
else -> "$targetSubdir/$rel"
}
)
append("` during site build.\n\n")
append("```lyng\n")
append(sourceText)
if (!sourceText.endsWith("\n")) append('\n')
append("```\n")
}
target.writeText(body)
}
}
generateFrom(examplesDir, "examples")
generateFrom(docsSamplesDir, "samples")
}
}
val generateDocsIndex by tasks.registering { val generateDocsIndex by tasks.registering {
group = "documentation" group = "documentation"
description = "Generates docs-index.json listing all Markdown files under /docs" description = "Generates docs-index.json listing all Markdown files under /docs"
val docsDir = rootProject.projectDir.resolve("docs") val docsDir = rootProject.projectDir.resolve("docs")
val generatedDocsDir = layout.buildDirectory.dir("generated-sample-docs/docs")
val outDir = layout.buildDirectory.dir("generated-resources") val outDir = layout.buildDirectory.dir("generated-resources")
inputs.dir(docsDir) inputs.dir(docsDir)
inputs.dir(generatedDocsDir)
outputs.dir(outDir) outputs.dir(outDir)
dependsOn(generateSampleDocPages)
doLast { doLast {
val docs = mutableListOf<String>() val docs = linkedSetOf<String>()
if (docsDir.exists()) { if (docsDir.exists()) {
docsDir.walkTopDown() docsDir.walkTopDown()
.filter { it.isFile && it.extension.equals("md", ignoreCase = true) } .filter { it.isFile && it.extension.equals("md", ignoreCase = true) }
@ -100,6 +155,16 @@ val generateDocsIndex by tasks.registering {
docs += "docs/$rel" docs += "docs/$rel"
} }
} }
val generatedRoot = generatedDocsDir.get().asFile
if (generatedRoot.exists()) {
generatedRoot.walkTopDown()
.filter { it.isFile && it.extension.equals("md", ignoreCase = true) }
.forEach { f ->
val rel = generatedRoot.toPath().relativize(f.toPath()).toString()
.replace('\\', '/')
docs += "docs/$rel"
}
}
val out = outDir.get().asFile val out = outDir.get().asFile
out.mkdirs() out.mkdirs()
val file = out.resolve("docs-index.json") val file = out.resolve("docs-index.json")
@ -113,7 +178,7 @@ val generateDocsIndex by tasks.registering {
append(']') append(']')
} }
file.writeText(json) file.writeText(json)
println("Generated ${'$'}{file.absolutePath} with ${'$'}{docs.size} entries") println("Generated ${file.absolutePath} with ${docs.size} entries")
} }
} }
@ -137,7 +202,7 @@ val generateSiteVersion by tasks.registering(Copy::class) {
// Ensure any ProcessResources task depends on docs index generation so the JSON is packaged // Ensure any ProcessResources task depends on docs index generation so the JSON is packaged
tasks.configureEach { tasks.configureEach {
if (name.endsWith("ProcessResources")) { if (name.endsWith("ProcessResources")) {
dependsOn(generateDocsIndex, generateSiteVersion) dependsOn(generateSampleDocPages, generateDocsIndex, generateSiteVersion)
} }
} }
@ -148,16 +213,20 @@ listOf(
"jsProcessResources" "jsProcessResources"
).forEach { taskName -> ).forEach { taskName ->
tasks.matching { it.name == taskName }.configureEach { tasks.matching { it.name == taskName }.configureEach {
dependsOn(generateDocsIndex) dependsOn(generateSampleDocPages, generateDocsIndex)
} }
} }
// Copy Markdown docs into the "docs/" folder in the final resources, so paths in docs-index.json match files // Copy Markdown docs into the "docs/" folder in the final resources, so paths in docs-index.json match files
tasks.named<Copy>("jsProcessResources").configure { tasks.named<Copy>("jsProcessResources").configure {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Ensure we don't end up with two copies at root; we no longer add docs as a plain resources srcDir // Ensure we don't end up with two copies at root; we no longer add docs as a plain resources srcDir
from(rootProject.projectDir.resolve("docs")) { from(rootProject.projectDir.resolve("docs")) {
into("docs") into("docs")
} }
from(layout.buildDirectory.dir("generated-sample-docs/docs")) {
into("docs")
}
} }
// Optional: configure toolchain if needed by the project; uses root Kotlin version from version catalog // Optional: configure toolchain if needed by the project; uses root Kotlin version from version catalog

View File

@ -986,10 +986,14 @@ fun rewriteAnchors(
} }
continue continue
} }
if (href.contains(".md")) { if (href.contains(".md") || href.contains(".lyng")) {
val parts = href.split('#', limit = 2) val parts = href.split('#', limit = 2)
val mdPath = parts[0] val rawPath = parts[0]
val frag = if (parts.size > 1) parts[1] else null val frag = if (parts.size > 1) parts[1] else null
val mdPath = when {
rawPath.endsWith(".lyng") -> "$rawPath.md"
else -> rawPath
}
val target = if (mdPath.startsWith("docs/")) { val target = if (mdPath.startsWith("docs/")) {
normalizePath(mdPath) normalizePath(mdPath)
} else { } else {

View File

@ -21,8 +21,32 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Lyng language</title> <title>Lyng language</title>
<script>
(function () {
var path = window.location.pathname || "/";
var hash = window.location.hash || "";
if (hash) return;
var normalized = path.replace(/^\/+/, "");
var route = null;
if (normalized.startsWith("docs/") && normalized.endsWith(".md")) {
route = normalized;
} else if (normalized.startsWith("examples/") && normalized.endsWith(".lyng")) {
route = "docs/" + normalized + ".md";
} else if (normalized.startsWith("samples/") && normalized.endsWith(".lyng")) {
route = "docs/" + normalized + ".md";
}
if (route) {
var target = window.location.origin + "/#/" + route;
if (window.location.search) target += window.location.search;
window.location.replace(target);
}
})();
</script>
<!-- Site favicon (SVG, adapts to light/dark) --> <!-- Site favicon (SVG, adapts to light/dark) -->
<link rel="icon" type="image/svg+xml" href="icons/lyng-favicon.svg"/> <link rel="icon" type="image/svg+xml" href="/icons/lyng-favicon.svg"/>
<!-- GitHub Markdown CSS (light and dark). We toggle these from the app. --> <!-- GitHub Markdown CSS (light and dark). We toggle these from the app. -->
<link <link
id="md-light" id="md-light"
@ -332,7 +356,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
<!-- and it's easy to individually load additional languages --> <!-- and it's easy to individually load additional languages -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/languages/go.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/languages/go.min.js"></script>
<script src="lyng-version.js"></script> <script src="/lyng-version.js"></script>
</head> </head>
@ -455,7 +479,7 @@
<div id="root" class="pt-4" tabindex="-1" aria-live="polite" aria-atomic="false"></div> <div id="root" class="pt-4" tabindex="-1" aria-live="polite" aria-atomic="false"></div>
<!-- App bundle (produced by Kotlin/JS). The Gradle config forces this name. --> <!-- App bundle (produced by Kotlin/JS). The Gradle config forces this name. -->
<script src="site.js"></script> <script src="/site.js"></script>
<!-- Bootstrap 5.3 JS bundle (includes Popper) --> <!-- Bootstrap 5.3 JS bundle (includes Popper) -->
<script <script