Skip to content

Commit 6146863

Browse files
Implement ConfigOptionsDocGenerator to automate MDX config tables"
1 parent 4223026 commit 6146863

8 files changed

Lines changed: 366 additions & 3193 deletions

File tree

fluss-docgen/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ The `ConfigOptionsDocGenerator` scans the `ConfigOptions` class and generates an
1010
1. It uses reflection to find all `ConfigOption` fields in the `ConfigOptions` class.
1111
2. It groups options into sections based on the `@ConfigSection` annotation or key prefixes.
1212
3. It handles special default value formatting via `@ConfigOverrideDefault`.
13-
4. It outputs an MDX file (config_reference.mdx) using React-compatible HTML table syntax.
13+
4. It outputs an MDX partial file (`_partial_config.mdx`) to the `website/docs/_configs/` directory for direct import into the Docusaurus site.
1414

1515
### Running the Generator
1616

1717
To update the configuration documentation, run the following command from the project root:
1818

1919
```bash
20-
./mvnw compile -pl fluss-docgen -am && ./mvnw exec:java -pl fluss-docgen -Dexec.mainClass="org.apache.fluss.docs.ConfigOptionsDocGenerator"
20+
./mvnw compile -pl fluss-docgen -am
21+
````
22+
23+
## Integration with Website
24+
25+
The generated file is stored in `website/docs/_configs/_partial_config.mdx`. To display these tables in the documentation, use the MDX import syntax in any `.md` or `.mdx` file:
26+
27+
```markdown
28+
import PartialConfig from '../_configs/_partial_config.mdx';
29+
<PartialConfig></PartialConfig>

fluss-docgen/src/main/java/org/apache/fluss/docs/ConfigOptionsDocGenerator.java

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
public class ConfigOptionsDocGenerator {
3939

4040
public static void main(String[] args) throws Exception {
41-
Path projectRoot = findProjectRoot();
42-
File outputFile =
43-
projectRoot.resolve("website/docs/maintenance/config_reference.mdx").toFile();
41+
Path root = findProjectRoot();
42+
String projectRoot = (root != null) ? root.toString() : System.getProperty("user.dir");
43+
String outputPath = projectRoot + "/website/docs/_configs/_partial_config.mdx";
44+
45+
File outputFile = new File(outputPath);
46+
outputFile.getParentFile().mkdirs();
4447

4548
System.out.println("Generating MDX partial: " + outputFile.getAbsolutePath());
4649

@@ -62,7 +65,6 @@ private static String generateMDXContent() throws IllegalAccessException {
6265
Field[] fields = ConfigOptions.class.getDeclaredFields();
6366
Map<String, List<Field>> sections = new TreeMap<>();
6467

65-
// 1. Group the fields first
6668
for (Field field : fields) {
6769
if (field.getType().equals(ConfigOption.class)) {
6870
String section = "Common";
@@ -79,16 +81,11 @@ private static String generateMDXContent() throws IllegalAccessException {
7981
}
8082
}
8183

82-
// 2. Generate the HTML for each section
8384
for (Map.Entry<String, List<Field>> entry : sections.entrySet()) {
8485
builder.append("## ").append(entry.getKey()).append(" Configurations\n\n");
85-
builder.append("<table class=\"configuration-table\">\n")
86-
.append(" <thead>\n <tr>\n")
87-
.append(" <th style={{width: '25%'}}>Key</th>\n")
88-
.append(" <th style={{width: '15%'}}>Default</th>\n")
89-
.append(" <th style={{width: '15%'}}>Type</th>\n")
90-
.append(" <th style={{width: '45%'}}>Description</th>\n")
91-
.append(" </tr>\n </thead>\n <tbody>\n");
86+
87+
builder.append("| Key | Default | Type | Description |\n");
88+
builder.append("| :--- | :--- | :--- | :--- |\n");
9289

9390
for (Field field : entry.getValue()) {
9491
ConfigOption<?> option = (ConfigOption<?>) field.get(null);
@@ -98,37 +95,29 @@ private static String generateMDXContent() throws IllegalAccessException {
9895
defaultValue = field.getAnnotation(ConfigOverrideDefault.class).value();
9996
}
10097

101-
// ESCAPE DESCRIPTION: Crucial for MDX/React rendering success
102-
// We escape <, >, {, and } which are special JSX characters
98+
// IMPORTANT: MDX hates unescaped < or { symbols in text
10399
String description =
104100
option.description()
105-
.replace("<", "&lt;")
106-
.replace(">", "&gt;")
107-
.replace("{", "&#123;")
108-
.replace("}", "&#125;")
101+
.replace("\n", " ")
102+
.replace("\r", " ")
103+
.replace("|", "\\|")
104+
.replace("<", "&lt;") // Escape for MDX
105+
.replace("{", "&#123;") // Escape for MDX
106+
.replace("}", "&#125;") // Escape for MDX
109107
.replace("%s", "");
110108

111-
builder.append(" <tr>\n")
112-
.append(" <td><code>")
109+
builder.append("| `")
113110
.append(option.key())
114-
.append("</code></td>\n")
115-
.append(" <td><code>")
111+
.append("` | `")
116112
.append(defaultValue.replace("<", "&lt;"))
117-
.append("</code></td>\n")
118-
.append(" <td>")
113+
.append("` | ")
119114
.append(getType(option))
120-
.append("</td>\n")
121-
.append(" <td>")
115+
.append(" | ")
122116
.append(description)
123-
.append("</td>\n")
124-
.append(" </tr>\n");
117+
.append(" |\n");
125118
}
126-
builder.append(" </tbody>\n</table>\n\n");
119+
builder.append("\n");
127120
}
128-
129-
// Mandatory export for MDX partials to render correctly in Docusaurus
130-
builder.append("export default ({children}) => <>{children}</>;\n");
131-
132121
return builder.toString();
133122
}
134123

fluss-docgen/src/test/java/org/apache/fluss/docs/ConfigOptionsDocGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void testGeneratorRunsSuccessfully() throws Exception {
3131
ConfigOptionsDocGenerator.main(new String[] {});
3232

3333
// Verify the file was actually created
34-
File generatedFile = new File("website/docs/maintenance/config_reference.mdx");
34+
File generatedFile = new File("website/docs/_configs/_partial_config.mdx");
3535
assertThat(generatedFile).exists();
3636
}
3737
}

0 commit comments

Comments
 (0)