Add built-in sitemap generation support for SEO (#701)#738
Add built-in sitemap generation support for SEO (#701)#738kocheick wants to merge 17 commits intovarabyte:devfrom
Conversation
DennisTsar
left a comment
There was a problem hiding this comment.
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
baseUrlis 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
|
Hi! Any updates? |
The feature ended up being a bit tricky to make sure we were getting it right for the general use-case, so at the moment it's stalled. Note that generating a sitemap on your own custom needs should be relatively trivial using Gradle (or just dropping a sitemap.xml into your resources/ folder). See also: |
80e7fa9 to
28deb8c
Compare
9100fe4 to
174e259
Compare
Overview
Implements automatic XML sitemap generation for Kobweb applications to improve SEO and search engine discoverability.
Closes #701
Implementation Details
New Features
sitemap.xmlat site root (/sitemap.xml)@Pageannotation detection (includes markdown-generated pages)kobweb.app.sitemap { ... }/users/{id}by defaultexcludeRoutes,extraRoutes, and customrouteFilterlambdashttp://localhost:8080for development testingTask Dependencies
kobwebxMarkdownProcess) when presentsrc/jsMain/resources/public/sitemap.xmlConfiguration Examples
Basic usage:
kobweb { app { sitemap { baseUrl.set("https://mysite.com") } } }Advanced configuration:
kobweb { app { sitemap { baseUrl.set("https://mysite.com") extraRoutes.addAll("/blog/post-1", "/products/special") excludeRoutes.addAll("/admin", "/internal") routeFilter.set { !it.contains("/temp/") } } } }Localhost testing:
kobweb { app { sitemap { baseUrl.set("http://localhost:8080") } } }Key Benefits
baseUrl/sitemap.xmllocationFiles Added/Modified
KobwebGenerateSitemapTask.kt- Main sitemap generation taskAppBlock.kt- AddedSitemapBlockconfiguration DSLKobwebApplicationPlugin.kt- Task registration and dependency wiringTesting
http://localhost:8080for local development testingsrc/jsMain/resources/public/sitemap.xml/sitemap.xmlwhen server is runningkobweb start) and production (kobweb export) workflowsBreaking Changes
None - this is purely additive functionality that only activates when
baseUrlis configured.