mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
201a0eb2f6 | ||
|
|
4f0ab31049 | ||
|
|
d97efda10b |
@@ -121,7 +121,7 @@ export function select_target(url: URL): Target {
|
|||||||
const part = route.parts[route.parts.length - 1];
|
const part = route.parts[route.parts.length - 1];
|
||||||
const params = part.params ? part.params(match) : {};
|
const params = part.params ? part.params(match) : {};
|
||||||
|
|
||||||
const page = { host: location.host, path, query, params };
|
const page = { path, query, params };
|
||||||
|
|
||||||
return { href: url.href, route, match, page };
|
return { href: url.href, route, match, page };
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ export function select_target(url: URL): Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function handle_error(url: URL) {
|
export function handle_error(url: URL) {
|
||||||
const { host, pathname, search } = location;
|
const { pathname, search } = location;
|
||||||
const { session, preloaded, status, error } = initial_data;
|
const { session, preloaded, status, error } = initial_data;
|
||||||
|
|
||||||
if (!root_preloaded) {
|
if (!root_preloaded) {
|
||||||
@@ -154,7 +154,7 @@ export function handle_error(url: URL) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
const query = extract_query(search);
|
const query = extract_query(search);
|
||||||
render(null, [], props, { host, path: pathname, query, params: {} });
|
render(null, [], props, { path: pathname, query, params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scroll_state() {
|
export function scroll_state() {
|
||||||
@@ -301,7 +301,6 @@ export async function hydrate_target(target: Target): Promise<{
|
|||||||
|
|
||||||
if (!root_preloaded) {
|
if (!root_preloaded) {
|
||||||
root_preloaded = initial_data.preloaded[0] || root_preload.call(preload_context, {
|
root_preloaded = initial_data.preloaded[0] || root_preload.call(preload_context, {
|
||||||
host: page.host,
|
|
||||||
path: page.path,
|
path: page.path,
|
||||||
query: page.query,
|
query: page.query,
|
||||||
params: {}
|
params: {}
|
||||||
@@ -339,7 +338,6 @@ export async function hydrate_target(target: Target): Promise<{
|
|||||||
if (ready || !initial_data.preloaded[i + 1]) {
|
if (ready || !initial_data.preloaded[i + 1]) {
|
||||||
preloaded = preload
|
preloaded = preload
|
||||||
? await preload.call(preload_context, {
|
? await preload.call(preload_context, {
|
||||||
host: page.host,
|
|
||||||
path: page.path,
|
path: page.path,
|
||||||
query: page.query,
|
query: page.query,
|
||||||
params: part.params ? part.params(target.match) : {}
|
params: part.params ? part.params(target.match) : {}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ export type Redirect = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Page = {
|
export type Page = {
|
||||||
host: string;
|
|
||||||
path: string;
|
path: string;
|
||||||
params: Record<string, string>;
|
params: Record<string, string>;
|
||||||
query: Record<string, string | string[]>;
|
query: Record<string, string | string[]>;
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ export function get_page_handler(
|
|||||||
try {
|
try {
|
||||||
const root_preloaded = manifest.root_preload
|
const root_preloaded = manifest.root_preload
|
||||||
? manifest.root_preload.call(preload_context, {
|
? manifest.root_preload.call(preload_context, {
|
||||||
host: req.headers.host,
|
|
||||||
path: req.path,
|
path: req.path,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
params: {}
|
params: {}
|
||||||
@@ -169,7 +168,6 @@ export function get_page_handler(
|
|||||||
|
|
||||||
return part.preload
|
return part.preload
|
||||||
? part.preload.call(preload_context, {
|
? part.preload.call(preload_context, {
|
||||||
host: req.headers.host,
|
|
||||||
path: req.path,
|
path: req.path,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
params
|
params
|
||||||
@@ -220,7 +218,6 @@ export function get_page_handler(
|
|||||||
stores: {
|
stores: {
|
||||||
page: {
|
page: {
|
||||||
subscribe: writable({
|
subscribe: writable({
|
||||||
host: req.headers.host,
|
|
||||||
path: req.path,
|
path: req.path,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
params
|
params
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ It lives in a `context="module"` script — see the [tutorial](https://svelte.de
|
|||||||
|
|
||||||
The `preload` function receives two arguments — `page` and `session`.
|
The `preload` function receives two arguments — `page` and `session`.
|
||||||
|
|
||||||
`page` is a `{ host, path, params, query }` object where `host` is the URL's host, `path` is its pathname, `params` is derived from `path` and the route filename, and `query` is an object of values in the query string.
|
`page` is a `{ path, params, query }` object where `path` is the URL's pathname, `params` is derived from `path` and the route filename, and `query` is an object of values in the query string.
|
||||||
|
|
||||||
So if the example above was `src/routes/blog/[slug].svelte` and the URL was `/blog/some-post?foo=bar&baz`, the following would be true:
|
So if the example above was `src/routes/blog/[slug].svelte` and the URL was `/blog/some-post?foo=bar&baz`, the following would be true:
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Inside a component, get references to the stores like so:
|
|||||||
```
|
```
|
||||||
|
|
||||||
* `preloading` contains a readonly boolean value, indicating whether or not a navigation is pending
|
* `preloading` contains a readonly boolean value, indicating whether or not a navigation is pending
|
||||||
* `page` contains a readonly `{ host, path, params, query }` object, identical to that passed to `preload` functions
|
* `page` contains a readonly `{ path, params, query }` object, identical to that passed to `preload` functions
|
||||||
* `session` contains whatever data was seeded on the server. It is a [writable store](https://svelte.dev/tutorial/writable-stores), meaning you can update it with new data (for example, after the user logs in) and your app will be refreshed
|
* `session` contains whatever data was seeded on the server. It is a [writable store](https://svelte.dev/tutorial/writable-stores), meaning you can update it with new data (for example, after the user logs in) and your app will be refreshed
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
site/package-lock.json
generated
6
site/package-lock.json
generated
@@ -846,9 +846,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@sveltejs/site-kit": {
|
"@sveltejs/site-kit": {
|
||||||
"version": "1.0.4",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.1.1.tgz",
|
||||||
"integrity": "sha512-BaQhIL1iPhCF+iDXfy9psDvRdFzfyMPkWnoZHfVz+INpHsU2aJmRZOPl9rykXmPyiPo+AwTTNK5vjIvmtwHLPQ==",
|
"integrity": "sha512-EYQKhrdbRWeaPteTN1YZ4oW0xBbUzQ2D+XPdIfEvwDvgxAka9KZP5BCiENrXFf7Z9lxe2HW6MDlrT2sMwoS8+g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@sindresorhus/slugify": "^0.9.1",
|
"@sindresorhus/slugify": "^0.9.1",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
"@babel/plugin-transform-runtime": "^7.4.4",
|
"@babel/plugin-transform-runtime": "^7.4.4",
|
||||||
"@babel/preset-env": "^7.4.4",
|
"@babel/preset-env": "^7.4.4",
|
||||||
"@babel/runtime": "^7.4.4",
|
"@babel/runtime": "^7.4.4",
|
||||||
"@sveltejs/site-kit": "^1.0.4",
|
"@sveltejs/site-kit": "^1.1.1",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"rollup": "^1.11.3",
|
"rollup": "^1.11.3",
|
||||||
"rollup-plugin-babel": "^4.3.2",
|
"rollup-plugin-babel": "^4.3.2",
|
||||||
|
|||||||
@@ -19,4 +19,4 @@
|
|||||||
<meta name="Description" content="The next small thing in web development">
|
<meta name="Description" content="The next small thing in web development">
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Docs {sections}/>
|
<Docs {sections} project="sapper"/>
|
||||||
|
|||||||
@@ -19,4 +19,4 @@
|
|||||||
<meta name="Description" content="The next small thing in web development">
|
<meta name="Description" content="The next small thing in web development">
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Docs {sections}/>
|
<Docs {sections} project="sapper" dir="migrating"/>
|
||||||
|
|||||||
@@ -7,23 +7,6 @@ import { make_session_slug_processor } from '@sveltejs/site-kit/utils/slug';
|
|||||||
import marked from 'marked';
|
import marked from 'marked';
|
||||||
import hljs from 'highlight.js';
|
import hljs from 'highlight.js';
|
||||||
|
|
||||||
const escaped = {
|
|
||||||
'"': '"',
|
|
||||||
"'": ''',
|
|
||||||
'&': '&',
|
|
||||||
'<': '<',
|
|
||||||
'>': '>',
|
|
||||||
};
|
|
||||||
|
|
||||||
const unescaped = Object.keys(escaped).reduce(
|
|
||||||
(unescaped, key) => ((unescaped[escaped[key]] = key), unescaped),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
function unescape(str) {
|
|
||||||
return String(str).replace(/&.+?;/g, match => unescaped[match] || match);
|
|
||||||
}
|
|
||||||
|
|
||||||
const block_types = [
|
const block_types = [
|
||||||
'blockquote',
|
'blockquote',
|
||||||
'html',
|
'html',
|
||||||
@@ -115,15 +98,13 @@ export default function generate_docs(dir) {
|
|||||||
const slug = level <= 4 && make_slug(rawtext);
|
const slug = level <= 4 && make_slug(rawtext);
|
||||||
|
|
||||||
if (level === 3 || level === 4) {
|
if (level === 3 || level === 4) {
|
||||||
const title = unescape(
|
const title = text
|
||||||
text
|
.replace(/<\/?code>/g, '')
|
||||||
.replace(/<\/?code>/g, '')
|
.replace(/\.(\w+)(\((.+)?\))?/, (m, $1, $2, $3) => {
|
||||||
.replace(/\.(\w+)(\((.+)?\))?/, (m, $1, $2, $3) => {
|
if ($3) return `.${$1}(...)`;
|
||||||
if ($3) return `.${$1}(...)`;
|
if ($2) return `.${$1}()`;
|
||||||
if ($2) return `.${$1}()`;
|
return `.${$1}`;
|
||||||
return `.${$1}`;
|
});
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
subsections.push({ slug, title, level });
|
subsections.push({ slug, title, level });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ type Opts = {
|
|||||||
cwd?: string,
|
cwd?: string,
|
||||||
static?: string,
|
static?: string,
|
||||||
basepath?: string,
|
basepath?: string,
|
||||||
host_header?: string,
|
|
||||||
timeout?: number | false,
|
timeout?: number | false,
|
||||||
concurrent?: number,
|
concurrent?: number,
|
||||||
oninfo?: ({ message }: { message: string }) => void;
|
oninfo?: ({ message }: { message: string }) => void;
|
||||||
@@ -45,7 +44,6 @@ async function _export({
|
|||||||
build_dir = '__sapper__/build',
|
build_dir = '__sapper__/build',
|
||||||
export_dir = '__sapper__/export',
|
export_dir = '__sapper__/export',
|
||||||
basepath = '',
|
basepath = '',
|
||||||
host_header,
|
|
||||||
timeout = 5000,
|
timeout = 5000,
|
||||||
concurrent = 8,
|
concurrent = 8,
|
||||||
oninfo = noop,
|
oninfo = noop,
|
||||||
@@ -142,7 +140,6 @@ async function _export({
|
|||||||
|
|
||||||
const r = await Promise.race([
|
const r = await Promise.race([
|
||||||
fetch(url.href, {
|
fetch(url.href, {
|
||||||
headers: { host: host_header || host },
|
|
||||||
redirect: 'manual'
|
redirect: 'manual'
|
||||||
}),
|
}),
|
||||||
timeout_deferred.promise
|
timeout_deferred.promise
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ prog.command('export [dest]')
|
|||||||
.describe('Export your app as static files (if possible)')
|
.describe('Export your app as static files (if possible)')
|
||||||
.option('--build', '(Re)build app before exporting', true)
|
.option('--build', '(Re)build app before exporting', true)
|
||||||
.option('--basepath', 'Specify a base path')
|
.option('--basepath', 'Specify a base path')
|
||||||
.option('--host', 'Host header to use when crawling site')
|
|
||||||
.option('--concurrent', 'Concurrent requests', 8)
|
.option('--concurrent', 'Concurrent requests', 8)
|
||||||
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
|
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
|
||||||
.option('--legacy', 'Create separate legacy build')
|
.option('--legacy', 'Create separate legacy build')
|
||||||
@@ -211,7 +210,6 @@ prog.command('export [dest]')
|
|||||||
legacy: boolean,
|
legacy: boolean,
|
||||||
bundler?: 'rollup' | 'webpack',
|
bundler?: 'rollup' | 'webpack',
|
||||||
basepath?: string,
|
basepath?: string,
|
||||||
host?: string,
|
|
||||||
concurrent: number,
|
concurrent: number,
|
||||||
timeout: number | false,
|
timeout: number | false,
|
||||||
cwd: string,
|
cwd: string,
|
||||||
@@ -238,7 +236,6 @@ prog.command('export [dest]')
|
|||||||
build_dir: opts['build-dir'],
|
build_dir: opts['build-dir'],
|
||||||
export_dir: dest,
|
export_dir: dest,
|
||||||
basepath: opts.basepath,
|
basepath: opts.basepath,
|
||||||
host_header: opts.host,
|
|
||||||
timeout: opts.timeout,
|
timeout: opts.timeout,
|
||||||
concurrent: opts.concurrent,
|
concurrent: opts.concurrent,
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { stores } from '@sapper/app';
|
|
||||||
const { page } = stores();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h1>{$page.host.replace(/:\d+$/, '')}</h1>
|
|
||||||
@@ -239,15 +239,6 @@ describe('basics', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can access host through page store', async () => {
|
|
||||||
await r.load('/host');
|
|
||||||
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
|
|
||||||
await r.sapper.start();
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
});
|
|
||||||
|
|
||||||
// skipped because Nightmare doesn't seem to focus the <a> correctly
|
// skipped because Nightmare doesn't seem to focus the <a> correctly
|
||||||
it('resets the active element after navigation', async () => {
|
it('resets the active element after navigation', async () => {
|
||||||
await r.load('/');
|
await r.load('/');
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
<script context="module">
|
|
||||||
export function preload(page) {
|
|
||||||
return {
|
|
||||||
host: page.host
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export let host;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h1>{host.replace(/:\d+$/, '')}</h1>
|
|
||||||
@@ -27,15 +27,6 @@ describe('preloading', function() {
|
|||||||
assert.equal(await r.text('h1'), 'true');
|
assert.equal(await r.text('h1'), 'true');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves host from preload', async () => {
|
|
||||||
await r.load('/preload-values/host');
|
|
||||||
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
|
|
||||||
await r.sapper.start();
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('prevent crash if preload return nothing', async () => {
|
it('prevent crash if preload return nothing', async () => {
|
||||||
await r.load('/preload-nothing');
|
await r.load('/preload-nothing');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user