From 22dc5360912b2c353fa58b9977105f0c7fa46fc2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 15 Jun 2023 11:28:17 -0400 Subject: [PATCH 1/6] simplify nav --- sites/svelte.dev/src/routes/+layout.server.js | 42 +++++++++-- sites/svelte.dev/src/routes/+layout.svelte | 70 ++++++------------- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/sites/svelte.dev/src/routes/+layout.server.js b/sites/svelte.dev/src/routes/+layout.server.js index af468f274346..822fcfb52b25 100644 --- a/sites/svelte.dev/src/routes/+layout.server.js +++ b/sites/svelte.dev/src/routes/+layout.server.js @@ -24,6 +24,9 @@ function get_nav_title(url) { return ''; } +/** + * @returns {Promise} + */ async function get_nav_context_list() { const docs_list = get_docs_list(get_docs_data()); const processed_docs_list = docs_list.map(({ title, pages }) => ({ @@ -58,17 +61,42 @@ async function get_nav_context_list() { })) .filter(({ title }) => title !== 'Embeds'); - return { - docs: processed_docs_list, - blog: processed_blog_list, - tutorial: processed_tutorial_list, - examples: processed_examples_list - }; + return [ + { + title: 'Tutorial', + prefix: 'tutorial', + pathname: '/tutorial', + sections: processed_tutorial_list + }, + { + title: 'Docs', + prefix: 'docs', + pathname: '/docs', + 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 + } + ]; } export const load = async ({ url }) => { return { nav_title: get_nav_title(url), - nav_context_list: get_nav_context_list() + nav_links: get_nav_context_list() }; }; diff --git a/sites/svelte.dev/src/routes/+layout.svelte b/sites/svelte.dev/src/routes/+layout.svelte index 833f2a4612d4..f7fcd4b010e2 100644 --- a/sites/svelte.dev/src/routes/+layout.svelte +++ b/sites/svelte.dev/src/routes/+layout.svelte @@ -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; @@ -17,13 +19,13 @@
- From 3ff8cdb19d07cc6877a344074781dd2068e4e542 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 16 Jun 2023 15:02:55 -0400 Subject: [PATCH 3/6] fix link --- sites/svelte.dev/src/routes/+layout.server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/svelte.dev/src/routes/+layout.server.js b/sites/svelte.dev/src/routes/+layout.server.js index 822fcfb52b25..c62f5a1206dd 100644 --- a/sites/svelte.dev/src/routes/+layout.server.js +++ b/sites/svelte.dev/src/routes/+layout.server.js @@ -71,7 +71,7 @@ async function get_nav_context_list() { { title: 'Docs', prefix: 'docs', - pathname: '/docs', + pathname: '/docs/introduction', sections: processed_docs_list }, { From 14983c36f3c59da780b234147891002d07e01e8a Mon Sep 17 00:00:00 2001 From: Puru Vijay Date: Sat, 17 Jun 2023 01:12:30 +0530 Subject: [PATCH 4/6] Dont need this anymore --- sites/svelte.dev/src/global.d.ts | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 sites/svelte.dev/src/global.d.ts diff --git a/sites/svelte.dev/src/global.d.ts b/sites/svelte.dev/src/global.d.ts deleted file mode 100644 index a3e64bed49e9..000000000000 --- a/sites/svelte.dev/src/global.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// - -declare global { - namespace App { - interface PageData { - nav_title: string; - } - } -} - -export {}; From e89bf57ab9afef1598186106f863acb956692aef Mon Sep 17 00:00:00 2001 From: Puru Vijay Date: Sat, 17 Jun 2023 01:39:58 +0530 Subject: [PATCH 5/6] Push --- sites/svelte.dev/src/routes/+layout.server.js | 79 +----------------- .../svelte.dev/src/routes/nav.json/+server.js | 81 +++++++++++++++++++ 2 files changed, 84 insertions(+), 76 deletions(-) create mode 100644 sites/svelte.dev/src/routes/nav.json/+server.js diff --git a/sites/svelte.dev/src/routes/+layout.server.js b/sites/svelte.dev/src/routes/+layout.server.js index c62f5a1206dd..d98be151c9f1 100644 --- a/sites/svelte.dev/src/routes/+layout.server.js +++ b/sites/svelte.dev/src/routes/+layout.server.js @@ -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([ @@ -24,79 +19,11 @@ function get_nav_title(url) { return ''; } -/** - * @returns {Promise} - */ -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 [ - { - 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 - } - ]; -} +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_links: get_nav_context_list() + nav_links: nav_list }; }; diff --git a/sites/svelte.dev/src/routes/nav.json/+server.js b/sites/svelte.dev/src/routes/nav.json/+server.js new file mode 100644 index 000000000000..fec735a10546 --- /dev/null +++ b/sites/svelte.dev/src/routes/nav.json/+server.js @@ -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} + */ +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 + } + ]; +} From 244ea2a27aee685a6d4887e46986dad5779d214e Mon Sep 17 00:00:00 2001 From: Puru Vijay Date: Sat, 17 Jun 2023 12:31:48 +0530 Subject: [PATCH 6/6] minor re-arrangement --- sites/svelte.dev/src/routes/+layout.server.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sites/svelte.dev/src/routes/+layout.server.js b/sites/svelte.dev/src/routes/+layout.server.js index d98be151c9f1..6e9a0cea6077 100644 --- a/sites/svelte.dev/src/routes/+layout.server.js +++ b/sites/svelte.dev/src/routes/+layout.server.js @@ -1,3 +1,12 @@ +export const load = async ({ url, fetch }) => { + const nav_list = await fetch('/nav.json').then((r) => r.json()); + + return { + nav_title: get_nav_title(url), + nav_links: nav_list + }; +}; + /** @param {URL} url */ function get_nav_title(url) { const list = new Map([ @@ -18,12 +27,3 @@ function get_nav_title(url) { return ''; } - -export const load = async ({ url, fetch }) => { - const nav_list = await fetch('/nav.json').then((r) => r.json()); - - return { - nav_title: get_nav_title(url), - nav_links: nav_list - }; -};