Skip to content

Commit 9178da5

Browse files
authored
New Docs: Updated templates with old design. (#32002)
* New Docs: Updated templates with old design. * New Docs: Remove (nullable) from methods that return null. * New Docs: Improved parameters table. * New Docs: Removed unused code from templates. * New Docs: Fixed h2/h3 in dark mode. * New Docs: Fixed Import. * New Docs: Fixed navigation scroll resetting.
1 parent 758b654 commit 9178da5

File tree

10 files changed

+230
-375
lines changed

10 files changed

+230
-375
lines changed

utils/docs/template/publish.js

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,20 @@ function updateItemName( item ) {
106106

107107
function addParamAttributes( params ) {
108108

109-
return params.filter( ( { name } ) => name && ! name.includes( '.' ) ).map( updateItemName );
109+
return params.filter( ( { name } ) => name && ! name.includes( '.' ) ).map( param => {
110+
111+
let itemName = updateItemName( param );
112+
113+
if ( param.type && param.type.names && param.type.names.length ) {
114+
115+
const escapedTypes = param.type.names.map( name => htmlsafe( name ) );
116+
itemName += ' : <span class="param-type">' + escapedTypes.join( ' | ' ) + '</span>';
117+
118+
}
119+
120+
return itemName;
121+
122+
} );
110123

111124
}
112125

@@ -182,41 +195,16 @@ function addSignatureParams( f ) {
182195

183196
const params = f.params ? addParamAttributes( f.params ) : [];
184197

185-
f.signature = util.format( '%s(%s)', ( f.signature || '' ), params.join( ', ' ) );
198+
f.signature = util.format( '%s( %s )', ( f.signature || '' ), params.join( ', ' ) );
186199

187200
}
188201

189202
function addSignatureReturns( f ) {
190203

191-
const attribs = [];
192-
let attribsString = '';
193204
let returnTypes = [];
194205
let returnTypesString = '';
195206
const source = f.yields || f.returns;
196207

197-
// jam all the return-type attributes into an array. this could create odd results (for example,
198-
// if there are both nullable and non-nullable return types), but let's assume that most people
199-
// who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
200-
if ( source ) {
201-
202-
source.forEach( item => {
203-
204-
helper.getAttribs( item ).forEach( attrib => {
205-
206-
if ( ! attribs.includes( attrib ) ) {
207-
208-
attribs.push( attrib );
209-
210-
}
211-
212-
} );
213-
214-
} );
215-
216-
attribsString = buildAttribsString( attribs );
217-
218-
}
219-
220208
if ( source ) {
221209

222210
returnTypes = addNonParamAttributes( source );
@@ -225,7 +213,7 @@ function addSignatureReturns( f ) {
225213

226214
if ( returnTypes.length ) {
227215

228-
returnTypesString = util.format( ' &rarr; %s{%s}', attribsString, returnTypes.join( '|' ) );
216+
returnTypesString = util.format( ' : %s', returnTypes.join( ' | ' ) );
229217

230218
}
231219

@@ -237,13 +225,13 @@ function addSignatureTypes( f ) {
237225

238226
const types = f.type ? buildItemTypeStrings( f ) : [];
239227

240-
f.signature = `${f.signature || ''}<span class="type-signature">${types.length ? ` :${types.join( '|' )}` : ''}</span>`;
228+
f.signature = `${f.signature || ''}<span class="type-signature">${types.length ? ` : ${types.join( ' | ' )}` : ''}</span>`;
241229

242230
}
243231

244232
function addAttribs( f ) {
245233

246-
const attribs = helper.getAttribs( f );
234+
const attribs = helper.getAttribs( f ).filter( attrib => attrib !== 'static' );
247235
const attribsString = buildAttribsString( attribs );
248236

249237
f.attribs = util.format( '<span class="type-signature">%s</span>', attribsString );
@@ -287,7 +275,8 @@ function generate( title, docs, filename, resolveLinks ) {
287275
const docData = {
288276
env: env,
289277
title: title,
290-
docs: docs
278+
docs: docs,
279+
augments: docs && docs[0] ? docs[0].augments : null
291280
};
292281

293282
const outpath = path.join( outdir, filename );

utils/docs/template/static/scripts/page.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,42 @@
4242

4343
( function loadNavigation() {
4444

45-
const navContainer = document.querySelector( '#content nav' );
45+
const content = document.getElementById( 'content' );
46+
const navContainer = content.querySelector( 'nav' );
4647

47-
if ( navContainer ) {
48+
fetch( 'nav.html' )
49+
.then( response => response.text() )
50+
.then( html => {
4851

49-
fetch( 'nav.html' )
50-
.then( response => response.text() )
51-
.then( html => {
52+
navContainer.innerHTML = html;
5253

53-
navContainer.innerHTML = html;
54+
const savedScrollTop = sessionStorage.getItem( 'navScrollTop' );
5455

55-
} )
56-
.catch( err => console.error( 'Failed to load navigation:', err ) );
56+
if ( savedScrollTop !== null ) {
5757

58-
}
58+
content.scrollTop = parseInt( savedScrollTop, 10 );
59+
60+
}
61+
62+
// Save scroll position when clicking nav links
63+
navContainer.addEventListener( 'click', function ( event ) {
64+
65+
const link = event.target.closest( 'a' );
66+
67+
if ( link ) {
68+
69+
sessionStorage.setItem( 'navScrollTop', content.scrollTop );
70+
71+
}
72+
73+
} );
74+
75+
updateNavigation();
76+
77+
sessionStorage.removeItem( 'navScrollTop' );
78+
79+
} )
80+
.catch( err => console.error( 'Failed to load navigation:', err ) );
5981

6082
} )();
6183

@@ -163,7 +185,6 @@ clearSearchButton.onclick = function () {
163185

164186
//
165187

166-
window.addEventListener( 'DOMContentLoaded', updateNavigation );
167188
window.addEventListener( 'hashchange', updateNavigation );
168189

169190
function updateNavigation() {
@@ -194,7 +215,14 @@ function updateNavigation() {
194215

195216
if ( aElement !== null ) {
196217

197-
aElement.scrollIntoView( { block: 'center' } );
218+
const savedScrollTop = sessionStorage.getItem( 'navScrollTop' );
219+
220+
if ( savedScrollTop === null ) {
221+
222+
aElement.scrollIntoView( { block: 'center' } );
223+
224+
}
225+
198226
aElement.classList.add( 'selected' );
199227

200228
}

0 commit comments

Comments
 (0)