echonesis commented on code in PR #297:
URL: https://github.com/apache/ozone-site/pull/297#discussion_r2744943756
##########
docusaurus.config.js:
##########
@@ -112,6 +112,59 @@ const config = {
return result;
},
+ /*
+ Validate internal markdown links to ensure they don't contain number
prefixes or file extensions.
+ These can break when the ordering or format of the target page is updated.
+ Docusaurus can resolve links without these.
+ See https://docusaurus.io/docs/api/docusaurus-config#markdown for
reference.
+ */
+ preprocessor: (/** @type {{filePath: string, fileContent: string}} */
params) => {
+ const {filePath, fileContent} = params;
+
+ // Validate internal links format
+ const internalLinkPattern = /\[([^\]]+)\]\(([^)]+\.md(?:#[^)]+)?)\)/g;
+ const numberPrefixPattern = /\/\d{2}-[^/]+/;
+
+ let matches;
+ const invalidLinks = [];
+
+ while ((matches = internalLinkPattern.exec(fileContent)) !== null) {
+ const linkText = matches[1];
+ const linkPath = matches[2];
+
+ // Skip external links (http://, https://, mailto:, etc.)
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(linkPath)) {
+ continue;
+ }
+
+ // Skip absolute paths from site root (starting with /)
+ if (linkPath.startsWith('/')) {
+ continue;
+ }
+
+ // Check for number prefixes or .md extensions
+ if (numberPrefixPattern.test(linkPath) || linkPath.includes('.md')) {
Review Comment:
Thanks for pointing this out!
I will remove it in the next commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]