forked from smithy-lang/smithy-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocsLandingPage.kt
57 lines (51 loc) · 2.12 KB
/
DocsLandingPage.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk
import org.gradle.api.Project
import software.amazon.smithy.utils.SimpleCodeWriter
import java.io.File
/**
* Generate a basic docs landing page into [outputDir]
*
* The generated docs will include links to crates.io, docs.rs and GitHub examples for all generated services. The generated docs will
* be written to `docs.md` in the provided [outputDir].
*/
fun Project.docsLandingPage(awsServices: AwsServices, outputPath: File) {
val project = this
val writer = SimpleCodeWriter()
with(writer) {
write("# AWS SDK for Rust")
write(
"The AWS SDK for Rust contains one crate for each AWS service, as well as ${cratesIo("aws-config")} " +
"${docsRs("aws-config")}, a crate implementing configuration loading such as credential providers. " +
"For usage documentation see the [Developer Guide](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/welcome.html).",
)
writer.write("## AWS Services")
writer.write("") // empty line between header and table
/* generate a basic markdown table */
writer.write("| Service | Package |")
writer.write("| ------- | ------- |")
awsServices.services.sortedBy { it.humanName }.forEach {
val items = listOfNotNull(cratesIo(it), docsRs(it), examplesLink(it, project)).joinToString(" ")
writer.write(
"| ${it.humanName} | $items |",
)
}
}
outputPath.writeText(writer.toString())
}
/**
* Generate a link to the examples for a given service
*/
private fun examplesLink(service: AwsService, project: Project) = service.examplesUri(project)?.let {
"([examples]($it))"
}
/**
* Generate a link to the docs
*/
private fun docsRs(service: AwsService) = docsRs(service.crate())
private fun docsRs(crate: String) = "([docs](https://docs.rs/$crate))"
private fun cratesIo(service: AwsService) = cratesIo(service.crate())
private fun cratesIo(crate: String) = "[$crate](https://crates.io/crates/$crate)"