Skip to content

Commit e25dc4b

Browse files
committed
Replace scripts/replace.js with a Docusaurus markdown preprocessor
Move the @Pulsar:...@ token expansion and the {@Inject:...} link expansion out of a standalone post-processing script / inline config block into two focused preprocessor modules under src/server/markdownPreprocessors/. The new pulsarVariables preprocessor scopes itself by filePath to docs/ and versioned_docs/version-*/, preserving the exact scope of the old script while making replacements visible during `yarn start` (previously only applied in CI). Computed version/URL helpers are centralized in src/config/pulsarVariables.ts so React components can consume them directly without needing a separate replacement pass. Drops the replace-in-file dependency and the node invocation from site_builder.py. Also adds @Pulsar:version:adapters@. BUILD_ALL_VERSION=1
1 parent 4213953 commit e25dc4b

13 files changed

Lines changed: 333 additions & 475 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ After committing the changes for the `docs` directory, you can use the `docs-too
3333
./scripts/docs-tool.sh apply_changes_to_versioned_docs
3434
```
3535

36+
## Markdown placeholders
37+
38+
Markdown files under `docs/` and `versioned_docs/version-*/` are run through
39+
two preprocessors at build time:
40+
41+
- `@pulsar:version@`, `@pulsar:rpm:client@`, `@pulsar:apidoc:python@`, etc. —
42+
version-aware tokens. The values come from `versions.json`, `site-baseurls.js`,
43+
and `data/release-*.js`. See `src/config/pulsarVariables.ts` for the full list.
44+
- `{@inject:javadoc:Name:org/...}`, `{@inject:endpoint|GET|/admin/...}` — link
45+
expansion for Javadoc, GitHub, REST endpoints. See
46+
`src/server/markdownPreprocessors/inject.ts`.
47+
48+
To reference the same values from React components, import from
49+
`@site/src/config/pulsarVariables` — no placeholder is needed in `.js`/`.tsx`.
50+
3651
## More information
3752

3853
* [Pulsar Website contribution guide](https://pulsar.apache.org/contribute/site-intro/)

docs/reference-configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ title: Pulsar Configuration
44
sidebar_label: "Pulsar Configuration"
55
---
66

7-
For a complete list of Pulsar configuration, visit the [Pulsar Reference](pathname:///reference/#/@pulsar:version_reference@/) website.
7+
For a complete list of Pulsar configuration, visit the <a href="pathname:///reference/#/@pulsar:version_reference@/" target="_blank" rel="noopener noreferrer">Pulsar Reference</a> website.

docusaurus.config.ts

Lines changed: 7 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -28,99 +28,15 @@ try {
2828
}
2929

3030
const {
31-
siteUrl,
32-
javadocUrl,
33-
restApiUrl,
34-
functionsApiUrl,
35-
sourceApiUrl,
36-
sinkApiUrl,
37-
packagesApiUrl,
38-
transactionsApiUrl,
39-
lookupApiUrl,
40-
githubUrl,
4131
githubSiteUrl,
4232
baseUrl,
43-
restApiBaseUrlMapping
33+
restApiBaseUrlMapping,
4434
} = require("./site-baseurls");
4535

46-
const injectLinkParse = (prefix, name, path) => {
47-
if (prefix == "javadoc") {
48-
return {
49-
link: javadocUrl + path,
50-
text: name,
51-
};
52-
} else if (prefix == "github") {
53-
return {
54-
link: githubUrl + "/tree/master/" + path,
55-
text: name,
56-
};
57-
} else if (prefix == "rest") {
58-
return {
59-
link: restApiUrl + "#" + path,
60-
text: name,
61-
};
62-
} else if (prefix == "functions") {
63-
return {
64-
link: functionsApiUrl + "#" + path,
65-
text: name,
66-
};
67-
} else if (prefix == "source") {
68-
return {
69-
link: sourceApiUrl + "#" + path,
70-
text: name,
71-
};
72-
} else if (prefix == "sink") {
73-
return {
74-
link: sinkApiUrl + "#" + path,
75-
text: name,
76-
};
77-
} else if (prefix == "packages") {
78-
return {
79-
link: packagesApiUrl + "#" + path,
80-
text: name,
81-
};
82-
}
83-
84-
return {
85-
link: path,
86-
text: name,
87-
};
88-
};
89-
90-
const injectLinkParseForEndpoint = (info) => {
91-
let [method, path, suffix] = info.split("|");
92-
93-
if (!suffix) {
94-
suffix = "";
95-
}
96-
97-
let restPath = path.split("/");
98-
const restApiVersion = restPath[2];
99-
const restApiType = restPath[3];
100-
const restBaseUrl = restApiBaseUrlMapping[restApiType] || restApiUrl;
101-
102-
let restUrl;
103-
if (suffix.indexOf("?version=") >= 0) {
104-
const suffixAndVersion = suffix.split("?version=")
105-
restUrl = "version=" + suffixAndVersion[1] + "&apiversion=" + restApiVersion + "#" + suffixAndVersion[0];
106-
if (suffixAndVersion[0].startsWith("operation/")) {
107-
path += suffixAndVersion[0].slice("operation".length)
108-
}
109-
} else {
110-
restUrl = "version=master&apiversion=" + restApiVersion + "#" + suffix;
111-
if (suffix.startsWith("operation/")) {
112-
path += suffix.slice("operation".length)
113-
}
114-
}
115-
116-
return {
117-
text: method + " " + path,
118-
link: restBaseUrl + "?" + restUrl,
119-
};
120-
};
121-
12236
/** @type {import('@docusaurus/types').Config} */
12337
module.exports = async function createConfigAsync() {
38+
const injectPreprocessor = (await import("./src/server/markdownPreprocessors/inject")).default;
39+
const pulsarVariablesPreprocessor = (await import("./src/server/markdownPreprocessors/pulsarVariables")).default;
12440
return {
12541
future: {
12642
faster: {
@@ -147,21 +63,10 @@ module.exports = async function createConfigAsync() {
14763
hooks: {
14864
onBrokenMarkdownLinks: "warn",
14965
},
150-
preprocessor: ({ filePath, fileContent }) => {
151-
return fileContent.replaceAll(/{@inject:([^}]+)}/g, (_, p1) => {
152-
const p1Trimmed = p1.trim();
153-
const endpointPrefix = 'endpoint|';
154-
let link, text;
155-
if (p1Trimmed.startsWith(endpointPrefix)) {
156-
// @ts-ignore
157-
({ link, text } = injectLinkParseForEndpoint(p1Trimmed.substring(endpointPrefix.length)));
158-
} else {
159-
const [prefix, name, path] = p1Trimmed.split(':');
160-
({ link, text } = injectLinkParse(prefix, name, path));
161-
}
162-
return `[${text}](${link})`; // Format as a markdown link
163-
});
164-
},
66+
preprocessor: (args) => injectPreprocessor({
67+
...args,
68+
fileContent: pulsarVariablesPreprocessor(args),
69+
}),
16570
},
16671
themes: ['@docusaurus/theme-mermaid'],
16772
themeConfig:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"react-svg": "^16.1.34",
6161
"rehype-katex": "^7.0.1",
6262
"remark-math": "^6.0.0",
63-
"replace-in-file": "6.3.2",
6463
"search-insights": "^2.17.3",
6564
"semver": "^7.7.4",
6665
"sine-waves": "^0.3.0",

0 commit comments

Comments
 (0)