File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 arrayBufferViewTypes ,
1313} from "./helpers.js" ;
1414import { collectLegacyNamespaceTypes } from "./legacy-namespace.js" ;
15+ import { extractSummaryFromFile } from "./mdn-comments.js" ;
1516
1617/// Decide which members of a function to emit
1718enum EmitScope {
@@ -906,7 +907,10 @@ export function emitWebIdl(
906907 comments . push ( "Available only in secure contexts." ) ;
907908 }
908909 if ( entity . mdnUrl ) {
909- if ( comments . length > 0 ) comments . push ( "" ) ;
910+ if ( comments . length == 0 ) {
911+ comments . push ( extractSummaryFromFile ( entity . mdnUrl ) ) ;
912+ }
913+ comments . push ( "" ) ;
910914 comments . push ( `[MDN Reference](${ entity . mdnUrl } )` ) ;
911915 }
912916
Original file line number Diff line number Diff line change @@ -107,3 +107,25 @@ export function generateDescriptions(): Record<string, string> {
107107
108108 return { } ;
109109}
110+
111+ export function extractSummaryFromFile ( url : string ) : string {
112+ const relativePath = url
113+ . replace ( "https://developer.mozilla.org/docs/" , "" )
114+ . toLowerCase ( ) ;
115+
116+ const filePath = new URL (
117+ `../../inputfiles/mdn/files/en-us/${ relativePath } /index.md` ,
118+ import . meta. url ,
119+ ) ;
120+
121+ try {
122+ const content = fs . readFileSync ( filePath , "utf-8" ) ;
123+ return extractSummary ( content ) ;
124+ } catch ( error ) {
125+ console . error (
126+ `Failed to read or extract summary from: ${ filePath . href } ` ,
127+ error ,
128+ ) ;
129+ return "" ;
130+ }
131+ }
You can’t perform that action at this time.
0 commit comments