Skip to content

Commit

Permalink
Package static assets with shared compose resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneeVandervelde committed Aug 18, 2024
1 parent 18fcc00 commit 19f78bc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/pushes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,11 @@ jobs:
-
name: Build Static Sample
run: ./gradlew sample-web:buildStatic sample-web:assemble
-
name: Create Deploy Directory
run: |
mkdir -p build/pages
cp -r sample-web/build/static/* build/pages/
cp -r sample-web/build/dist/js/productionExecutable/* build/pages/
mv build/pages/sample.html build/pages/index.html
-
name: Upload Pages Artifact
uses: actions/[email protected]
with:
path: build/pages
path: sample-web/build/dist/web
-
name: Deploy to GitHub Pages
uses: actions/[email protected]
3 changes: 0 additions & 3 deletions render-compose-html/src/commonMain/resources/common.css

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ abstract class InkUiScript {
var title: String? = null
var sectioned: Boolean = false
var contentBreak: Boolean = false
var resourceBaseUrl: String = "https://ui.inkapplications.com/res"

fun addPageHeader(element: UiElement) {
pageHeaders.add(renderer.renderElement(element))
Expand All @@ -48,16 +49,18 @@ abstract class InkUiScript {
styles += stylesheet
}

fun useHostedStyles() {
styles += "https://assets.inkapplications.com/css/main-v1.3.css"
private fun getStyles(): List<String> {
return listOf(
"$resourceBaseUrl/css/main-2.0.css",
) + styles
}

internal fun getHtml(): String {
return renderer.renderDocument(
pageTitle = title ?: fileName,
pageHeaders = pageHeaders,
bodies = bodies,
stylesheets = styles,
stylesheets = getStyles(),
sectioned = sectioned,
contentBreak = contentBreak,
)
Expand Down
40 changes: 35 additions & 5 deletions sample-web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,48 @@ kotlin {
}
}

val staticOutputDir = project.layout.buildDirectory.get().dir("static").asFile
val staticResDir = project.layout.buildDirectory.get().dir("static/res").asFile
val composeOutputDir = project.layout.buildDirectory.get().dir("dist/js/productionExecutable").asFile
val webDistDir = project.layout.buildDirectory.get().dir("dist/web").asFile
val webDistComposeDir = project.layout.buildDirectory.get().dir("dist/web/compose").asFile

tasks.register("buildStatic") {
dependsOn(projects.renderStaticHtml.dependencyProject.tasks.named("installDist"))
doLast {
staticOutputDir.createDirectory()
exec {
val app = projects.renderStaticHtml.dependencyProject.layout.buildDirectory.get().file("install/render-ui/bin/render-ui")
val script = project.layout.projectDirectory.file("src/staticMain/Sample.inkui.kts")
val staticDir = project.layout.buildDirectory.get().dir("static").asFile
if (!staticDir.exists()) {
staticDir.createDirectory()
}
val output = "${staticDir.path}/sample.html"
val output = "${staticOutputDir.path}/index.html"
commandLine("sh", "-c", "$app $script > $output")
}
copy {
staticResDir.createDirectory()
from(projects.renderComposeHtml.dependencyProject.layout.projectDirectory.dir("src/commonMain/composeResources"))
into(staticResDir)
}
}
}

tasks.named("assemble") {
dependsOn("buildStatic")
}

tasks.register("distWeb") {
dependsOn("assemble")

doLast {
webDistDir.createDirectory()
webDistComposeDir.createDirectory()

copy {
from(staticOutputDir)
into(webDistDir)
}
copy {
from(composeOutputDir)
into(webDistComposeDir)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Sample</title>
<link rel="stylesheet" href="composeResources/com.inkapplications.ui.render_compose_html.generated.resources/css/common.css" type="text/css" media="all" />
<link rel="stylesheet" href="composeResources/com.inkapplications.ui.render_compose_html.generated.resources/css/main-2.0.css" type="text/css" media="all" />
</head>
<body class="sectioned" id="compose-root">
<script src="sample-web.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion sample-web/src/staticMain/Sample.inkui.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
useHostedStyles()
title = "Test"
resourceBaseUrl = "res"
sectioned = true

addPageHeader(TextElement("Page Header", TextStyle.H1))
Expand Down

0 comments on commit 19f78bc

Please sign in to comment.