@@ -24,6 +24,7 @@ import remarkStringify from 'remark-stringify';
2424import { unified } from 'unified' ;
2525import { remove } from 'unist-util-remove' ;
2626
27+ const CACHE_VERSION = 2 ;
2728const CACHE_COMPRESS_LEVEL = 4 ;
2829const R2_BUCKET = process . env . NEXT_PUBLIC_DEVELOPER_DOCS
2930 ? 'sentry-develop-docs'
@@ -197,7 +198,7 @@ async function genMDFromHTML(source, target, {cacheDir, noCache}) {
197198 // Remove all script tags, as they are not needed in markdown
198199 // and they are not stable across builds, causing cache misses
199200 . replace ( / < s c r i p t [ ^ > ] * > [ \s \S ] * ?< \/ s c r i p t > / gi, '' ) ;
200- const cacheKey = md5 ( leanHTML ) ;
201+ const cacheKey = `v ${ CACHE_VERSION } _ ${ md5 ( leanHTML ) } ` ;
201202 const cacheFile = path . join ( cacheDir , cacheKey ) ;
202203 if ( ! noCache ) {
203204 try {
@@ -217,8 +218,8 @@ async function genMDFromHTML(source, target, {cacheDir, noCache}) {
217218 const data = String (
218219 await unified ( )
219220 . use ( rehypeParse )
220- // Need the `main div > hgroup ` selector for the headers
221- . use ( ( ) => tree => selectAll ( 'main div > hgroup , div#main' , tree ) )
221+ // Need the `head > title ` selector for the headers
222+ . use ( ( ) => tree => selectAll ( 'head > title , div#main' , tree ) )
222223 // If we don't do this wrapping, rehypeRemark just returns an empty string -- yeah WTF?
223224 . use ( ( ) => tree => ( {
224225 type : 'element' ,
@@ -231,6 +232,19 @@ async function genMDFromHTML(source, target, {cacheDir, noCache}) {
231232 handlers : {
232233 // Remove buttons as they usually get confusing in markdown, especially since we use them as tab headers
233234 button ( ) { } ,
235+ // Convert the title to the top level heading
236+ // This is needed because the HTML title tag is not part of the main content
237+ // and we want to have a top level heading in the markdown
238+ title : ( _state , node ) => ( {
239+ type : 'heading' ,
240+ depth : 1 ,
241+ children : [
242+ {
243+ type : 'text' ,
244+ value : node . children [ 0 ] . value ,
245+ } ,
246+ ] ,
247+ } ) ,
234248 } ,
235249 } )
236250 // We end up with empty inline code blocks, probably from some tab logic in the HTML, remove them
0 commit comments