@@ -69,15 +69,19 @@ const createMetadata = slugger => {
6969 * @param {HeadingMetadataParent } heading The new heading metadata
7070 */
7171 setHeading : heading => {
72- internalMetadata . heading = heading ;
72+ // We clone the heading to ensure that we don't accidentally override it
73+ // with later mutations below on the `.create` method
74+ internalMetadata . heading = { ...heading } ;
7375 } ,
7476 /**
7577 * Set the Stability Index of a given Metadata
7678 *
7779 * @param {StabilityIndexParent } stability The stability index node to be added
7880 */
7981 addStability : stability => {
80- internalMetadata . stability . children . push ( stability ) ;
82+ // We clone the stability to ensure that we don't accidentally override it
83+ // with later mutations below on the `.create` method
84+ internalMetadata . stability . children . push ( { ...stability } ) ;
8185 } ,
8286 /**
8387 * Set the Metadata (from YAML if exists) properties to the current Metadata entry
@@ -132,7 +136,7 @@ const createMetadata = slugger => {
132136 // a certain navigation section to a page ad the exact point of the page (scroll)
133137 // This is useful for classes, globals and other type of YAML entries, as they reside
134138 // within a module (page) and we want to link to them directly
135- const slugHash = `# ${ slugger . slug ( internalMetadata . heading . text ) } ` ;
139+ const sectionSlug = slugger . slug ( internalMetadata . heading . data . text ) ;
136140
137141 const {
138142 source_link : sourceLink ,
@@ -141,6 +145,9 @@ const createMetadata = slugger => {
141145 tags = [ ] ,
142146 } = internalMetadata . properties ;
143147
148+ // Also add the slug to the heading data as it is used to build the heading
149+ internalMetadata . heading . data . slug = sectionSlug ;
150+
144151 // Defines the toJSON method for the Heading AST node to be converted as JSON
145152 internalMetadata . heading . toJSON = ( ) => internalMetadata . heading . data ;
146153
@@ -153,7 +160,7 @@ const createMetadata = slugger => {
153160 // The API file basename (without the extension)
154161 api : apiDoc . stem ,
155162 // The path/slug of the API section
156- slug : ` ${ apiDoc . stem } .html ${ slugHash } ` ,
163+ slug : sectionSlug ,
157164 // The source link of said API section
158165 sourceLink : sourceLink ,
159166 // The latest updates to an API section
0 commit comments