Files
archtika/web-app/src/lib/components/WebsiteEditor.svelte

85 lines
1.5 KiB
Svelte
Raw Normal View History

2024-08-01 18:09:35 +02:00
<script lang="ts">
import type { Snippet } from "svelte";
2024-08-03 13:49:41 +02:00
import markdownit from "markdown-it";
import hljs from "highlight.js";
2024-08-01 18:09:35 +02:00
const {
id,
title,
children,
fullPreview = false,
previewContent
} = $props<{
2024-08-01 18:09:35 +02:00
id: string;
title: string;
children: Snippet;
fullPreview?: boolean;
2024-08-01 18:09:35 +02:00
previewContent: string;
}>();
2024-08-03 13:49:41 +02:00
const md = markdownit({
linkify: true,
typographer: true,
highlight: (str, lang) => {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(str, { language: lang }).value;
} catch (_) {}
}
return "";
}
});
2024-08-01 18:09:35 +02:00
</script>
<div class="operations">
<h1>{title}</h1>
2024-08-02 15:33:18 +02:00
<nav class="operations__nav">
2024-08-01 18:09:35 +02:00
<a href="/website/{id}">Settings</a>
<a href="/website/{id}/articles">Articles</a>
<a href="/website/{id}/publish">Publish</a>
2024-08-02 15:33:18 +02:00
</nav>
2024-08-01 18:09:35 +02:00
{@render children()}
</div>
<div class="preview">
{#if fullPreview}
<iframe src={previewContent} title="Preview"></iframe>
{:else}
{@html md.render(previewContent)}
{/if}
2024-08-01 18:09:35 +02:00
</div>
<style>
.operations,
.preview {
padding: 1rem;
2024-08-03 13:49:41 +02:00
overflow-y: auto;
2024-08-01 18:09:35 +02:00
}
.operations {
2024-08-02 15:33:18 +02:00
border-inline-end: var(--border-primary);
2024-08-01 18:09:35 +02:00
}
2024-08-02 15:33:18 +02:00
.operations__nav {
margin-block: 1rem 2rem;
display: flex;
gap: 1rem;
2024-08-02 15:33:18 +02:00
overflow-x: auto;
}
2024-08-01 18:09:35 +02:00
.preview {
2024-08-03 13:49:41 +02:00
display: flex;
flex-direction: column;
gap: 1rem;
2024-08-01 18:09:35 +02:00
}
iframe {
inline-size: 100%;
block-size: 100%;
border: var(--border-primary);
}
2024-08-01 18:09:35 +02:00
</style>