@@ -24,6 +24,7 @@ import remarkStringify from 'remark-stringify';
24
24
import { unified } from 'unified' ;
25
25
import { remove } from 'unist-util-remove' ;
26
26
27
+ const CACHE_VERSION = 2 ;
27
28
const CACHE_COMPRESS_LEVEL = 4 ;
28
29
const R2_BUCKET = process . env . NEXT_PUBLIC_DEVELOPER_DOCS
29
30
? 'sentry-develop-docs'
@@ -197,7 +198,7 @@ async function genMDFromHTML(source, target, {cacheDir, noCache}) {
197
198
// Remove all script tags, as they are not needed in markdown
198
199
// and they are not stable across builds, causing cache misses
199
200
. 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 ) } ` ;
201
202
const cacheFile = path . join ( cacheDir , cacheKey ) ;
202
203
if ( ! noCache ) {
203
204
try {
@@ -217,8 +218,8 @@ async function genMDFromHTML(source, target, {cacheDir, noCache}) {
217
218
const data = String (
218
219
await unified ( )
219
220
. 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 ) )
222
223
// If we don't do this wrapping, rehypeRemark just returns an empty string -- yeah WTF?
223
224
. use ( ( ) => tree => ( {
224
225
type : 'element' ,
@@ -231,6 +232,19 @@ async function genMDFromHTML(source, target, {cacheDir, noCache}) {
231
232
handlers : {
232
233
// Remove buttons as they usually get confusing in markdown, especially since we use them as tab headers
233
234
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
+ } ) ,
234
248
} ,
235
249
} )
236
250
// We end up with empty inline code blocks, probably from some tab logic in the HTML, remove them
0 commit comments