-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
sbt/src/main/scala/pink/cozydev/protosearch/ProtosearchPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 CozyDev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pink.cozydev.protosearch.sbt | ||
|
||
import sbt.* | ||
import sbt.Keys.* | ||
import laika.sbt.LaikaPlugin | ||
import laika.sbt.LaikaPlugin.autoImport._ | ||
|
||
object ProtosearchPlugin extends AutoPlugin { | ||
|
||
override val trigger = allRequirements | ||
|
||
override def requires = plugins.JvmPlugin && LaikaPlugin | ||
|
||
object autoImport { | ||
val protosearchGenerateIndex = taskKey[Set[File]]("Generate Protosearch Index files") | ||
val protosearchIndexTarget = settingKey[String]("The target directory for index files") | ||
} | ||
|
||
import autoImport._ | ||
|
||
override lazy val projectSettings: Seq[Setting[_]] = Seq( | ||
protosearchIndexTarget := ((Laika / target).value / "index").toString(), | ||
protosearchGenerateIndex := Tasks.protosearchGenerateIndex.value, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2022 CozyDev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pink.cozydev.protosearch.sbt | ||
|
||
import cats.effect.IO | ||
import cats.effect.unsafe.implicits.global | ||
import pink.cozydev.protosearch.analysis.DocsDirectory | ||
import sbt.* | ||
import laika.io.model.FilePath | ||
|
||
object Tasks { | ||
import Def.* | ||
import laika.sbt.LaikaPlugin.autoImport._ | ||
import pink.cozydev.protosearch.sbt.ProtosearchPlugin.autoImport._ | ||
|
||
val protosearchGenerateIndex: Initialize[Task[Set[File]]] = task { | ||
val userConfig = (Compile / laikaConfig).value | ||
val targetDir = protosearchIndexTarget.value | ||
|
||
val parser = laika.sbt.Settings.parser.value | ||
val tree = parser.use(_.fromInput(laikaInputs.value.delegate).parse).unsafeRunSync() | ||
DocsDirectory.plaintextRenderer | ||
.use( | ||
_.from(tree) | ||
.toDirectory(FilePath.parse(targetDir))(userConfig.encoding) | ||
.render | ||
) | ||
.unsafeRunSync() | ||
|
||
val msg = IO.println(s"rendered to ${targetDir}") | ||
|
||
msg.unsafeRunSync() | ||
Set.empty | ||
} | ||
|
||
} |