Skip to content

Commit f1c029b

Browse files
authored
Merge pull request #1522 from ItzNotABug/fix-docs-bugs
Fix Docs Bugs
2 parents a47240a + 9478245 commit f1c029b

File tree

6 files changed

+147
-15
lines changed

6 files changed

+147
-15
lines changed

src/lib/components/PreFooter.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import { trackEvent } from '$lib/actions/analytics';
44
</script>
55

6-
<img src="/images/bgs/pre-footer.png" alt="" class="web-pre-footer-bg" loading="lazy" style="z-index:-1" />
6+
<img
7+
src="/images/bgs/pre-footer.png"
8+
alt=""
9+
class="web-pre-footer-bg"
10+
loading="lazy"
11+
style="z-index:-1"
12+
/>
713

814
<div class="web-u-row-gap-80 relative grid gap-8 md:grid-cols-2">
915
<section class="web-hero flex items-center justify-center gap-y-8">

src/lib/layouts/Docs.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
}
3535
3636
const CTX_KEY = Symbol('docs');
37+
const TUT_CTX_KEY = Symbol('tut-docs');
3738
export const isInDocs = () => getContext<boolean>(CTX_KEY) ?? false;
39+
export const isInTutorialDocs = () => getContext<boolean>(TUT_CTX_KEY) ?? false;
3840
</script>
3941

