Skip to content

Commit d0dc250

Browse files
authored
Add transform action to remove package prefix in toc files (#6787)
Per [b/379093944](https://b.corp.google.com/issues/379093944), This adds a transform action to remove the `com.google.` package prefix in the TOC files, as it pollutes the visual landscape for consumers. Long-term, this action will be replaced by a parameter offered via newer versions of dackka- but we don't currently have the bandwidth for such an upgrade. A tracking bug has been left with the implementation to migrate to said parameter whenever we have the time to upgrade.
1 parent 60a021d commit d0dc250

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

plugins/src/main/java/com/google/firebase/gradle/plugins/FiresiteTransformTask.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import org.gradle.api.tasks.TaskAction
3838
* - Adds the deprecated status to ktx sections in _toc.yaml files
3939
* - Fixes broken hyperlinks in `@see` blocks
4040
* - Removes the prefix path from book_path
41+
* - Removes the `com.google` package prefix from _toc.yaml files
4142
*
4243
* **Please note:** This task is idempotent- meaning it can safely be ran multiple times on the same
4344
* set of files.
@@ -77,10 +78,35 @@ abstract class FiresiteTransformTask : DefaultTask() {
7778
}
7879

7980
private fun File.fixYamlFile() {
80-
val fixedContent = readText().removeClassHeader().removeIndexHeader().addDeprecatedStatus()
81+
val fixedContent =
82+
readText().removeClassHeader().removeIndexHeader().addDeprecatedStatus().removePackagePrefix()
8183
writeText(fixedContent)
8284
}
8385

86+
/**
87+
* Removes the `com.google.` prefix from the package titles in the table of contents.
88+
*
89+
* The prefix pollutes the TOC, especially on smaller screen sizes; so we opt to removed it
90+
* entirely.
91+
*
92+
* Example input:
93+
* ```
94+
* toc:
95+
* - title: "com.google.firebase.functions"
96+
* path: "/docs/reference/android/com/google/firebase/functions/package-summary.html"
97+
* ```
98+
*
99+
* Example output:
100+
* ```
101+
* toc:
102+
* - title: "firebase.functions"
103+
* path: "/docs/reference/android/com/google/firebase/functions/package-summary.html"
104+
* ```
105+
*
106+
* TODO(b/378717454): Migrate to the param packagePrefixToRemoveInToc in dackka when fixed
107+
*/
108+
private fun String.removePackagePrefix() = remove(Regex("(?<=title: \")(com\\.google\\.)"))
109+
84110
/**
85111
* Fixes broken hyperlinks in the rendered HTML
86112
*

0 commit comments

Comments
 (0)