Compare commits

..

3 Commits

Author SHA1 Message Date
Richard Harris
201a0eb2f6 fix edit links 2019-06-16 15:22:52 -04:00
Richard Harris
4f0ab31049 html titles 2019-06-16 15:18:40 -04:00
Richard Harris
d97efda10b update site-kit 2019-06-16 14:43:01 -04:00
16 changed files with 18 additions and 86 deletions

View File

@@ -121,7 +121,7 @@ export function select_target(url: URL): Target {
const part = route.parts[route.parts.length - 1];
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 };
}
@@ -129,7 +129,7 @@ export function select_target(url: URL): Target {
}
export function handle_error(url: URL) {
const { host, pathname, search } = location;
const { pathname, search } = location;
const { session, preloaded, status, error } = initial_data;
if (!root_preloaded) {
@@ -154,7 +154,7 @@ export function handle_error(url: URL) {
}
const query = extract_query(search);
render(null, [], props, { host, path: pathname, query, params: {} });
render(null, [], props, { path: pathname, query, params: {} });
}
export function scroll_state() {
@@ -301,7 +301,6 @@ export async function hydrate_target(target: Target): Promise<{
if (!root_preloaded) {
root_preloaded = initial_data.preloaded[0] || root_preload.call(preload_context, {
host: page.host,
path: page.path,
query: page.query,
params: {}
@@ -339,7 +338,6 @@ export async function hydrate_target(target: Target): Promise<{
if (ready || !initial_data.preloaded[i + 1]) {
preloaded = preload
? await preload.call(preload_context, {
host: page.host,
path: page.path,
query: page.query,
params: part.params ? part.params(target.match) : {}

View File

@@ -56,7 +56,6 @@ export type Redirect = {
};
export type Page = {
host: string;
path: string;
params: Record<string, string>;
query: Record<string, string | string[]>;

View File

@@ -149,7 +149,6 @@ export function get_page_handler(
try {
const root_preloaded = manifest.root_preload
? manifest.root_preload.call(preload_context, {
host: req.headers.host,
path: req.path,
query: req.query,
params: {}
@@ -169,7 +168,6 @@ export function get_page_handler(
return part.preload
? part.preload.call(preload_context, {
host: req.headers.host,
path: req.path,
query: req.query,
params
@@ -220,7 +218,6 @@ export function get_page_handler(
stores: {
page: {
subscribe: writable({
host: req.headers.host,
path: req.path,
query: req.query,
params

View File

@@ -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`.
`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:

View File

@@ -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
* `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

View File

@@ -846,9 +846,9 @@
}
},
"@sveltejs/site-kit": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.0.4.tgz",
"integrity": "sha512-BaQhIL1iPhCF+iDXfy9psDvRdFzfyMPkWnoZHfVz+INpHsU2aJmRZOPl9rykXmPyiPo+AwTTNK5vjIvmtwHLPQ==",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.1.1.tgz",
"integrity": "sha512-EYQKhrdbRWeaPteTN1YZ4oW0xBbUzQ2D+XPdIfEvwDvgxAka9KZP5BCiENrXFf7Z9lxe2HW6MDlrT2sMwoS8+g==",
"dev": true,
"requires": {
"@sindresorhus/slugify": "^0.9.1",

View File

@@ -28,7 +28,7 @@
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^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",
"rollup": "^1.11.3",
"rollup-plugin-babel": "^4.3.2",

View File

@@ -19,4 +19,4 @@
<meta name="Description" content="The next small thing in web development">
</svelte:head>
<Docs {sections}/>
<Docs {sections} project="sapper"/>

View File

@@ -19,4 +19,4 @@
<meta name="Description" content="The next small thing in web development">
</svelte:head>
<Docs {sections}/>
<Docs {sections} project="sapper" dir="migrating"/>

View File

@@ -7,23 +7,6 @@ import { make_session_slug_processor } from '@sveltejs/site-kit/utils/slug';
import marked from 'marked';
import hljs from 'highlight.js';
const escaped = {
'"': '&quot;',
"'": '&#39;',
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
};
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 = [
'blockquote',
'html',
@@ -115,15 +98,13 @@ export default function generate_docs(dir) {
const slug = level <= 4 && make_slug(rawtext);
if (level === 3 || level === 4) {
const title = unescape(
text
.replace(/<\/?code>/g, '')
.replace(/\.(\w+)(\((.+)?\))?/, (m, $1, $2, $3) => {
if ($3) return `.${$1}(...)`;
if ($2) return `.${$1}()`;
return `.${$1}`;
})
);
const title = text
.replace(/<\/?code>/g, '')
.replace(/\.(\w+)(\((.+)?\))?/, (m, $1, $2, $3) => {
if ($3) return `.${$1}(...)`;
if ($2) return `.${$1}()`;
return `.${$1}`;
});
subsections.push({ slug, title, level });
}

View File

@@ -18,7 +18,6 @@ type Opts = {
cwd?: string,
static?: string,
basepath?: string,
host_header?: string,
timeout?: number | false,
concurrent?: number,
oninfo?: ({ message }: { message: string }) => void;
@@ -45,7 +44,6 @@ async function _export({
build_dir = '__sapper__/build',
export_dir = '__sapper__/export',
basepath = '',
host_header,
timeout = 5000,
concurrent = 8,
oninfo = noop,
@@ -142,7 +140,6 @@ async function _export({
const r = await Promise.race([
fetch(url.href, {
headers: { host: host_header || host },
redirect: 'manual'
}),
timeout_deferred.promise

View File

@@ -194,7 +194,6 @@ prog.command('export [dest]')
.describe('Export your app as static files (if possible)')
.option('--build', '(Re)build app before exporting', true)
.option('--basepath', 'Specify a base path')
.option('--host', 'Host header to use when crawling site')
.option('--concurrent', 'Concurrent requests', 8)
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
.option('--legacy', 'Create separate legacy build')
@@ -211,7 +210,6 @@ prog.command('export [dest]')
legacy: boolean,
bundler?: 'rollup' | 'webpack',
basepath?: string,
host?: string,
concurrent: number,
timeout: number | false,
cwd: string,
@@ -238,7 +236,6 @@ prog.command('export [dest]')
build_dir: opts['build-dir'],
export_dir: dest,
basepath: opts.basepath,
host_header: opts.host,
timeout: opts.timeout,
concurrent: opts.concurrent,

View File

@@ -1,6 +0,0 @@
<script>
import { stores } from '@sapper/app';
const { page } = stores();
</script>
<h1>{$page.host.replace(/:\d+$/, '')}</h1>

View File

@@ -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
it('resets the active element after navigation', async () => {
await r.load('/');

View File

@@ -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>

View File

@@ -27,15 +27,6 @@ describe('preloading', function() {
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 () => {
await r.load('/preload-nothing');