Browse Source

Docs: Redirect /pages/ClassName.html to /#ClassName.

Mr.doob 3 months ago
parent
commit
50f79bbaa8
2 changed files with 36 additions and 0 deletions
  1. 18 0
      docs/scripts/page.js
  2. 18 0
      utils/docs/template/static/scripts/page.js

+ 18 - 0
docs/scripts/page.js

@@ -1,3 +1,21 @@
+if ( ! window.frameElement && window.location.protocol !== 'file:' ) {
+
+	// navigates to docs home if direct access, e.g.
+	//   https://threejs.org/docs/pages/BoxGeometry.html
+	// ->https://threejs.org/docs/#BoxGeometry
+
+	const url = new URL( window.location.href );
+
+	// hash route, e.g. #BoxGeometry
+	url.hash = url.pathname.replace( /\/docs\/pages\/(.*?)(?:\.html)?$/, '$1' );
+
+	// docs home, e.g. https://threejs.org/docs/
+	url.pathname = url.pathname.replace( /(\/docs\/).*$/, '$1' );
+
+	window.location.replace( url );
+
+}
+
 // Initialize Highlight.js for syntax highlighting
 if ( typeof hljs !== 'undefined' ) {
 

+ 18 - 0
utils/docs/template/static/scripts/page.js

@@ -1,3 +1,21 @@
+if ( ! window.frameElement && window.location.protocol !== 'file:' ) {
+
+	// navigates to docs home if direct access, e.g.
+	//   https://threejs.org/docs/pages/BoxGeometry.html
+	// ->https://threejs.org/docs/#BoxGeometry
+
+	const url = new URL( window.location.href );
+
+	// hash route, e.g. #BoxGeometry
+	url.hash = url.pathname.replace( /\/docs\/pages\/(.*?)(?:\.html)?$/, '$1' );
+
+	// docs home, e.g. https://threejs.org/docs/
+	url.pathname = url.pathname.replace( /(\/docs\/).*$/, '$1' );
+
+	window.location.replace( url );
+
+}
+
 // Initialize Highlight.js for syntax highlighting
 if ( typeof hljs !== 'undefined' ) {
 

粤ICP备19079148号