Browse Source

Article styles and layout

master
buttercat1791 2 years ago committed by Silberengel
parent
commit
2fd22b6039
  1. 33
      package.json
  2. 8
      pnpm-lock.yaml
  3. 49
      src/app.css
  4. 75
      src/lib/Article.svelte
  5. 2
      src/lib/ArticleHeader.svelte
  6. 6
      src/lib/components/Navigation.svelte
  7. 24
      tailwind.config.cjs

33
package.json

@ -2,6 +2,7 @@
"name": "nostrwiki", "name": "nostrwiki",
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
"build": "vite build", "build": "vite build",
@ -11,10 +12,26 @@
"lint": "prettier --plugin-search-dir . --check . && eslint .", "lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ." "format": "prettier --plugin-search-dir . --write ."
}, },
"dependencies": {
"@nostr-dev-kit/ndk": "^2.3.3",
"@nostr-dev-kit/ndk-cache-dexie": "^2.2.4",
"@popperjs/core": "^2.11.8",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
"markdown-it": "^14.0.0",
"markdown-it-plain-text": "^0.3.0",
"marked": "^11.1.1",
"nostr-tools": "^2.1.4",
"showdown": "^2.1.0",
"svelte-add": "2023.12.16-0.0",
"tailwind-merge": "^2.2.1"
},
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^3.1.1", "@sveltejs/adapter-auto": "^3.1.1",
"@sveltejs/kit": "^2.4.3", "@sveltejs/kit": "^2.4.3",
"@types/markdown-it": "^13.0.7", "@types/markdown-it": "^13.0.7",
"@types/showdown": "^2.0.6",
"autoprefixer": "^10.4.17", "autoprefixer": "^10.4.17",
"eslint-plugin-svelte": "^2.35.1", "eslint-plugin-svelte": "^2.35.1",
"flowbite": "^2.2.1", "flowbite": "^2.2.1",
@ -30,21 +47,5 @@
"tslib": "^2.6.2", "tslib": "^2.6.2",
"typescript": "^5.3.3", "typescript": "^5.3.3",
"vite": "^5.0.12" "vite": "^5.0.12"
},
"type": "module",
"dependencies": {
"@nostr-dev-kit/ndk": "^2.3.3",
"@nostr-dev-kit/ndk-cache-dexie": "^2.2.4",
"@popperjs/core": "^2.11.8",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
"markdown-it": "^14.0.0",
"markdown-it-plain-text": "^0.3.0",
"marked": "^11.1.1",
"nostr-tools": "^2.1.4",
"showdown": "^2.1.0",
"svelte-add": "2023.12.16-0.0",
"tailwind-merge": "^2.2.1"
} }
} }

8
pnpm-lock.yaml

@ -57,6 +57,9 @@ importers:
'@types/markdown-it': '@types/markdown-it':
specifier: ^13.0.7 specifier: ^13.0.7
version: 13.0.7 version: 13.0.7
'@types/showdown':
specifier: ^2.0.6
version: 2.0.6
autoprefixer: autoprefixer:
specifier: ^10.4.17 specifier: ^10.4.17
version: 10.4.17(postcss@8.4.33) version: 10.4.17(postcss@8.4.33)
@ -507,6 +510,9 @@ packages:
'@types/pug@2.0.10': '@types/pug@2.0.10':
resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==} resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==}
'@types/showdown@2.0.6':
resolution: {integrity: sha512-pTvD/0CIeqe4x23+YJWlX2gArHa8G0J0Oh6GKaVXV7TAeickpkkZiNOgFcFcmLQ5lB/K0qBJL1FtRYltBfbGCQ==}
'@typescript-eslint/types@6.21.0': '@typescript-eslint/types@6.21.0':
resolution: {integrity: sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==} resolution: {integrity: sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==}
engines: {node: ^16.0.0 || >=18.0.0} engines: {node: ^16.0.0 || >=18.0.0}
@ -2316,6 +2322,8 @@ snapshots:
'@types/pug@2.0.10': {} '@types/pug@2.0.10': {}
'@types/showdown@2.0.6': {}
'@typescript-eslint/types@6.21.0': {} '@typescript-eslint/types@6.21.0': {}
'@typescript-eslint/typescript-estree@6.21.0(typescript@5.3.3)': '@typescript-eslint/typescript-estree@6.21.0(typescript@5.3.3)':

