Skip to content

Commit 6117625

Browse files
committed
test
1 parent df50dd5 commit 6117625

File tree

13 files changed

+78
-53
lines changed

13 files changed

+78
-53
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<nav>
2+
<a href="/">Home</a>
3+
<a href="/blog">Blog</a>
4+
</nav>
5+
6+
<slot />
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
<script>
2-
/** @type {import('./$types').PageData} */
3-
export let data;
4-
</script>
5-
6-
<h1>Top news</h1>
7-
8-
{#each data.items as item}
9-
<article>
10-
<h2>{item.title}</h2>
11-
<p>
12-
<a href={item.url}> link </a>
13-
14-
<a href="/item/{item.id}">
15-
{item.comments_count} comments
16-
</a>
17-
18-
posted {item.time_ago}
19-
</p>
20-
</article>
21-
{/each}
1+
<p>Home Page</p>

content/tutorial/02-sveltekit/02-routing/06-universal-load-functions/app-a/src/routes/api/__hidden

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { json } from '@sveltejs/kit';
2+
import { posts } from './data';
3+
4+
export function GET() {
5+
return json(posts.map((post) => ({ title: post.title, slug: post.slug })));
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { json } from '@sveltejs/kit';
2+
import { posts } from '../data';
3+
4+
export function GET({ params }) {
5+
return json(posts.find((post) => post.slug === params.slug));
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const posts = [
2+
{
3+
slug: 'welcome',
4+
title: 'Welcome to the Aperture Science computer-aided enrichment center',
5+
content:
6+
'<p>We hope your brief detention in the relaxation vault has been a pleasant one.</p><p>Your specimen has been processed and we are now ready to begin the test proper.</p>'
7+
},
8+
9+
{
10+
slug: 'safety',
11+
title: 'Safety notice',
12+
content:
13+
'<p>While safety is one of many Enrichment Center Goals, the Aperture Science High Energy Pellet, seen to the left of the chamber, can and has caused permanent disabilities, such as vaporization. Please be careful.</p>'
14+
},
15+
16+
{
17+
slug: 'cake',
18+
title: 'This was a triumph',
19+
content: "<p>I'm making a note here: HUGE SUCCESS.</p>"
20+
}
21+
];

content/tutorial/02-sveltekit/02-routing/06-universal-load-functions/app-a/src/routes/+page.server.js renamed to content/tutorial/02-sveltekit/02-routing/06-universal-load-functions/app-a/src/routes/blog/+page.server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { error } from '@sveltejs/kit';
22

33
/** @type {import('./$types').PageServerLoad} */
44
export async function load({ fetch }) {
5-
const response = await fetch('https://api.hnpwa.com/v0/news/1.json');
5+
const response = await fetch('/api/blog');
66

77
if (!response.ok) {
88
throw error(response.status);
99
}
1010

11-
const items = await response.json();
11+
const summaries = await response.json();
1212

1313
return {
14-
items
14+
summaries
1515
};
1616
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
/** @type {import('./$types').PageData} */
3+
export let data;
4+
</script>
5+
6+
<h1>Blog</h1>
7+
8+
<ul>
9+
{#each data.summaries as { slug, title }}
10+
<li><a href="/blog/{slug}">{title}</a></li>
11+
{/each}
12+
</ul>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { error } from '@sveltejs/kit';
22

33
/** @type {import('./$types').PageServerLoad} */
44
export async function load({ fetch, params }) {
5-
const response = await fetch(`https://api.hnpwa.com/v0/item/${params.id}.json`);
5+
const response = await fetch(`/api/blog/${params.slug}`);
66

77
if (!response.ok) {
88
throw error(response.status);
99
}
1010

11-
return response.json();
11+
return { post: response.json() };
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import Comment from './Comment.svelte';
3+
4+
/** @type {import('./$types').PageData} */
5+
export let data;
6+
</script>
7+
8+
<h1>{data.post.title}</h1>
9+
<div>{@html data.post.content}</div>

content/tutorial/02-sveltekit/02-routing/06-universal-load-functions/app-a/src/routes/item/[id]/+page.svelte

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/routes/tutorial/[slug]/Folder.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@
3232
const { edit, add, remove } = getContext('filetree');
3333
3434
$: _files = files || []; // workaround for what seems to be a Svelte bug, where files is undefined on navigation
35+
$: hidden_children = _files
36+
.filter((file) =>
37+
file.name.startsWith(prefix + file.name.slice(prefix.length).split('/').shift() + '/__hidden')
38+
)
39+
.map((file) => file.name.slice(0, -'/__hidden'.length));
3540
$: children = _files
36-
.filter((file) => file.name.startsWith(prefix))
41+
.filter(
42+
(file) =>
43+
file.name.startsWith(prefix) &&
44+
!hidden_children.some(
45+
(hidden) => file.name.startsWith(hidden + '/') || file.name === hidden
46+
)
47+
)
3748
.sort((a, b) => (a.name < b.name ? -1 : 1));
3849
$: child_directories = children.filter(
3950
(child) => child.depth === depth + 1 && child.type === 'directory'

0 commit comments

Comments
 (0)