Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jun 18, 2024
1 parent a2bca85 commit aac0030
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
24 changes: 10 additions & 14 deletions apps/svelte.dev/src/routes/docs/[...path]/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { error, redirect } from '@sveltejs/kit';
import { markedTransform } from '@sveltejs/site-kit/markdown';

export async function load({ params }) {
const page = index[`docs/${params.path}`];
const document = index[`docs/${params.path}`];

if (!page) {
if (!document) {
error(404);
}

if (!page.body) {
let child = page;
if (!document.body) {
let child = document;

while (child.children[0]) {
child = child.children[0];
}

if (child === page) {
if (child === document) {
error(404);
}

Expand All @@ -26,15 +26,11 @@ export async function load({ params }) {
const pkg = params.path.split('/')[0];

return {
// TODO DRY this out
page: {
slug: page.slug,
file: page.file,
title: page.metadata.title,
sections: page.sections,
body: await markedTransform(page.body),
prev: page.prev?.slug.startsWith(`docs/${pkg}/`) ? page.prev : null,
next: page.next?.slug.startsWith(`docs/${pkg}/`) ? page.next : null
document: {
...document,
body: await markedTransform(document.body),
prev: document.prev?.slug.startsWith(`docs/${pkg}/`) ? document.prev : null,
next: document.next?.slug.startsWith(`docs/${pkg}/`) ? document.next : null
}
};
}
32 changes: 18 additions & 14 deletions apps/svelte.dev/src/routes/docs/[...path]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,43 @@
</script>

<svelte:head>
<title>{data.page?.title} • Docs • Svelte</title>

<meta name="twitter:title" content="{data.page.title} • Docs • Svelte" />
<meta name="twitter:description" content="{data.page.title} • Svelte documentation" />
<meta name="Description" content="{data.page.title} • Svelte documentation" />
<title>{data.document.metadata.title} • Docs • Svelte</title>

<meta name="twitter:title" content="{data.document.metadata.title} • Docs • Svelte" />
<meta
name="twitter:description"
content="{data.document.metadata.title} • Svelte documentation"
/>
<meta name="Description" content="{data.document.metadata.title} • Svelte documentation" />
</svelte:head>

<div class="text" id="docs-content" use:copy_code_descendants>
<a
class="edit"
href="https://github.com/sveltejs/svelte.dev/edit/main/apps/svelte.dev/content/{data.page.file}"
href="https://github.com/sveltejs/svelte.dev/edit/main/apps/svelte.dev/content/{data.document
.file}"
>
<Icon size={50} name="edit" /> Edit this page on GitHub
</a>

<DocsOnThisPage details={data.page} />
<DocsOnThisPage details={data.document} />

{@html data.page.body}
{@html data.document.body}
</div>

<div class="controls">
<div>
<span class:faded={!data.page.prev}>previous</span>
<span class:faded={!data.document.prev}>previous</span>

{#if data.page.prev}
<a href="/{data.page.prev.slug}">{data.page.prev.title}</a>
{#if data.document.prev}
<a href="/{data.document.prev.slug}">{data.document.prev.title}</a>
{/if}
</div>

<div>
<span class:faded={!data.page.next}>next</span>
{#if data.page.next}
<a href="/{data.page.next.slug}">{data.page.next.title}</a>
<span class:faded={!data.document.next}>next</span>
{#if data.document.next}
<a href="/{data.document.next.slug}">{data.document.next.title}</a>
{/if}
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/site-kit/src/lib/docs/DocsOnThisPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { readable } from 'svelte/store';
import { slide } from 'svelte/transition';
/** @type {{details: import('./types').Page, orientation?: 'auto' | 'inline' | 'aside', children?: import('svelte').Snippet}} */
/** @type {{details: import('../types').Document, orientation?: 'auto' | 'inline' | 'aside', children?: import('svelte').Snippet}} */
let { details, orientation = 'auto', children } = $props();
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -223,9 +223,9 @@
<ul>
<li>
<a
href={details.path}
href="/{details.slug}"
aria-current={hash === '' ? 'page' : false}
onclick={on_link_click}>{details.title}</a
onclick={on_link_click}>{details.metadata.title}</a
>
</li>
{#each details.sections as { title, slug }}
Expand Down

0 comments on commit aac0030

Please sign in to comment.