File tree 1 file changed +6
-5
lines changed
quartz/components/scripts
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -4,18 +4,19 @@ function getRandomInt(max: number) {
4
4
return Math . floor ( Math . random ( ) * max ) ;
5
5
}
6
6
7
+ function isValidUrl ( newSlug : string , oldSlug : String ) {
8
+ return oldSlug !== newSlug && ! newSlug . includes ( "/contributing/" )
9
+ }
10
+
7
11
async function navigateToRandomPage ( ) {
8
12
const fullSlug = getFullSlug ( window )
9
13
const data = await fetchData
10
14
const allPosts = Object . keys ( data ) . map ( ( slug ) => simplifySlug ( slug as FullSlug ) )
11
15
// window.location.href = `${pathToRoot(fullSlug)}/${allPosts[getRandomInt(allPosts.length - 1)]}`
12
16
let newSlug = `${ pathToRoot ( fullSlug ) } /${ allPosts [ getRandomInt ( allPosts . length - 1 ) ] } ` ;
13
17
14
- if ( newSlug === fullSlug ) {
15
- // Generate a new random slug until it's different from the starting fullSlug
16
- do {
17
- newSlug = `${ pathToRoot ( fullSlug ) } /${ allPosts [ getRandomInt ( allPosts . length - 1 ) ] } ` ;
18
- } while ( newSlug === fullSlug ) ;
18
+ while ( ! isValidUrl ( newSlug , fullSlug ) ) {
19
+ newSlug = `${ pathToRoot ( fullSlug ) } /${ allPosts [ getRandomInt ( allPosts . length - 1 ) ] } ` ;
19
20
}
20
21
window . location . href = newSlug ;
21
22
}
You can’t perform that action at this time.
0 commit comments