Not sure if this is the right channel to ask, but ...
# dokka
s
Not sure if this is the right channel to ask, but can you manipulate where
knit
generates it's files πŸ€” Currently I have some snippets
md
inside a
docusaurus
project,
rootDir/content/blog/my-doc.md
and I have a Gradle project with KotlinX Knit setup in
rootDir
. My goal is to have a
rootDir/guide
submodule with Kotlin setup, and have KotlinX Knit generate the code in there. Currently the only way I found. to do this is to move the generated Knit files into the
rootDir/guide
, but that seems like a ugly hack 😞
It currently makes a
guide
sub directory in
rootDir/content/blog/
. While it should be in
rootDir/guide
It works if I use
<!--- KNIT example-knit-01.kt -->
but I'd like to use
> You can get the full code [here](guide/src/test/kotlin/example/example-basic-01.kt)
a
have you tried the
test.dir
and
knit.dir
properties? from memory, Knit will read the
knit.properties
file in each dir https://github.com/Kotlin/kotlinx-knit#tests
s
Yes, I have
knit.dir
setup, and it works correctly when using
<!--- KNIT example-knit-01.kt -->
but using a link it completely ignores that path. So I guess it's a bug in Knit πŸ€”
a
so this is what you want to have?
Copy code
└── /
    β”œβ”€β”€ content/
    β”‚   └── blog/
    β”‚       β”œβ”€β”€ my-doc.md
    β”‚       └── knit.properties
    └── guide/
        └── src/test/kotlin/example/
            └── example-basic-01.kt
what happens if you set
Copy code
knit.dir=../../guide/src/test/kotlin/example
?
s
Yes, that is indeed the structure I have. Let me try.
Then it only works the other way around. I can now use
Copy code
> You can get the full code [here](../../guide/src/test/kotlin/examples/example-basic-01.kt)
but breaks
<!--- KNIT example-basic-02.kt -->
😞
a
hmmm
there are also some knit Gradle settings https://github.com/Kotlin/kotlinx-knit#dokka-setup
s
I moved the
knit.properties
to
content/blog
, and I can duplicate it between different folders πŸ€” But now I cannot reference
test.template
by doing
../../
nor using
symlinks
..
Getting somewhere though
I guess the templateloader cannot see symlinks
a
I’m also using Docusaurus + Knit in kxs-ts-gen https://adamko-dev.github.io/kotlinx-serialization-typescript-generator/docs/examples/basic-classes I got this working by having separate Gradle projects for Knit (
./docs/
) and Docusaurus (
./site/
). The Knit project generates the examples & tests internally (
./docs/src/test
,
./docs/src/examples/
), and shares the files to the Docusaurus project via Gradle Configurations. And the Docusaurus project fixes the links with a regex.
πŸ‘€ 1
s
Interesting, thanks for sharing!
a
no problem! Any questions, please ask
s
I think I got it to work without any
Sync
or copy like tasks needed ☺️ Thanks for your help @Adam S! Wouldn't have been able to set it up in this way without it πŸ™
Copy code
└── /
    β”œβ”€β”€ content/
    β”‚   └── blog/
    β”‚       β”œβ”€β”€ my-doc.md
    β”‚       └── knit.properties
    β”‚       └── knit.test.template
    └── guide/
        └── build.gradle.kts
        └── src/test/kotlin/example/
            └── example-basic-01.kt
        └── src/test/kotlin/example/test
            └── BasicTest.kt
    β”œβ”€β”€ knit.properties
    β”œβ”€β”€ build.gradle.kts
    β”œβ”€β”€ settings.gradle.kts
This is the structure I ended up with
a
nice! What did you put
knit.properties
? Did you have to do any
knit {}
Gradle config?
s
In the
root/knit.properties
I am pointing to
guide/src/test/kotlin/examples/
and in the nested
content/blog/knit.properties
I am pointing to the same directory
../../guide/src/test/kotlin/examples/
. My
knit { }
configured is the default, I only applied
siteRoot
.
πŸ‘ 1