-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create complete documentation site (#189)
* migrate from Writerside to Docusaurus * update actions * many progresses for website innit * tidy, todos, fix edit link * add more todos * improve homepage features * improve homepage features * remove completed task "update features so they are spaced evenly" * fix external link arrow * tweak features colours * fix external link arrow * add more metadata content tags * update package-lock.json * create screenshot capturing tool using Playwright * cracking progress with the showcase site * add TODOs for tuning-performance.md docs * add some delays to ScreenshotterWorker, to ensure the pages load before screenshotting * showcase tweaks/fixes * tweak user tags * fixing features site * remove and/or boolean filter * remove text search * update Dokkatoo screenshot * tweak ScreenshotterWorker * Many wizardy things. It's looking very pretty now! * mark `modules/docs` as documentation * add examples to showcase * sort tags * simplifying svg, translating, and tidying * update showcase tag descriptions * finish up getting-started.mdx * many docs progressesings * update heart icon * wip * tweak tuning-performance.md * finish up convention-plugins.md, tidy migrating-from-dokka.md * formatting * typo * file tree formatting * tidying, reorg user data * update features text * add 'pick and choose' plugin selection option * fix static site generation * trace deprecated npm modules (easier to debug)
- Loading branch information
Showing
107 changed files
with
18,126 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
buildSrc/src/main/kotlin/buildsrc/screenshotter/ScreenshotTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package buildsrc.screenshotter | ||
|
||
import buildsrc.utils.domainObjectContainer | ||
import java.net.URI | ||
import javax.inject.Inject | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.NamedDomainObjectContainer | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.tasks.* | ||
import org.gradle.kotlin.dsl.* | ||
import org.gradle.workers.WorkerExecutor | ||
|
||
/** | ||
* Take screenshots of [websites] using Playwright. | ||
*/ | ||
@CacheableTask | ||
abstract class ScreenshotTask @Inject constructor( | ||
private val workers: WorkerExecutor, | ||
private val objects: ObjectFactory, | ||
) : DefaultTask() { | ||
|
||
@get:OutputDirectory | ||
abstract val outputDirectory: DirectoryProperty | ||
|
||
@get:Nested | ||
val websites: NamedDomainObjectContainer<Website> = objects.domainObjectContainer() | ||
|
||
@get:Classpath | ||
abstract val runtimeClasspath: ConfigurableFileCollection | ||
|
||
init { | ||
group = "screenshotter" | ||
description = "Take screenshots of websites, save to directory. Used for the website showcase." | ||
extensions.add("websites", websites) // so that Gradle generates Kotlin DSL accessors | ||
} | ||
|
||
@TaskAction | ||
fun action() { | ||
val workQueue = workers.classLoaderIsolation { | ||
classpath.from(runtimeClasspath) | ||
} | ||
|
||
workQueue.submit(ScreenshotterWorker::class) { | ||
this.websites.addAll(this@ScreenshotTask.websites.map(ScreenshotterWorker.Parameters::Website)) | ||
this.outputDirectory = this@ScreenshotTask.outputDirectory | ||
} | ||
} | ||
|
||
fun website(name: String, uri: String) { | ||
websites.register(name) { | ||
this.uri.set(URI(uri)) | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
buildSrc/src/main/kotlin/buildsrc/screenshotter/ScreenshotterWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package buildsrc.screenshotter | ||
|
||
import com.microsoft.playwright.Browser | ||
import com.microsoft.playwright.Browser.NewPageOptions | ||
import com.microsoft.playwright.Page.ScreenshotOptions | ||
import com.microsoft.playwright.Playwright | ||
import com.microsoft.playwright.options.ColorScheme | ||
import com.microsoft.playwright.options.ColorScheme.DARK | ||
import com.microsoft.playwright.options.ColorScheme.LIGHT | ||
import com.microsoft.playwright.options.LoadState.DOMCONTENTLOADED | ||
import java.io.Serializable | ||
import java.net.URI | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.nanoseconds | ||
import kotlin.time.Duration.Companion.seconds | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.logging.Logging | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.workers.WorkAction | ||
import org.gradle.workers.WorkParameters | ||
|
||
internal abstract class ScreenshotterWorker : WorkAction<ScreenshotterWorker.Parameters> { | ||
|
||
private val logger = Logging.getLogger(ScreenshotterWorker::class.java) | ||
|
||
interface Parameters : WorkParameters { | ||
val outputDirectory: DirectoryProperty | ||
val websites: ListProperty<Website> | ||
|
||
data class Website( | ||
val name: String, | ||
val uri: URI, | ||
val isEnabled: Boolean, | ||
) : Serializable { | ||
constructor(website: buildsrc.screenshotter.Website) : this( | ||
name = website.name, | ||
uri = website.uri.get(), | ||
isEnabled = website.enabled.orNull ?: false, | ||
) | ||
} | ||
} | ||
|
||
override fun execute() { | ||
Playwright.create().use { playwright -> | ||
logger.info("[ScreenshotterWorker] Created Playwright ${playwright}") | ||
playwright.webkit().launch().use { browser -> | ||
parameters.websites | ||
.get() | ||
.filter { it.isEnabled } | ||
.forEach { website -> | ||
browser.screenshot(website.name, website.uri, LIGHT) | ||
browser.screenshot(website.name, website.uri, DARK) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Browser.screenshot( | ||
name: String, | ||
uri: URI, | ||
colorScheme: ColorScheme, | ||
) { | ||
val outputFileName = "$name-${colorScheme.name.lowercase()}.png" | ||
val outputFile = parameters.outputDirectory | ||
.file(outputFileName) | ||
.get().asFile | ||
val duration = measureTime { | ||
newPage( | ||
NewPageOptions() | ||
.setColorScheme(colorScheme) | ||
).apply { | ||
navigate(uri.toString()).finished() | ||
waitForLoadState(DOMCONTENTLOADED) | ||
Thread.sleep(0.5.seconds.inWholeMilliseconds) | ||
screenshot( | ||
ScreenshotOptions().setPath(outputFile.toPath()) | ||
) | ||
} | ||
} | ||
logger.lifecycle("[ScreenshotterWorker] Captured ${colorScheme.name.lowercase()} screenshot for $name $uri in $duration") | ||
} | ||
|
||
companion object { | ||
// can't use kotlin.time.measureTime {} because Gradle forces the language level to be low. | ||
private fun measureTime(block: () -> Unit): Duration = | ||
System.nanoTime().let { startTime -> | ||
block() | ||
(System.nanoTime() - startTime).nanoseconds | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
buildSrc/src/main/kotlin/buildsrc/screenshotter/Website.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package buildsrc.screenshotter | ||
|
||
import java.io.Serializable | ||
import java.net.URI | ||
import javax.inject.Inject | ||
import org.gradle.api.Named | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.Optional | ||
|
||
abstract class Website @Inject constructor( | ||
@Internal | ||
protected val named: String, | ||
) : Named, Serializable { | ||
@get:Input | ||
abstract val uri: Property<URI> | ||
@get:Input | ||
@get:Optional | ||
abstract val enabled: Property<Boolean> | ||
|
||
@Input | ||
override fun getName(): String = named | ||
} |
32 changes: 32 additions & 0 deletions
32
buildSrc/src/main/kotlin/buildsrc/screenshotter/plugin.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package buildsrc.screenshotter | ||
|
||
import buildsrc.utils.declarable | ||
import buildsrc.utils.resolvable | ||
import org.gradle.api.attributes.Usage.JAVA_RUNTIME | ||
import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE | ||
|
||
|
||
val screenshotterClasspath: Configuration by configurations.creating { | ||
declarable() | ||
withDependencies { | ||
add(project.dependencies.create("com.microsoft.playwright:playwright:1.42.0")) | ||
} | ||
} | ||
|
||
val screenshotterClasspathResolver: Configuration by configurations.creating { | ||
resolvable() | ||
extendsFrom(screenshotterClasspath) | ||
attributes { | ||
attribute(USAGE_ATTRIBUTE, objects.named(JAVA_RUNTIME)) | ||
} | ||
} | ||
|
||
val screenshotter by tasks.registering(ScreenshotTask::class) { | ||
runtimeClasspath.from(screenshotterClasspathResolver.incoming.files) | ||
|
||
websites.configureEach { | ||
enabled.convention(true) | ||
} | ||
|
||
outputDirectory.set(temporaryDir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package buildsrc.utils | ||
|
||
import com.github.gradle.node.npm.task.NpmTask | ||
import org.gradle.api.provider.Provider | ||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs | ||
|
||
fun NpmTask.args(values: String) { | ||
args.set(parseSpaceSeparatedArgs(values)) | ||
} | ||
|
||
fun NpmTask.args(values: Provider<String>) { | ||
args.addAll(values.map(::parseSpaceSeparatedArgs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Website | ||
|
||
The Dokkatoo website is built using [Docusaurus](https://docusaurus.io/), a modern static website | ||
generator. | ||
|
||
Some docs are provided by [the documentation subproject](../docs/), as they are processed by Knit. | ||
|
||
### Local Development | ||
|
||
```shell | ||
./gradlew docusaurusRun | ||
``` | ||
|
||
This command starts a local development server and opens up a browser window. Most changes are | ||
reflected live without having to restart the server. | ||
|
||
### Build | ||
|
||
```shell | ||
./gradlew docusaurusBuild | ||
``` | ||
|
||
This command generates static content into the `build` directory and can be served using any static | ||
contents hosting service. | ||
|
||
### Deployment | ||
|
||
Using SSH: | ||
|
||
```shell | ||
USE_SSH=true yarn deploy | ||
``` | ||
|
||
Not using SSH: | ||
|
||
```shell | ||
GIT_USER=<Your GitHub username> yarn deploy | ||
``` | ||
|
||
If you are using GitHub pages for hosting, this command is a convenient way to build the website and | ||
push to the `gh-pages` branch. |
Oops, something went wrong.