Skip to content

Commit 50d48fd

Browse files
committed
Add a table of contents to MetricsDocGen
1 parent af2ca87 commit 50d48fd

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

core/src/main/java/org/apache/accumulo/core/metrics/MetricsDocGen.java

+29-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class MetricsDocGen {
3737

3838
void generate() {
3939
pageHeader();
40+
generateTableOfContents();
4041

4142
for (var category : Metric.MetricCategory.values()) {
4243
generateCategorySection(category, category.getSectionTitle());
@@ -54,8 +55,18 @@ void pageHeader() {
5455
doc.println("Below are the metrics used to monitor various components of Accumulo.\n");
5556
}
5657

58+
void generateTableOfContents() {
59+
doc.println("## Table of Contents\n");
60+
for (var category : Metric.MetricCategory.values()) {
61+
String sectionId = generateSectionId(category.getSectionTitle());
62+
doc.println("- [" + category.getSectionTitle() + "](#" + sectionId + ")");
63+
}
64+
doc.println();
65+
}
66+
5767
void generateCategorySection(Metric.MetricCategory category, String sectionTitle) {
58-
beginSection(sectionTitle);
68+
String sectionId = generateSectionId(sectionTitle);
69+
beginSection(sectionTitle, sectionId);
5970

6071
// Enable block-level HTML parsing
6172
doc.println("{::options parse_block_html=\"true\" /}");
@@ -70,10 +81,17 @@ void generateCategorySection(Metric.MetricCategory category, String sectionTitle
7081
doc.println("{::options parse_block_html=\"false\" /}\n");
7182
}
7283

73-
void beginSection(String sectionTitle) {
74-
doc.println("\n## " + sectionTitle + "\n");
84+
/**
85+
* Starts a new section in the documentation. In this case a section is a category of metrics.
86+
* Adds an anchor to the section title so we can link to it.
87+
*/
88+
void beginSection(String sectionTitle, String sectionId) {
89+
doc.println("\n## <a id=\"" + sectionId + "\"></a>" + sectionTitle + "\n");
7590
}
7691

92+
/**
93+
* Generates a subsection for a metric. This includes the metric name, type, and description.
94+
*/
7795
void generateMetricSubsection(Metric metric) {
7896
// Open the div block with markdown enabled
7997
doc.println("<div markdown=\"1\" class=\"metric-section\">");
@@ -86,6 +104,14 @@ void generateMetricSubsection(Metric metric) {
86104
doc.println("</div>");
87105
}
88106

107+
/**
108+
* Generates a section ID from a section title. This is used to create anchors for linking to
109+
* sections.
110+
*/
111+
String generateSectionId(String sectionTitle) {
112+
return sectionTitle.toLowerCase().replace(" ", "-").replace(".", "");
113+
}
114+
89115
private MetricsDocGen(PrintStream doc) {
90116
this.doc = doc;
91117
this.sortedMetrics.addAll(Arrays.asList(Metric.values()));

0 commit comments

Comments
 (0)