Skip to content

Commit

Permalink
Create complete documentation site (#189)
Browse files Browse the repository at this point in the history
* 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
aSemy authored Mar 17, 2024
1 parent 779f5e7 commit 5e5b75f
Show file tree
Hide file tree
Showing 107 changed files with 18,126 additions and 380 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ examples/** linguist-d
examples/*/dokka linguist-vendored
examples/versioning-multimodule-example/dokka/previousDocVersions linguist-generated
examples/versioning-multimodule-example/dokkatoo/previousDocVersions linguist-generated
modules/docs/** linguist-documentation
modules/dokkatoo-plugin-integration-tests/projects/**dokka/ linguist-vendored
modules/dokkatoo-plugin-integration-tests/projects/**dokkatoo/ linguist-documentation

Expand Down
40 changes: 5 additions & 35 deletions .github/workflows/run_publish_site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ concurrency:

jobs:

build-dokka:
build-site:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
Expand All @@ -40,52 +40,23 @@ jobs:
distribution: temurin
java-version: 11

- name: dokkatooGenerate
- name: Build site
uses: gradle/gradle-build-action@v3
with:
gradle-home-cache-cleanup: true
# write build cache on 'main' and 'release' branches, or tags (default is 'main' only)
cache-read-only: ${{ github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/heads/release') && !startsWith(github.ref, 'refs/tags/') }}
arguments: |
:modules:docs:dokkatooGenerate
:modules:docs:docusaurusBuild
- name: Upload Dokka to Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./modules/docs/build/dokka/html/


build-writerside:
runs-on: ubuntu-latest
env:
WRITERSIDE_INSTANCE: "dokkatoo/d"
WRITERSIDE_DOC_ZIP: "webHelpD2-all.zip"
steps:
- name: Build Writerside docs
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.WRITERSIDE_INSTANCE }}
artifact: ${{ env.WRITERSIDE_DOC_ZIP }}
docker-version: "233.14389"

- name: Writerside check
uses: JetBrains/writerside-checker-action@v1
with:
instance: ${{ env.WRITERSIDE_INSTANCE }}

- name: Unpack Writerside zip
run: unzip -O UTF-8 -qq '${{ env.WRITERSIDE_DOC_ZIP }}' -d writerside-dir

- name: Upload Writerside to Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./writerside-dir/

path: ./modules/docs/site/build/

deploy:
needs:
- build-dokka
- build-writerside
- build-site
runs-on: ubuntu-latest
permissions:
pages: write # to deploy to Pages
Expand All @@ -94,7 +65,6 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
10 changes: 10 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ jobs:
gradle-task: >-
${{ matrix.task }} --stacktrace
checkout-ref: ${{ inputs.checkout-ref }}


site-check:
# verify the site can be built
uses: ./.github/workflows/run_gradle_task.yml
with:
runs-on: ubuntu-latest
gradle-task: >-
docusaurusBuild --stacktrace
checkout-ref: ${{ inputs.checkout-ref }}
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ dependencies {
implementation(libs.gradlePlugin.bcvMu)
implementation(libs.gradlePlugin.dokkatoo)
implementation(libs.gradlePlugin.gradlePublishPlugin)
implementation(libs.gradlePlugin.node)
implementation("org.jetbrains.kotlin:kotlin-serialization:$embeddedKotlinVersion")

implementation("org.tomlj:tomlj:1.1.1") {
because("parse Dokka's libs.version.toml, so Dokkatoo can use the same versions")
}

compileOnly("com.microsoft.playwright:playwright:1.42.0")
}

java {
Expand Down
56 changes: 56 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/screenshotter/ScreenshotTask.kt
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))
}
}
}
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 buildSrc/src/main/kotlin/buildsrc/screenshotter/Website.kt
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 buildSrc/src/main/kotlin/buildsrc/screenshotter/plugin.gradle.kts
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)
}
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/utils/gradleNode.kt
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))
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gradlePlugin-android = "8.3.0"
gradlePlugin-dokkatoo = "latest.integration"
gradlePlugin-gradlePublishPlugin = "1.2.1"
gradlePlugin-bcvMu = "0.1.0"
gradlePlugin-node = "7.0.2"


[libraries]
Expand Down Expand Up @@ -49,6 +50,7 @@ kotest-assertionsJson = { module = "io.kotest:kotest-assertions-json" }
gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "gradlePlugin-android" }
gradlePlugin-androidApi = { module = "com.android.tools.build:gradle-api", version.ref = "gradlePlugin-android" }
gradlePlugin-dokkatoo = { module = "dev.adamko.dokkatoo:dokkatoo-plugin", version.ref = "gradlePlugin-dokkatoo" }
gradlePlugin-node = { module = "com.github.node-gradle:gradle-node-plugin", version.ref = "gradlePlugin-node" }
gradlePlugin-bcvMu = { module = "dev.adamko.kotlin.binary_compatibility_validator:bcv-gradle-plugin", version.ref = "gradlePlugin-bcvMu" }
gradlePlugin-gradlePublishPlugin = { module = "com.gradle.publish:plugin-publish-plugin", version.ref = "gradlePlugin-gradlePublishPlugin" }
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand Down
41 changes: 41 additions & 0 deletions modules/docs/DocsReadme.md
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.
Loading

0 comments on commit 5e5b75f

Please sign in to comment.