-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
site: quicker redirects to appease the SEO deities #9116
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7a29487
site: quicker redirects to appease the SEO deities
gtm-nayan 97bae37
minify
gtm-nayan 0860cf3
use null marker in id
gtm-nayan 90da4f2
Update sites/svelte.dev/src/routes/docs/+server.js
gtm-nayan 4e8e4d9
Update sites/svelte.dev/vite.config.js
gtm-nayan 0f9b706
change prefix
gtm-nayan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const prerender = true; | ||
export { GET } from '../docs/+server.js'; | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @ts-expect-error custom suffix doesn't have types | ||
gtm-nayan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import js from 'minified-raw:./redirect.js'; | ||
|
||
// avoid outputting a file named "docs" that would conflict with prerendered "docs" directory | ||
export const prerender = false; | ||
|
||
export function GET() { | ||
return new Response(`<html><head><script>${js}</script></head></html>`, { | ||
headers: { | ||
'content-type': 'text/html' | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** @type {[RegExp, string][]}*/ | ||
const pages_regex_map = [ | ||
// Basic ones | ||
[/(before-we-begin|getting-started)$/i, 'introduction'], | ||
[/template-syntax$/i, 'basic-markup'], | ||
[/component-format$/i, 'svelte-components'], | ||
[/run-time$/i, 'svelte'], | ||
[/compile-time$/i, 'svelte-compiler'], | ||
[/(accessibility-warnings)$/i, '$1'], | ||
|
||
// component-format- | ||
[/component-format-(script|style|script-context-module)$/i, 'svelte-components#$1'], | ||
[/component-format-(script)(?:-?(.*))$/i, 'svelte-components#$1-$2'], | ||
|
||
// template-syntax | ||
[/template-syntax-((?:element|component)-directives)-?(.*)/i, '$1#$2'], | ||
[/template-syntax-slot$/i, 'special-elements#slot'], | ||
[/template-syntax-(slot)-?(.*)/i, 'special-elements#$1-$2'], | ||
[/template-syntax-(if|each|await|key)$/i, 'logic-blocks#$1'], | ||
[/template-syntax-(const|debug|html)$/i, 'special-tags#$1'], | ||
[/template-syntax-(tags|attributes-and-props|text-expressions|comments)$/i, 'basic-markup#$1'], | ||
// !!!! This one should stay at the bottom of `template-syntax`, or it may end up hijacking logic blocks and special tags | ||
[/template-syntax-(.+)/i, 'special-elements#$1'], | ||
|
||
// run-time | ||
[/run-time-(svelte-(?:store|motion|transition|animate))-?(.*)/i, '$1#$2'], | ||
[/run-time-(client-side-component-api)-?(.*)/i, '$1#$2'], | ||
[/run-time-(svelte-easing|server-side-component-api|custom-element-api|svelte-register)$/i, '$1'], | ||
// Catch all, should be at the end or will include store, motion, transition and other modules starting with svelte | ||
[/run-time-(svelte)(?:-(.+))?/i, '$1#$2'], | ||
|
||
// Compile time | ||
[/compile-time-svelte-?(.*)/i, 'svelte-compiler#$1'], | ||
|
||
// Accessibility warnings | ||
[/(accessibility-warnings)-?(.+)/i, '$1#$2'] | ||
]; | ||
|
||
function get_url_to_redirect_to() { | ||
const hash = location.hash.slice(1); | ||
if (!hash) return '/docs/introduction'; | ||
|
||
for (const [regex, replacement] of pages_regex_map) { | ||
if (regex.test(hash)) { | ||
return `/docs/${ | ||
hash | ||
.replace(regex, replacement) | ||
.replace(/#$/, '') // Replace trailing # at the end | ||
.replace('#--', '#') // have to do the -- replacement because of `--style-props` in old being `style-props` in new | ||
}`; | ||
} | ||
} | ||
|
||
// ID doesn't match anything, take the user to intro page only | ||
return '/docs/introduction'; | ||
} | ||
|
||
location.href = new URL(get_url_to_redirect_to(), location.origin).href; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should make
docs.html
return anything. It returns "500 | not found" right now, which is really weird, but we should just fix that to return 404There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to get it to output the same prerendered files as it did before, not sure why it's a 500/404 currently because there is a docs.html in the prerendered output. Some manifest thing maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably sveltejs/kit#10565 will fix the 500/404 thing
https://svelte.dev/docs.html doesn't currently return anything, but would with this PR, so this isn't really making it equivalent to what it was before