|
1 | 1 | <script> |
2 | 2 | import { marked } from 'marked'; |
3 | | -import { onMount } from 'svelte'; |
4 | 3 |
|
5 | 4 | export let data; |
6 | 5 |
|
7 | 6 | let content = ''; |
8 | | -let title = ''; |
9 | | -let loading = true; |
10 | | -let error = false; |
11 | | -
|
12 | | -onMount(async () => { |
13 | | - try { |
14 | | - const slug = data.slug; |
15 | | - if (!slug) { |
16 | | - error = true; |
17 | | - return; |
18 | | - } |
19 | | -
|
20 | | - // Try to load the markdown file |
21 | | - const response = await fetch(`/docs/${slug}.md`); |
22 | | - if (!response.ok) { |
23 | | - error = true; |
24 | | - return; |
25 | | - } |
26 | | -
|
27 | | - const markdown = await response.text(); |
28 | | - |
29 | | - // Extract title from first heading |
30 | | - const titleMatch = markdown.match(/^#\s+(.+)$/m); |
31 | | - title = titleMatch ? titleMatch[1] : slug.split('/').pop() || 'Documentation'; |
32 | | - |
33 | | - // Process markdown |
34 | | - content = marked(markdown); |
35 | | - loading = false; |
36 | | - } catch (err) { |
37 | | - console.error('Error loading document:', err); |
38 | | - error = true; |
39 | | - } |
40 | | -}); |
| 7 | +
|
| 8 | +// Process markdown when data changes |
| 9 | +$: { |
| 10 | + if (data.markdown) { |
| 11 | + content = marked(data.markdown); |
| 12 | + } |
| 13 | +} |
41 | 14 | </script> |
42 | 15 |
|
43 | 16 | <svelte:head> |
44 | | - <title>{title || 'Documentation'} - Rhema Documentation</title> |
45 | | - <meta name="description" content="Rhema documentation for {title || 'Documentation'}" /> |
| 17 | + <title>{data.title} - Rhema Documentation</title> |
| 18 | + <meta name="description" content="Rhema documentation for {data.title}" /> |
46 | 19 | </svelte:head> |
47 | 20 |
|
48 | 21 | <div class="docs-page"> |
49 | 22 | <div class="docs-content"> |
50 | 23 | <header class="docs-header"> |
51 | | - <h1>{title || 'Loading...'}</h1> |
| 24 | + <h1>{data.title}</h1> |
52 | 25 | <div class="breadcrumb"> |
53 | | - <a href="/">Home</a> |
| 26 | + <a href="/rhema/">Home</a> |
54 | 27 | <span class="separator">/</span> |
55 | | - <a href="/docs">Documentation</a> |
| 28 | + <a href="/rhema/docs">Documentation</a> |
56 | 29 | <span class="separator">/</span> |
57 | | - <span class="current">{title || 'Loading...'}</span> |
| 30 | + <span class="current">{data.title}</span> |
58 | 31 | </div> |
59 | 32 | </header> |
60 | 33 |
|
61 | | - {#if loading} |
62 | | - <div class="loading"> |
63 | | - <p>Loading documentation...</p> |
64 | | - </div> |
65 | | - {:else if error} |
66 | | - <div class="error"> |
67 | | - <h2>Document Not Found</h2> |
68 | | - <p>The requested documentation page could not be found.</p> |
69 | | - <a href="/docs">Return to Documentation</a> |
70 | | - </div> |
71 | | - {:else} |
72 | | - <article class="markdown-content"> |
73 | | - {@html content} |
74 | | - </article> |
75 | | - {/if} |
| 34 | + <article class="markdown-content"> |
| 35 | + {@html content} |
| 36 | + </article> |
76 | 37 | </div> |
77 | 38 | </div> |
78 | 39 |
|
|
0 commit comments