1- import { get_blog_data , get_blog_list } from '$lib/server/blog/index.js' ;
2- import { get_docs_data , get_docs_list } from '$lib/server/docs/index.js' ;
3- import { get_examples_data , get_examples_list } from '$lib/server/examples/index.js' ;
4- import { get_tutorial_data , get_tutorial_list } from '$lib/server/tutorial/index.js' ;
1+ export const load = async ( { url, fetch } ) => {
2+ const nav_list = await fetch ( '/nav.json' ) . then ( ( r ) => r . json ( ) ) ;
3+
4+ return {
5+ nav_title : get_nav_title ( url ) ,
6+ nav_links : nav_list
7+ } ;
8+ } ;
59
610/** @param {URL } url */
711function get_nav_title ( url ) {
@@ -23,80 +27,3 @@ function get_nav_title(url) {
2327
2428 return '' ;
2529}
26-
27- /**
28- * @returns {Promise<import('@sveltejs/site-kit').NavigationLink[]> }
29- */
30- async function get_nav_context_list ( ) {
31- const docs_list = get_docs_list ( get_docs_data ( ) ) ;
32- const processed_docs_list = docs_list . map ( ( { title, pages } ) => ( {
33- title,
34- sections : pages . map ( ( { title, path } ) => ( { title, path } ) )
35- } ) ) ;
36-
37- const blog_list = get_blog_list ( get_blog_data ( ) ) ;
38- const processed_blog_list = [
39- {
40- title : 'Blog' ,
41- sections : blog_list . map ( ( { title, slug, date } ) => ( {
42- title,
43- path : '/blog/' + slug ,
44- // Put a NEW badge on blog posts that are less than 14 days old
45- badge : ( + new Date ( ) - + new Date ( date ) ) / ( 1000 * 60 * 60 * 24 ) < 14 ? 'NEW' : undefined
46- } ) )
47- }
48- ] ;
49-
50- const tutorial_list = get_tutorial_list ( get_tutorial_data ( ) ) ;
51- const processed_tutorial_list = tutorial_list . map ( ( { title, tutorials } ) => ( {
52- title,
53- sections : tutorials . map ( ( { title, slug } ) => ( { title, path : '/tutorial/' + slug } ) )
54- } ) ) ;
55-
56- const examples_list = get_examples_list ( get_examples_data ( ) ) ;
57- const processed_examples_list = examples_list
58- . map ( ( { title, examples } ) => ( {
59- title,
60- sections : examples . map ( ( { title, slug } ) => ( { title, path : '/examples/' + slug } ) )
61- } ) )
62- . filter ( ( { title } ) => title !== 'Embeds' ) ;
63-
64- return [
65- {
66- title : 'Tutorial' ,
67- prefix : 'tutorial' ,
68- pathname : '/tutorial' ,
69- sections : processed_tutorial_list
70- } ,
71- {
72- title : 'Docs' ,
73- prefix : 'docs' ,
74- pathname : '/docs/introduction' ,
75- sections : processed_docs_list
76- } ,
77- {
78- title : 'Examples' ,
79- prefix : 'examples' ,
80- pathname : '/examples' ,
81- sections : processed_examples_list
82- } ,
83- {
84- title : 'REPL' ,
85- prefix : 'repl' ,
86- pathname : '/repl'
87- } ,
88- {
89- title : 'Blog' ,
90- prefix : 'blog' ,
91- pathname : '/blog' ,
92- sections : processed_blog_list
93- }
94- ] ;
95- }
96-
97- export const load = async ( { url } ) => {
98- return {
99- nav_title : get_nav_title ( url ) ,
100- nav_links : get_nav_context_list ( )
101- } ;
102- } ;
0 commit comments