4042
<script lang="ts">
@@ -43,6 +45,7 @@
4345
import { getContext, setContext } from 'svelte';
4446
import { GITHUB_REPO_LINK, GITHUB_STARS } from '$lib/constants';
4547
import { PUBLIC_APPWRITE_DASHBOARD } from '$env/static/public';
48+
import { page } from '$app/stores';
4649
4750
export let variant: DocsLayoutVariant = 'default';
4851
export let isReferences = false;
@@ -63,7 +66,9 @@
6366
showSidenav: false
6467
}));
6568
});
66-
setContext(CTX_KEY, true);
69+
70+
const key = $page.route.id?.includes('tutorials') ? TUT_CTX_KEY : CTX_KEY;
71+
setContext(key, true);
6772
6873
const handleKeydown = (e: KeyboardEvent) => {
6974
if (e.key === 'Escape' && ($layoutState.showReferences || $layoutState.showSidenav)) {

src/lib/layouts/DocsTutorial.svelte

Lines changed: 117 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import type { Tutorial } from '$markdoc/layouts/Tutorial.svelte';
55
import type { TocItem } from './DocsArticle.svelte';
66
import Heading from '$markdoc/nodes/Heading.svelte';
7-
import { onMount } from 'svelte';
7+
import { onMount, tick } from 'svelte';
8+
import { page } from '$app/stores';
89
910
export let toc: Array<TocItem>;
1011
export let back: string;
@@ -31,13 +32,66 @@
3132
3233
let slotContent: HTMLElement | null = null;
3334
35+
function scrollToElement(pageHash: string) {
36+
const element = document.getElementById(pageHash);
37+
if (element) {
38+
const offset = 50;
39+
const rect = element.getBoundingClientRect();
40+
window.scroll({ top: window.scrollY + rect.top - offset });
41+
}
42+
}
43+
44+
/**
45+
* Due to underlying logic with anchor links & the auto-scroll via hash values in the URL,
46+
* we have an issue where if the first item is not scrolled enough it isn't marked as `selected`.
47+
*
48+
* We do below workaround for the time being without breaking things to scroll to the first item.
49+
*/
50+
async function preSelectItemOnInit() {
51+
await tick();
52+
53+
if (!$page.url.hash) return;
54+
const tocItem = toc.slice(1);
55+
56+
// no sub-items, return.
57+
if (!tocItem.length) return;
58+
59+
const pageHash = $page.url.hash.replace('#', '');
60+
const tocItemHref = tocItem[0].href.replace('#', '');
61+
62+
if (pageHash !== tocItemHref) return;
63+
64+
scrollToElement(pageHash);
65+
}
66+
67+
// same issue as above, only happens on the first item.
68+
function scrollToItem(parent: TocItem, index: number) {
69+
const tocItem = toc.slice(1);
70+
71+
if (!tocItem.length) return;
72+
const tocItemHref = parent.href.replace('#', '');
73+
74+
const element = document.getElementById(tocItemHref);
75+
76+
if (index === 0) {
77+
scrollToElement(tocItemHref);
78+
} else {
79+
element?.scrollIntoView();
80+
}
81+
82+
// because we used `preventDefault`.
83+
history.pushState(null, '', parent.href);
84+
}
85+
3486
onMount(() => {
3587
if (!slotContent) return;
3688
3789
// dynamically modify all `label` headers to `body`.
38-
slotContent.querySelectorAll<HTMLHeadingElement>('h2.web-label').forEach((header) => {
39-
header.classList.replace('web-label', 'web-main-body-500');
90+
slotContent.querySelectorAll<HTMLHeadingElement>('h2.text-label').forEach((header) => {
91+
header.classList.replace('text-label', 'web-main-body-500');
4092
});
93+
94+
preSelectItemOnInit();
4195
});
4296
</script>
4397

@@ -77,7 +131,9 @@
77131
/>
78132
</a>
79133
{/if}
80-
<h1 class="web-title lg:-ml-5">{firstStepItem?.title}</h1>
134+
<h1 class="web-title {currentStep === 1 ? 'lg:-ml-5' : ''}">
135+
{firstStepItem?.title}
136+
</h1>
81137
</div>
82138
</div>
83139
<div class="web-article-header-end" />
@@ -87,16 +143,18 @@
87143
<section class="web-article-content-sub-section">
88144
<header class="web-article-content-header">
89145
<span class="web-numeric-badge">{currentStep}</span>
90-
<Heading level={1} id={currentStepItem.href} step={currentStep}>
91-
{getCorrectTitle(currentStepItem, 1)}
92-
</Heading>
146+
<div class="tutorial-heading">
147+
<Heading level={1} id={currentStepItem.href} step={currentStep}>
148+
{getCorrectTitle(currentStepItem, 1)}
149+
</Heading>
150+
</div>
93151
</header>
94152

95-
<div class="u-padding-block-start-32" bind:this={slotContent}>
153+
<div class="web-u-padding-block-start-32" bind:this={slotContent}>
96154
<slot />
97155
</div>
98156

99-
<div class="flex justify-between">
157+
<div class="web-u-padding-block-start-32 flex justify-between">
100158
{#if prevStep}
101159
<a href={prevStep.href} class="web-button is-text previous-step-anchor">
102160
<span class="icon-cheveron-left" aria-hidden="true" />
@@ -135,6 +193,7 @@
135193
<ol class="web-references-menu-list">
136194
{#each tutorials as tutorial, index}
137195
{@const isCurrentStep = currentStep === tutorial.step}
196+
{@const absoluteToc = toc.slice(1)}
138197
<li class="web-references-menu-item">
139198
<a
140199
href={tutorial.href}
@@ -148,14 +207,16 @@
148207
>{index === 0 ? 'Introduction' : tutorial.title}</span
149208
>
150209
</a>
151-
{#if isCurrentStep && toc.length}
210+
{#if isCurrentStep && absoluteToc.length}
152211
<ol
153212
class="web-references-menu-list u-margin-block-start-16 u-margin-inline-start-32"
154213
>
155-
{#each toc.slice(1) as parent}
214+
{#each absoluteToc as parent, innerIndex}
156215
<li class="web-references-menu-item">
157216
<a
158217
href={parent.href}
218+
on:click|preventDefault={() =>
219+
scrollToItem(parent, innerIndex)}
159220
class="web-references-menu-link is-inner"
160221
class:tutorial-scroll-indicator={parent.selected}
161222
class:is-selected={parent.selected}
@@ -208,4 +269,49 @@
208269
background: unset;
209270
padding-inline-start: unset;
210271
}
272+
273+
.u-margin-block-start-16 {
274+
margin-block-start: 1rem;
275+
}
276+
277+
.u-margin-inline-start-32 {
278+
margin-inline-start: 2rem;
279+
}
280+
281+
.web-references-menu-item:has(.is-selected)::before {
282+
/* maintains the distance correctly for the children items */
283+
inset-inline-start: -3.55rem;
284+
}
285+
286+
/* Static slider: default slider for each selected link */
287+
.web-references-menu-list > .web-references-menu-item > .is-selected::before {
288+
content: ' ';
289+
position: absolute;
290+
inset-block-start: 0;
291+
block-size: 1.375rem;
292+
inline-size: 0.0625rem;
293+
inset-inline-start: -1.3125rem;
294+
background-color: hsl(var(--p-references-menu-link-color-text));
295+
}
296+
297+
/* Hide static slider if any child menu item is selected */
298+
.web-references-menu-list
299+
> .web-references-menu-item:has(.web-references-menu-list .is-selected)
300+
> .is-selected::before {
301+
background-color: transparent;
302+
}
303+
304+
/* Transparent slider for selected child items because we use parent level */
305+
.web-references-menu-list
306+
> .web-references-menu-item
307+
> .web-references-menu-list
308+
> .web-references-menu-item
309+
> .is-selected::before {
310+
content: '';
311+
background-color: transparent;
312+
}
313+
314+
:global(.tutorial-heading h2) {
315+
margin-bottom: unset;
316+
}
211317
</style>

src/markdoc/nodes/Fence.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { copy } from '$lib/utils/copy';
88
import type { CodeContext } from '../tags/MultiCode.svelte';
99
import { melt } from '@melt-ui/svelte';
10+
import { isInTutorialDocs } from '$lib/layouts/Docs.svelte';
1011
1112
export let content: string;
1213
export let toCopy: string | undefined = undefined;
@@ -15,6 +16,7 @@
1516
export let withLineNumbers = true;
1617
export let badge: string | null = null;
1718
19+
const inTutorialDocs = isInTutorialDocs();
1820
const insideMultiCode = hasContext('multi-code');
1921
const selected = insideMultiCode ? getContext<CodeContext>('multi-code').selected : null;
2022
@@ -61,7 +63,11 @@
6163
{@html result}
6264
{/if}
6365
{:else}
64-
<section class="dark web-code-snippet" aria-label="code-snippet panel">
66+
<section
67+
class="dark web-code-snippet"
68+
class:no-top-margin={inTutorialDocs}
69+
aria-label="code-snippet panel"
70+
>
6571
<header class="web-code-snippet-header">
6672
<div class="web-code-snippet-header-start">
6773
{#if badgeValue}
@@ -98,3 +104,9 @@
98104
</div>
99105
</section>
100106
{/if}
107+
108+
<style>
109+
.no-top-margin {
110+
margin-top: unset !important;
111+
}
112+
</style>

src/markdoc/nodes/Paragraph.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import { isInPolicy } from '$markdoc/layouts/Policy.svelte';
44
import { getContext, hasContext } from 'svelte';
55
import { isInTable } from './Table.svelte';
6-
import { isInDocs } from '$lib/layouts/Docs.svelte';
6+
import { isInDocs, isInTutorialDocs } from '$lib/layouts/Docs.svelte';
77
88
const noParagraph = hasContext('no-paragraph') ? getContext('no-paragraph') : false;
99
const inDocs = isInDocs();
10+
const inTutorialDocs = isInTutorialDocs();
1011
const inPolicy = isInPolicy();
1112
const inChangelog = isInChangelog();
1213
const inTable = isInTable();
@@ -18,6 +19,7 @@
1819
if (inDocs) return 'text-paragraph-md mb-8';
1920
if (inPolicy) return 'text-paragraph-md mb-4';
2021
if (inTable) return 'text-paragraph-md';
22+
if (inTutorialDocs) return 'text-paragraph-md mb-2';
2123
if (inChangelog) return 'text-paragraph-lg mb-4 font-normal';
2224
return 'text-paragraph-lg mb-8';
2325
})();

src/routes/products/storage/ProjectCard.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
export let image: $$Props['image'];
1919
export let href: $$Props['href'];
2020
</script>
21+
2122
<a
2223
class="web-card is-white web-u-flex-vertical u-gap-8"
2324
style="--card-padding: 0.5rem;"

0 commit comments

Comments
 (0)