Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions sites/svelte.dev/src/global.d.ts

This file was deleted.

51 changes: 3 additions & 48 deletions sites/svelte.dev/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { get_blog_data, get_blog_list } from '$lib/server/blog/index.js';
import { get_docs_data, get_docs_list } from '$lib/server/docs/index.js';
import { get_examples_data, get_examples_list } from '$lib/server/examples/index.js';
import { get_tutorial_data, get_tutorial_list } from '$lib/server/tutorial/index.js';

/** @param {URL} url */
function get_nav_title(url) {
const list = new Map([
Expand All @@ -24,51 +19,11 @@ function get_nav_title(url) {
return '';
}

async function get_nav_context_list() {
const docs_list = get_docs_list(get_docs_data());
const processed_docs_list = docs_list.map(({ title, pages }) => ({
title,
sections: pages.map(({ title, path }) => ({ title, path }))
}));

const blog_list = get_blog_list(get_blog_data());
const processed_blog_list = [
{
title: 'Blog',
sections: blog_list.map(({ title, slug, date }) => ({
title,
path: '/blog/' + slug,
// Put a NEW badge on blog posts that are less than 14 days old
badge: (+new Date() - +new Date(date)) / (1000 * 60 * 60 * 24) < 14 ? 'NEW' : undefined
}))
}
];

const tutorial_list = get_tutorial_list(get_tutorial_data());
const processed_tutorial_list = tutorial_list.map(({ title, tutorials }) => ({
title,
sections: tutorials.map(({ title, slug }) => ({ title, path: '/tutorial/' + slug }))
}));

const examples_list = get_examples_list(get_examples_data());
const processed_examples_list = examples_list
.map(({ title, examples }) => ({
title,
sections: examples.map(({ title, slug }) => ({ title, path: '/examples/' + slug }))
}))
.filter(({ title }) => title !== 'Embeds');

return {
docs: processed_docs_list,
blog: processed_blog_list,
tutorial: processed_tutorial_list,
examples: processed_examples_list
};
}
export const load = async ({ url, fetch }) => {
const nav_list = await fetch('/nav.json').then((r) => r.json());

export const load = async ({ url }) => {
return {
nav_title: get_nav_title(url),
nav_context_list: get_nav_context_list()
nav_links: nav_list
};
};
68 changes: 16 additions & 52 deletions sites/svelte.dev/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import { browser } from '$app/environment';
import { page } from '$app/stores';
import { Icon, Shell } from '@sveltejs/site-kit/components';
import { Nav, NavItem, Separator } from '@sveltejs/site-kit/nav';
import { Nav, Separator } from '@sveltejs/site-kit/nav';
import { Search, SearchBox } from '@sveltejs/site-kit/search';
import '@sveltejs/site-kit/styles/index.css';

export let data;
</script>

<svelte:head>
Expand All @@ -17,7 +19,7 @@

<div style:display={$page.url.pathname !== '/docs' ? 'contents' : 'none'}>
<Shell nav_visible={$page.url.pathname !== '/repl/embed'}>
<Nav slot="top-nav">
<Nav slot="top-nav" title={data.nav_title} links={data.nav_links}>
<svelte:fragment slot="home-large">
<strong>svelte</strong>.dev
</svelte:fragment>
Expand All @@ -26,62 +28,24 @@
<strong>svelte</strong>
</svelte:fragment>

<svelte:fragment slot="nav-center">
<svelte:fragment slot="search">
{#if $page.url.pathname !== '/search'}
<li><Search /></li>
<Search />
{/if}
</svelte:fragment>

<svelte:fragment slot="nav-right">
<NavItem
href="/tutorial"
selected={$page.url.pathname.startsWith('/tutorial') || null}
relatedMenuName="tutorial"
>
Tutorial
</NavItem>

<NavItem
href="/docs/introduction"
selected={$page.url.pathname.startsWith('/docs') || null}
relatedMenuName="docs"
>
Docs
</NavItem>

<NavItem
href="/examples"
selected={$page.url.pathname.startsWith('/examples') || null}
relatedMenuName="examples"
>
Examples
</NavItem>

<NavItem href="/repl" selected={$page.url.pathname.startsWith('/repl') || null}>
REPL
</NavItem>

<NavItem
href="/blog"
selected={$page.url.pathname.startsWith('/blog') || null}
relatedMenuName="blog"
>
Blog
</NavItem>

<Separator />

<NavItem href="https://kit.svelte.dev" external>SvelteKit</NavItem>
<svelte:fragment slot="external-links">
<a href="https://kit.svelte.dev">SvelteKit</a>

<NavItem href="/chat" external title="Discord Chat">
<span slot="small">Discord</span>
<Icon name="discord" />
</NavItem>
<a href="/chat" title="Discord Chat">
<span class="small">Discord</span>
<span class="large"><Icon name="discord" /></span>
</a>

<NavItem href="https://github.com/sveltejs/svelte" external title="GitHub Repo">
<span slot="small">GitHub</span>
<Icon name="github" />
</NavItem>
<a href="https://github.com/sveltejs/svelte" title="GitHub Repo">
<span class="small">GitHub</span>
<span class="large"><Icon name="github" /></span>
</a>
</svelte:fragment>
</Nav>

Expand Down
81 changes: 81 additions & 0 deletions sites/svelte.dev/src/routes/nav.json/+server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { get_blog_data, get_blog_list } from '$lib/server/blog/index.js';
import { get_docs_data, get_docs_list } from '$lib/server/docs/index.js';
import { get_examples_data, get_examples_list } from '$lib/server/examples/index.js';
import { get_tutorial_data, get_tutorial_list } from '$lib/server/tutorial/index.js';
import { json } from '@sveltejs/kit';

export const prerender = true;

export const GET = async () => {
return json(await get_nav_list());
};

/**
* @returns {Promise<import('@sveltejs/site-kit').NavigationLink[]>}
*/
async function get_nav_list() {
const docs_list = get_docs_list(get_docs_data());
const processed_docs_list = docs_list.map(({ title, pages }) => ({
title,
sections: pages.map(({ title, path }) => ({ title, path }))
}));

const blog_list = get_blog_list(get_blog_data());
const processed_blog_list = [
{
title: 'Blog',
sections: blog_list.map(({ title, slug, date }) => ({
title,
path: '/blog/' + slug,
// Put a NEW badge on blog posts that are less than 14 days old
badge: (+new Date() - +new Date(date)) / (1000 * 60 * 60 * 24) < 14 ? 'NEW' : undefined
}))
}
];

const tutorial_list = get_tutorial_list(get_tutorial_data());
const processed_tutorial_list = tutorial_list.map(({ title, tutorials }) => ({
title,
sections: tutorials.map(({ title, slug }) => ({ title, path: '/tutorial/' + slug }))
}));

const examples_list = get_examples_list(get_examples_data());
const processed_examples_list = examples_list
.map(({ title, examples }) => ({
title,
sections: examples.map(({ title, slug }) => ({ title, path: '/examples/' + slug }))
}))
.filter(({ title }) => title !== 'Embeds');

return [
{
title: 'Tutorial',
prefix: 'tutorial',
pathname: '/tutorial',
sections: processed_tutorial_list
},
{
title: 'Docs',
prefix: 'docs',
pathname: '/docs/introduction',
sections: processed_docs_list
},
{
title: 'Examples',
prefix: 'examples',
pathname: '/examples',
sections: processed_examples_list
},
{
title: 'REPL',
prefix: 'repl',
pathname: '/repl'
},
{
title: 'Blog',
prefix: 'blog',
pathname: '/blog',
sections: processed_blog_list
}
];
}