mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-14 03:54:46 +00:00
fix: add link rel=preload for exported sites
This commit is contained in:
3
test/apps/export-webpack/src/routes/_error.svelte
Normal file
3
test/apps/export-webpack/src/routes/_error.svelte
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>{status}</h1>
|
||||
|
||||
<p>{error.message}</p>
|
||||
13
test/apps/export-webpack/src/routes/blog/[slug].html
Normal file
13
test/apps/export-webpack/src/routes/blog/[slug].html
Normal file
@@ -0,0 +1,13 @@
|
||||
<script context="module">
|
||||
export function preload({ params }) {
|
||||
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
|
||||
return { post };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let post;
|
||||
</script>
|
||||
|
||||
<h1>{post.title}</h1>
|
||||
19
test/apps/export-webpack/src/routes/blog/[slug].json.js
Normal file
19
test/apps/export-webpack/src/routes/blog/[slug].json.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import posts from './_posts.js';
|
||||
|
||||
export function get(req, res) {
|
||||
const post = posts.find(post => post.slug === req.params.slug);
|
||||
|
||||
if (post) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(post));
|
||||
} else {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify({ message: 'not found' }));
|
||||
}
|
||||
}
|
||||
5
test/apps/export-webpack/src/routes/blog/_posts.js
Normal file
5
test/apps/export-webpack/src/routes/blog/_posts.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default [
|
||||
{ slug: 'foo', title: 'once upon a foo' },
|
||||
{ slug: 'bar', title: 'a bar is born' },
|
||||
{ slug: 'baz', title: 'bazzily ever after' }
|
||||
];
|
||||
17
test/apps/export-webpack/src/routes/blog/index.html
Normal file
17
test/apps/export-webpack/src/routes/blog/index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return this.fetch('blog.json').then(r => r.json()).then(posts => {
|
||||
return { posts };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let posts;
|
||||
</script>
|
||||
|
||||
<h1>blog</h1>
|
||||
|
||||
{#each posts as post}
|
||||
<p><a href="blog/{post.slug}">{post.title}</a></p>
|
||||
{/each}
|
||||
9
test/apps/export-webpack/src/routes/blog/index.json.js
Normal file
9
test/apps/export-webpack/src/routes/blog/index.json.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import posts from './_posts.js';
|
||||
|
||||
export function get(req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(posts));
|
||||
}
|
||||
4
test/apps/export-webpack/src/routes/index.svelte
Normal file
4
test/apps/export-webpack/src/routes/index.svelte
Normal file
@@ -0,0 +1,4 @@
|
||||
<h1>Great success!</h1>
|
||||
|
||||
<a href="blog">blog</a>
|
||||
<a href="">empty anchor</a>
|
||||
Reference in New Issue
Block a user