Skip to content

Commit

Permalink
Use code generator to generate unique pages for multi-languague SEO
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 9, 2023
1 parent b2b153c commit 272f7bc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
51 changes: 51 additions & 0 deletions site/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,55 @@ kotlin {
}
}

// For SEO we will have to use unique urls for each page
// Here we will use code generator to generate unique pages that redirect to the original pages

val langs = listOf("ar")
val pages = listOf("download_mobile_app", "privacy_policy")

val generateLanguaguesPagesTask = tasks.register("generateLanguaguesPages") {
group = "net.freshplatform.alrayada_landing_page"

doLast {
val pagesDirectory = project.file("src/jsMain/kotlin/net/freshplatform/alrayada_landing_page")
langs.forEach { lang ->
pages.forEach { page ->

pagesDirectory.resolve("pages/$lang/${page}/Index.kt").apply {
parentFile.mkdirs()
writeText("""
package ${group}.pages.ar.${page}
import androidx.compose.runtime.Composable
import com.varabyte.kobweb.core.Page
import com.varabyte.kobweb.core.rememberPageContext
@Composable
@Page
fun PrivacyPolicyPage_${lang}() {
rememberPageContext().router.navigateTo("/${page}/?lang=${lang}")
}
""".trimIndent())
}
}

pagesDirectory.resolve("pages/$lang/Index.kt").apply {
parentFile.mkdirs()
writeText("""
package ${group}.pages.ar
import androidx.compose.runtime.Composable
import com.varabyte.kobweb.core.Page
import com.varabyte.kobweb.core.rememberPageContext
@Composable
@Page
fun PrivacyPolicyPage_${lang}() {
rememberPageContext().router.navigateTo("/?lang=${lang}")
}
""".trimIndent())
}

}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package net.freshplatform.alrayada_landing_page.core.router

object AppRouter {
// Unfortunately we can't use those in the pages routeOverride, even though it's a constant in compile time
const val HOME = ""
// Unfortunately, we can't use those in the pages routeOverride, even though it's a constant in compile time
const val PRIVACY_POLICY = "/privacy_policy"
const val DOWNLOAD_MOBILE_APP = "/download_mobile_app"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import com.varabyte.kobweb.core.rememberPageContext

@Composable
@Page
fun HomePage_Arabic() {
fun PrivacyPolicyPage_ar() {
rememberPageContext().router.navigateTo("/?lang=ar")
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package net.freshplatform.alrayada_landing_page.pages.ar.download_mobile_app

import androidx.compose.runtime.Composable
import net.freshplatform.alrayada_landing_page.core.router.AppRouter
import com.varabyte.kobweb.core.Page
import com.varabyte.kobweb.core.rememberPageContext

@Composable
@Page
fun DownloadMobileAppPage_Arabic() {
rememberPageContext().router.navigateTo("${AppRouter.DOWNLOAD_MOBILE_APP}/?lang=ar")
fun PrivacyPolicyPage_ar() {
rememberPageContext().router.navigateTo("/download_mobile_app/?lang=ar")
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package net.freshplatform.alrayada_landing_page.pages.ar.privacy_policy

import androidx.compose.runtime.Composable
import net.freshplatform.alrayada_landing_page.core.router.AppRouter
import com.varabyte.kobweb.core.Page
import com.varabyte.kobweb.core.rememberPageContext

@Composable
@Page
fun PrivacyPolicyPage_Arabic() {
rememberPageContext().router.navigateTo("${AppRouter.PRIVACY_POLICY}/?lang=ar")
fun PrivacyPolicyPage_ar() {
rememberPageContext().router.navigateTo("/privacy_policy/?lang=ar")
}

0 comments on commit 272f7bc

Please sign in to comment.