Hallo there :smile: , I currently have a bunch of ...
# kobweb
s
Hallo there 😄 , I currently have a bunch of markdown files that are auto-generated by some reporting libraries, I would like to have kobweb turn these into compose web pages. Copying them into
src/jsMain/resources/markdown
feels wrong, as I don't really want these in source control. Is there a way to tell kobweb-x markdown to look at a different folder to find the markdown-files to process?
d
Hmmm maybe I can turn https://github.com/varabyte/kobweb/blob/ffaeb907fd0d4ababe77fee892d5e9ff61ce2e87/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/MarkdownBlock.kt#L16 into a list property. For now would you be ok making sure those files get generated into
build/generated/reporting-lib/src/jsMain/resources/markdown/
and add
build/generated/reporting-lib
to your Kotlin resource dirs?
s
Hi. Thanks for your reply. This is actually the approach I was trying, but it was looking like the markdown process was only looking under the src folder for md files, not the build folder. I'll double check to make sure I havent made a mistake here...
d
You added the
Copy code
jsMain {
    resources.srcDir(yourTaskWithDirOutputHere)
}
line? As a test, you can call
Copy code
kobweb {
  markdown {
    process.set {
      generateMarkdown("test.md", "This is a test")
    }
  }
}
and see where that file ends up getting generated into at compile time.
@stantronic FYI we overhauled the implementation behind the scenes for our markdown processing logic. I tried to keep your comment in mind so hopefully you'll be able to verify that our approach will work for you. We've just pushed
0.20.5-SNAPSHOT
which contains the changes. I think you'll actually have to change your code because we no longer search all resource directories automatically anymore (we ran into a chicken and egg problem where people wanted to produce resources in response to processing their markdown). We will only look under
"src/jsMain/resources/markdown"
by default moving forward. So now what you can do is call
kobweb.markdown.addSource
and give it the root directory of where your generated markdown files live. No more need to force a magical "markdown" subfolder to exist in there. In your project's build script, I imagine the change would be:
Copy code
kobweb.markdown.addSource(
  project.layout.buildDirectory.dir(
    "generated/reporting-lib/markdown-files"
  )
)
and you should be good to go. At that point, a markdown file under
.../markdown-files
will get converted into a root page in your site. Let's say you wanted all those files to go into a subroute. For example, say
.../markdown-files/ExPage.md
should become
"<http://yoursite.com/reporting/ex-page|yoursite.com/reporting/ex-page>
In that case, you can associate each new source location with a target package all code should be added under. So for the above case, that would look like:
Copy code
kobweb.markdown.addSource(
  project.layout.buildDirectory.dir(
    "generated/reporting-lib/markdown-files"
  ),
  ".pages.reporting"
)