-
Notifications
You must be signed in to change notification settings - Fork 88
Add built-in sitemap generation support for SEO (#701) #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Add built-in sitemap generation support for SEO (#701) #738
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this.
I took a look at the code relating to the task creation & configuration and left some comments/tips about how to make it more Gradle idiomatic. I haven't looked at the code the pertains to the actual sitemap generation.
The biggest thing to address is the following (copied from one my comments below):
It's worth considering how we actually want a user to enable/disable sitemap generation. While onlyIf { baseUrl.isPresent }
is an option, it has a few drawbacks:
- It's not obvious to a user that
baseUrl
is required for sitemap generation - Users that don't want sitemap generation still see the (skipped) task in their console
Instead, I would suggest having sitemap generation enabled with a function:
fun generateSitemap(baseUrl: String, /* other parameters with defaults */)
// or possibly
fun generateSitemap(baseUrl: String, config: SitemapConfig.() -> Unit = {})
The latter could be nicer to support Property
values, which would allow creating a task to, for example, fetch entries from a database, and then use those values to populate extraRoutes
for dynamic routes. We could also provide both. Calling the function would register the sitemap generation task (with some mechanism to disallow/warn about calling it multiple times) and configure it accordingly.
...pplication/src/main/kotlin/com/varabyte/kobweb/gradle/application/KobwebApplicationPlugin.kt
Outdated
Show resolved
Hide resolved
...pplication/src/main/kotlin/com/varabyte/kobweb/gradle/application/KobwebApplicationPlugin.kt
Outdated
Show resolved
Hide resolved
...on/src/main/kotlin/com/varabyte/kobweb/gradle/application/tasks/KobwebGenerateSitemapTask.kt
Show resolved
Hide resolved
...on/src/main/kotlin/com/varabyte/kobweb/gradle/application/tasks/KobwebGenerateSitemapTask.kt
Outdated
Show resolved
Hide resolved
...on/src/main/kotlin/com/varabyte/kobweb/gradle/application/tasks/KobwebGenerateSitemapTask.kt
Outdated
Show resolved
Hide resolved
...ns/application/src/main/kotlin/com/varabyte/kobweb/gradle/application/extensions/AppBlock.kt
Outdated
Show resolved
Hide resolved
...ns/application/src/main/kotlin/com/varabyte/kobweb/gradle/application/extensions/AppBlock.kt
Outdated
Show resolved
Hide resolved
...ns/application/src/main/kotlin/com/varabyte/kobweb/gradle/application/extensions/AppBlock.kt
Outdated
Show resolved
Hide resolved
...ns/application/src/main/kotlin/com/varabyte/kobweb/gradle/application/extensions/AppBlock.kt
Outdated
Show resolved
Hide resolved
…d improve configuration validation
…ion and improve resource processing integration
…eRoutes` with extensible `filter` for route inclusion
…onfiguration and improve Gradle task skipping behavior
…uring `generateSitemap` calls
I'm not sure if you are waiting for a review on this (feel free to request a re-review from me if so), but I'll note that in the current state Also, in case it got buried, I described here how to deal with |
…ialization handling
…le provider handling and gradle caching
…fore writing sitemap file
there was indeed a misplaced
to:
|
regarding kobwebSiteRoutes Fix: configuration cache compatibility for
|
…ror when base path is not included
Overview
Implements automatic XML sitemap generation for Kobweb applications to improve SEO and search engine discoverability.
Closes #701
Implementation Details
New Features
sitemap.xml
at site root (/sitemap.xml
)@Page
annotation detection (includes markdown-generated pages)kobweb.app.sitemap { ... }
/users/{id}
by defaultexcludeRoutes
,extraRoutes
, and customrouteFilter
lambdashttp://localhost:8080
for development testingTask Dependencies
kobwebxMarkdownProcess
) when presentsrc/jsMain/resources/public/sitemap.xml
Configuration Examples
Basic usage:
kobweb { app { sitemap { baseUrl.set("https://mysite.com") } } }
Advanced configuration:
Localhost testing:
kobweb { app { sitemap { baseUrl.set("http://localhost:8080") } } }
Key Benefits
baseUrl
/sitemap.xml
locationFiles Added/Modified
KobwebGenerateSitemapTask.kt
- Main sitemap generation taskAppBlock.kt
- AddedSitemapBlock
configuration DSLKobwebApplicationPlugin.kt
- Task registration and dependency wiringTesting
http://localhost:8080
for local development testingsrc/jsMain/resources/public/sitemap.xml
/sitemap.xml
when server is runningkobweb start
) and production (kobweb export
) workflowsBreaking Changes
None - this is purely additive functionality that only activates when
baseUrl
is configured.