Skip to content

Fix Javadoc link generation in Dackka #4258

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

Merged
merged 4 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ abstract class DackkaPlugin : Plugin<Project> {
val transformJavadoc = project.tasks.register<FiresiteTransformTask>("firesiteTransformJavadoc") {
dependsOnAndMustRunAfter("separateJavadoc")

referencePath.set("/docs/reference/android")
referenceHeadTagsPath.set("docs/reference/android")
dackkaFiles.set(project.childFile(separatedFilesDirectory, "android"))
outputDirectory.set(project.childFile(targetDirectory, "android"))
Expand All @@ -303,6 +304,7 @@ abstract class DackkaPlugin : Plugin<Project> {
dependsOnAndMustRunAfter("separateKotlindoc")

referenceHeadTagsPath.set("docs/reference/kotlin")
referencePath.set("/docs/reference/kotlin")
dackkaFiles.set(project.childFile(separatedFilesDirectory, "kotlin"))
outputDirectory.set(project.childFile(targetDirectory, "kotlin"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.gradle.api.tasks.TaskAction
* More specifically, it:
* - Deletes unnecessary files
* - Removes Class and Index headers from _toc.yaml files
* - Appends /docs/ to hyperlinks in html files
* - Changes links to be appropriate for Firesite versus normal Devsite behavior
* - Removes the prefix path from book_path
* - Removes the firebase prefix from all links
* - Changes the path for _reference-head-tags at the top of html files
Expand All @@ -36,6 +36,9 @@ abstract class FiresiteTransformTask : DefaultTask() {
@get:Input
abstract val referenceHeadTagsPath: Property<String>

@get:Input
abstract val referencePath: Property<String>

@get:OutputDirectory
abstract val outputDirectory: Property<File>

Expand Down Expand Up @@ -65,15 +68,21 @@ abstract class FiresiteTransformTask : DefaultTask() {
}

private fun File.fixHTMLFile() {
val fixedContent = readText().fixBookPath().fixHyperlinks().removeLeadingFirebaseDomainInLinks().fixReferenceHeadTagsPath()
val fixedContent = readText().fixBookPath().fixReferenceHeadTagsPath().fixLinks()
writeText(fixedContent)
}

private fun File.fixYamlFile() {
val fixedContent = readText().removeClassHeader().removeIndexHeader().removeLeadingFirebaseDomainInLinks()
val fixedContent = readText().removeClassHeader().removeIndexHeader().fixLinks()
writeText(fixedContent)
}

// Our documentation does not live under the standard path expected by Dackka, especially
// between Kotlin + Javadocs
// TODO(b/243674305): Remove when dackka exposes configuration for this
private fun String.fixLinks() =
replace(Regex("(?<=\")/reference[^\"]*?(?=/com/google/firebase)"), referencePath.get())

// We utilize difference reference head tags between Kotlin and Java docs
// TODO(b/248316730): Remove when dackka exposes configuration for this
private fun String.fixReferenceHeadTagsPath() =
Expand All @@ -92,11 +101,6 @@ abstract class FiresiteTransformTask : DefaultTask() {
private fun String.fixBookPath() =
remove(Regex("(?<=setvar book_path ?%})(.+)(?=/_book.yaml\\{% ?endsetvar)"))

// Our documentation lives under /docs/reference/ versus the expected /reference/
// TODO(b/243674305): Remove when dackka exposes configuration for this
private fun String.fixHyperlinks() =
replace(Regex("(?<=href=\")(/)(?=reference/.*\\.html)"), "/docs/")

// The documentation will work fine without this. This is primarily to make sure that links
// resolve to their local counter part. Meaning when the docs are staged, they will resolve to
// staged docs instead of prod docs- and vise versa.
Expand Down
44 changes: 0 additions & 44 deletions kotlindoc/package-lists/firebase/package-list

This file was deleted.