49
src/app.css

@ -5,16 +5,16 @@
@layer components { @layer components {
/* General */ /* General */
.leather { .leather {
@apply bg-primary-1000 dark:bg-primary-0; @apply bg-primary-0 dark:bg-primary-1000 text-gray-800 dark:text-gray-300;
} }
/* Button */ /* Button */
button.btn-leather.text-white { button.btn-leather.text-white {
@apply text-primary-1000; @apply text-primary-0;
} }
.btn-leather span svg { .btn-leather span svg {
@apply fill-gray-700 hover:fill-primary-400 dark:fill-gray-400 dark:hover:fill-primary-700; @apply fill-gray-800 hover:fill-primary-400 dark:fill-gray-300 dark:hover:fill-primary-500;
} }
.btn-leather.text-xs { .btn-leather.text-xs {
@ -35,7 +35,7 @@
/* Card */ /* Card */
div.card-leather { div.card-leather {
@apply bg-primary-1000 dark:bg-primary-0 border-gray-200 has-[:hover]:border-primary-400 dark:border-gray-700 dark:has-[:hover]:border-primary-700; @apply bg-primary-0 dark:bg-primary-1000 border-gray-200 has-[:hover]:border-primary-800 dark:border-gray-800 dark:has-[:hover]:border-primary-500;
} }
div.card-leather h1, div.card-leather h1,
@ -44,12 +44,26 @@
div.card-leather h4, div.card-leather h4,
div.card-leather h5, div.card-leather h5,
div.card-leather h6 { div.card-leather h6 {
@apply text-gray-700 hover:text-primary-400 dark:text-gray-400 dark:hover:text-primary-700; @apply text-gray-800 hover:text-primary-400 dark:text-gray-300 dark:hover:text-primary-500;
}
/* Content */
div.note-leather {
@apply bg-primary-0 dark:bg-primary-1000 text-gray-800 dark:text-gray-300 hover:bg-primary-100 dark:hover:bg-primary-800 p-2 rounded;
}
/* Heading */
h1.h-leather,
h2.h-leather,
h3.h-leather,
h4.h-leather,
h5.h-leather {
@apply text-gray-800 dark:text-gray-300;
} }
/* Modal */ /* Modal */
div.modal-leather > div { div.modal-leather > div {
@apply bg-primary-1000 dark:bg-primary-0 border-b-[1px] border-gray-700 dark:border-gray-400; @apply bg-primary-0 dark:bg-primary-1000 border-b-[1px] border-gray-800 dark:border-gray-500;
} }
div.modal-leather > div > h1, div.modal-leather > div > h1,
@ -58,20 +72,20 @@
div.modal-leather > div > h4, div.modal-leather > div > h4,
div.modal-leather > div > h5, div.modal-leather > div > h5,
div.modal-leather > div > h6 { div.modal-leather > div > h6 {
@apply text-gray-700 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-400; @apply text-gray-800 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-300;
} }
div.modal-leather button { div.modal-leather button {
@apply bg-primary-1000 hover:bg-primary-1000 dark:bg-primary-0 dark:hover:bg-primary-0 text-gray-700 hover:text-primary-400 dark:text-gray-400 dark:hover:text-primary-700; @apply bg-primary-0 hover:bg-primary-0 dark:bg-primary-1000 dark:hover:bg-primary-1000 text-gray-800 hover:text-primary-400 dark:text-gray-300 dark:hover:text-primary-500;
} }
/* Navbar */ /* Navbar */
nav.navbar-leather { nav.navbar-leather {
@apply bg-primary-1000 dark:bg-primary-0; @apply bg-primary-0 dark:bg-primary-1000;
} }
nav.navbar-leather svg { nav.navbar-leather svg {
@apply fill-gray-700 hover:fill-primary-400 dark:fill-gray-400 dark:hover:fill-primary-700; @apply fill-gray-800 hover:fill-primary-400 dark:fill-gray-300 dark:hover:fill-primary-500;
} }
nav.navbar-leather h1, nav.navbar-leather h1,
@ -80,16 +94,25 @@
nav.navbar-leather h4, nav.navbar-leather h4,
nav.navbar-leather h5, nav.navbar-leather h5,
nav.navbar-leather h6 { nav.navbar-leather h6 {
@apply text-gray-700 hover:text-primary-400 dark:text-gray-400 dark:hover:text-primary-700; @apply text-gray-800 hover:text-primary-400 dark:text-gray-300 dark:hover:text-primary-500;
}
/* Sidebar */
aside.sidebar-leather > div {
@apply bg-gray-100 dark:bg-gray-900;
}
a.sidebar-item-leather {
@apply hover:bg-primary-100 dark:hover:bg-primary-800;
} }
/* Tooltip */ /* Tooltip */
div.tooltip-leather { div.tooltip-leather {
@apply text-gray-700 dark:text-gray-400; @apply text-gray-800 dark:text-gray-300;
} }
/* Unordered list */ /* Unordered list */
.ul-leather li a { .ul-leather li a {
@apply text-gray-700 hover:text-primary-400 dark:text-gray-400 dark:hover:text-primary-700; @apply text-gray-800 hover:text-primary-400 dark:text-gray-300 dark:hover:text-primary-500;
} }
} }

75
src/lib/Article.svelte

@ -1,46 +1,73 @@
<script lang="ts"> <script lang="ts">
import { ndk } from '$lib/ndk'; import { ndk } from '$lib/ndk';
import Toc from '$lib/components/Toc.svelte';
import Notes from '$lib/components/Note.svelte';
import { idList } from '$lib/stores'; import { idList } from '$lib/stores';
import type { NDKEvent } from '@nostr-dev-kit/ndk'; import type { NDKEvent } from '@nostr-dev-kit/ndk';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { Sidebar, SidebarGroup, SidebarItem, SidebarWrapper } from 'flowbite-svelte'; import { Heading, Sidebar, SidebarGroup, SidebarItem, SidebarWrapper, Skeleton, TextPlaceholder } from 'flowbite-svelte';
import showdown from 'showdown';
import { sineIn } from 'svelte/easing';
import { onMount } from 'svelte';
$: activeUrl = $page.url.pathname; $: activeHash = $page.url.hash;
let events: NDKEvent[] = []; async function getEvents(): Promise<NDKEvent[]> {
const eventPromises = $idList.map(async (id) => await $ndk.fetchEvent(id));
async function getEvents() { const events = await Promise.all(eventPromises);
$idList.forEach(async (id) => { return events.filter((event) => event != null);
const event = await $ndk.fetchEvent(id);
events = [...events, event];
});
} }
const converter = new showdown.Converter();
const transitionParams = {
x: -320,
duration: 200,
easing: sineIn
};
let width: number;
let breakpoint: number = 768; // Tailwind md breakpoint
let drawerHidden: boolean = false;
$: width >= breakpoint
? drawerHidden = false
: drawerHidden = true;
onMount(() => {
width >= breakpoint
? drawerHidden = false
: drawerHidden = true;
});
</script> </script>
{#await getEvents() then article} {#await getEvents()}
<Sidebar {activeUrl}> <Sidebar class='sidebar-leather fixed top-20 left-0 px-4 w-60'>
<SidebarWrapper>
<Skeleton/>
</SidebarWrapper>
</Sidebar>
<TextPlaceholder class='max-w-2xl'/>
{:then events}
<!-- TODO: Collapse the sidebar when the page gets below a certain width. -->
<!-- TODO: Handle hash paths for navigation within the article. -->
<Sidebar class='sidebar-leather fixed top-20 left-0 px-4 w-60' {activeHash}>
<SidebarWrapper> <SidebarWrapper>
<SidebarGroup> <SidebarGroup>
{#each events as event} {#each events as event}
<SidebarItem <SidebarItem
title={event.getMatchingTags('title')[0][1]} class='sidebar-item-leather'
href={nip19.noteEncode(event.id)} label={event.getMatchingTags('title')[0][1]}
href={`${$page.url.pathname}#${event.getMatchingTags('title')[0][1]}`}
/> />
{/each} {/each}
</SidebarGroup> </SidebarGroup>
</SidebarWrapper> </SidebarWrapper>
</Sidebar> </Sidebar>
<!-- <div class="article"> <div class='flex flex-col space-y-4 max-w-2xl'>
<div class="toc"> {#each events as event}
<Toc notes={events} /> <div class='note-leather flex flex-col space-y-2'>
</div> <Heading tag='h3' class='h-leather'>{event.getMatchingTags('title')[0][1]}</Heading>
{@html converter.makeHtml(event.content)}
<div class="article-content"> </div>
<Notes notes={events} /> {/each}
</div> </div>
</div> -->
{/await} {/await}
<style> <style>

2
src/lib/ArticleHeader.svelte

@ -51,7 +51,7 @@
} }
</script> </script>
<Card class='ArticleBox card-leather w-80'> <Card class='ArticleBox card-leather w-lg'>
<div class='flex flex-col space-y-4'> <div class='flex flex-col space-y-4'>
<a href="/{href}" on:click={handleSendEvents}> <a href="/{href}" on:click={handleSendEvents}>
<h2>{title}</h2> <h2>{title}</h2>

6
src/lib/components/Navigation.svelte

@ -1,6 +1,5 @@
<script lang="ts"> <script lang="ts">
import { DarkMode, Navbar, NavLi, NavUl, NavHamburger, NavBrand } from 'flowbite-svelte'; import { DarkMode, Navbar, NavLi, NavUl, NavHamburger, NavBrand } from 'flowbite-svelte';
import { HomeSolid } from 'flowbite-svelte-icons';
let className: string; let className: string;
export { className as class }; export { className as class };
@ -11,8 +10,6 @@
<NavBrand href='./'> <NavBrand href='./'>
<h1 class='font-serif'>Alexandria</h1> <h1 class='font-serif'>Alexandria</h1>
</NavBrand> </NavBrand>
<!-- TODO: Restyle the dark mode icon. -->
<DarkMode btnClass='btn-leather p-4'/>
</div> </div>
<NavHamburger class='btn-leather' /> <NavHamburger class='btn-leather' />
<NavUl class='ul-leather'> <NavUl class='ul-leather'>
@ -20,5 +17,8 @@
<NavLi href='./create'>New Note</NavLi> <NavLi href='./create'>New Note</NavLi>
<NavLi href='./visualize'>Visualize</NavLi> <NavLi href='./visualize'>Visualize</NavLi>
<NavLi href='./login'>Login</NavLi> <NavLi href='./login'>Login</NavLi>
<NavLi>
<DarkMode btnClass='btn-leather p-0'/>
</NavLi>
</NavUl> </NavUl>
</Navbar> </Navbar>

24
tailwind.config.cjs

@ -12,18 +12,18 @@ const config = {
extend: { extend: {
colors: { colors: {
primary: { primary: {
0: '#110d08', 0: '#efe6dc',
50: '#231a10', 50: '#decdb9',
100: '#342718', 100: '#d6c1a8',
200: '#574229', 200: '#c6a885',
300: '#795c39', 300: '#b58f62',
400: '#9c7649', 400: '#ad8351',
500: '#ad8351', 500: '#9c7649',
600: '#b58f62', 600: '#795c39',
700: '#c6a885', 700: '#574229',
800: '#d6c1a8', 800: '#342718',
900: '#decdb9', 900: '#231a10',
1000: '#efe6dc', 1000: '#110d08',
}, },
} }
}, },

Loading…
Cancel
Save