Przeglądaj źródła

feat(docs): Strip JSDoc tags from graphql comments

Michael Bromley 6 lat temu
rodzic
commit
a86d48f7c6
1 zmienionych plików z 15 dodań i 2 usunięć
  1. 15 2
      scripts/docs/generate-graphql-docs.ts

+ 15 - 2
scripts/docs/generate-graphql-docs.ts

@@ -127,8 +127,21 @@ function generateGraphqlDocs(hugoOutputPath: string) {
 /**
  * Renders the type description if it exists.
  */
-function renderDescription(type: { description?: string | null }, appendNewlines = true): string {
-    return type.description ? `${type.description + (appendNewlines ? '\n\n' : '')}` : '';
+function renderDescription(type: { description?: string | null }): string {
+    if (!type.description) {
+        return '';
+    }
+    // Strip any JSDoc tags which may be used to annotate the generated
+    // TS types.
+    const stringsToStrip = [
+        /@docsCategory\s+[^\n]+/g,
+        /@description\s+/g,
+    ];
+    let result = type.description;
+    for (const pattern of stringsToStrip) {
+        result = result.replace(pattern, '');
+    }
+    return result + '\n\n';
 }
 
 function renderFields(