From 39419d38f4b06208469dd4a39ffdde5d4b6b0b66 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Tue, 20 May 2025 06:17:34 +0200 Subject: [PATCH] Remove wiki stuff and update readme for issue #173 --- README.md | 12 +- src/lib/components/Navigation.svelte | 2 - src/lib/components/WikiCard.svelte | 49 ---- src/lib/wiki.ts | 184 --------------- src/routes/wiki/+page.svelte | 323 --------------------------- src/routes/wiki/+page.ts | 25 --- 6 files changed, 7 insertions(+), 588 deletions(-) delete mode 100644 src/lib/components/WikiCard.svelte delete mode 100644 src/lib/wiki.ts delete mode 100644 src/routes/wiki/+page.svelte delete mode 100644 src/routes/wiki/+page.ts diff --git a/README.md b/README.md index f82fb12..1438b73 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,15 @@ # Alexandria Alexandria is a reader and writer for curated publications, including e-books. -For a thorough introduction, please refer to our [project documention](./publication?d=gitcitadel-project-documentation-by-stella-v-1), viewable on Alexandria, or to the Alexandria [About page](./about). +For a thorough introduction, please refer to our [project documention](https://next-alexandria.gitcitadel.eu/publication?d=gitcitadel-project-documentation-by-stella-v-1), viewable on Alexandria, or to the Alexandria [About page](https://next-alexandria.gitcitadel.eu/about). + +It also contains a [universal event viewer](https://next-alexandria.gitcitadel.eu/events), with which you can search our relays, some aggregator relays, and your own relay list, to find and view event data. ## Issues and Patches -If you would like to suggest a feature or report a bug, please use the [Alexandria Contact page](./contact). +If you would like to suggest a feature or report a bug, please use the [Alexandria Contact page](https://next-alexandria.gitcitadel.eu/contact). -You can also contact us [on Nostr](./events?id=nprofile1qqsggm4l0xs23qfjwnkfwf6fqcs66s3lz637gaxhl4nwd2vtle8rnfqprfmhxue69uhhg6r9vehhyetnwshxummnw3erztnrdaks5zhueg), directly. +You can also contact us [on Nostr](https://next-alexandria.gitcitadel.eu/events?id=nprofile1qqsggm4l0xs23qfjwnkfwf6fqcs66s3lz637gaxhl4nwd2vtle8rnfqprfmhxue69uhhg6r9vehhyetnwshxummnw3erztnrdaks5zhueg), directly. ## Developing @@ -73,7 +75,7 @@ To run the container, in detached mode (-d): docker run -d --rm --name=gc-alexandria -p 4174:80 gc-alexandria ``` -The container is then viewable on your [local machine](./). +The container is then viewable on your [local machine](http://localhost:4174). If you want to see the container process (assuming it's the last process to start), enter: @@ -118,4 +120,4 @@ npx playwright test ## Markup Support -Alexandria supports both Markdown and AsciiDoc markup for different content types. For a detailed list of supported tags and features in the basic and advanced markdown parsers, as well as information about AsciiDoc usage for publications and wikis, see [MarkupInfo.md](./src/lib/utils/markup/MarkupInfo.md). \ No newline at end of file +Alexandria supports both Markdown and AsciiDoc markup for different content types. For a detailed list of supported tags and features in the basic and advanced markdown parsers, as well as information about AsciiDoc usage for publications and wikis, see [MarkupInfo.md](https://next-alexandria.gitcitadel.eu/src/lib/utils/markup/MarkupInfo.md). \ No newline at end of file diff --git a/src/lib/components/Navigation.svelte b/src/lib/components/Navigation.svelte index 986f246..d8503bd 100644 --- a/src/lib/components/Navigation.svelte +++ b/src/lib/components/Navigation.svelte @@ -10,7 +10,6 @@ import Login from "./Login.svelte"; let { class: className = "" } = $props(); - @@ -25,7 +24,6 @@ Publications - Wiki Events Visualize Getting Started diff --git a/src/lib/components/WikiCard.svelte b/src/lib/components/WikiCard.svelte deleted file mode 100644 index ae84c7f..0000000 --- a/src/lib/components/WikiCard.svelte +++ /dev/null @@ -1,49 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/lib/wiki.ts b/src/lib/wiki.ts deleted file mode 100644 index f329590..0000000 --- a/src/lib/wiki.ts +++ /dev/null @@ -1,184 +0,0 @@ -import { parseBasicmarkup } from './utils/markup/basicMarkupParser'; -import { getUserMetadata, fetchEventWithFallback } from './utils/nostrUtils'; -import { get } from 'svelte/store'; -import { ndkInstance } from '$lib/ndk'; -import { nip19 } from 'nostr-tools'; -import type { NDKEvent } from '@nostr-dev-kit/ndk'; -import type NDK from '@nostr-dev-kit/ndk'; -import Pharos from '$lib/parser.ts'; -import { wikiKind } from './consts'; - -/** - * Fetch a single wiki event by id (hex or bech32). - */ -export async function fetchWikiEventById(id: string): Promise { - const ndk = get(ndkInstance); - if (!ndk) { - console.warn('NDK instance not found in fetchWikiEventById'); - return null; - } - - let eventId = id; - if (id.startsWith('nevent') || id.startsWith('note') || id.startsWith('naddr')) { - try { - const decoded = nip19.decode(id); - if (decoded.type === 'nevent') { - eventId = decoded.data.id; - } else if (decoded.type === 'note') { - eventId = decoded.data; - } - } catch (e) { - console.error('Failed to decode id in fetchWikiEventById:', e); - return null; - } - } - - const event = await fetchEventWithFallback(ndk, eventId); - if (event && event.kind === wikiKind) { - console.log('Fetched wiki event:', event); - return event; - } - console.warn('No wiki event found for id:', eventId); - return null; -} - -/** - * Fetch all wiki events by d-tag. - */ -export async function fetchWikiEventsByDTag(dtag: string): Promise { - const ndk = get(ndkInstance); - if (!ndk) { - console.warn('NDK instance not found in fetchWikiEventsByDTag'); - return []; - } - - const event = await fetchEventWithFallback(ndk, { - kinds: [wikiKind], - '#d': [dtag] - }); - - if (!event) { - console.warn(`No wiki events found for dtag: ${dtag}`); - return []; - } - - // For d-tag queries, we want to get all matching events, not just the first one - const events = await ndk.fetchEvents({ - kinds: [wikiKind], - '#d': [dtag] - }); - - const arr = Array.from(events); - console.log(`Fetched ${arr.length} wiki events for dtag:`, dtag); - return arr; -} - -/** - * Get a display name for a pubkey. - */ -export async function getProfileName(pubkey: string): Promise { - if (!pubkey) return 'unknown'; - const metadata = await getUserMetadata(pubkey); - return metadata.displayName || metadata.name || pubkey.slice(0, 10); -} - -/** - * Fetch and parse a wiki page by event id or nevent. - */ -export async function getWikiPageById(id: string, ndk: NDK) { - console.log('getWikiPageById: fetching wiki page for id', id); - if (!id) { - console.error('getWikiPageById: id is undefined'); - return null; - } - - let event; - try { - event = await fetchEventWithFallback(ndk, id); - if (!event) { - console.error('getWikiPageById: No event found for id:', id); - return null; - } - if (event.kind !== wikiKind) { - console.error('getWikiPageById: Event found but kind !== wikiKind:', event); - return null; - } - if (!event.content) { - console.error('getWikiPageById: Event has no content:', event); - return null; - } - if (!event.tags) { - console.error('getWikiPageById: Event has no tags:', event); - return null; - } - } catch (err) { - console.error('getWikiPageById: Exception fetching event:', err, 'id:', id); - return null; - } - - const pubhex = event.pubkey || ''; - const titleTag = event.tags.find((tag: string[]) => tag[0] === 'title'); - const title = titleTag ? titleTag[1] : 'Untitled'; - const summaryTag = event.tags.find((tag: string[]) => tag[0] === 'summary'); - const summary = summaryTag ? summaryTag[1] : ''; - const hashtags = event.tags.filter((tag: string[]) => tag[0] === 't').map((tag: string[]) => tag[1]) || []; - - let asciidoc = event.content; - if (!/^=\s/m.test(asciidoc)) { - console.warn('getWikiPageById: No document header found, prepending fake header for title:', title); - asciidoc = `= ${title}\n\n` + asciidoc; - } - - let html = ''; - try { - const pharos = new Pharos(ndk); - console.log('Pharos instance:', pharos); - pharos.parse(asciidoc); - const pharosHtml = pharos.getHtml(); - console.log('AsciiDoc:', asciidoc); - console.log('Pharos HTML:', pharosHtml); - html = await parseBasicmarkup(pharosHtml ?? ''); - if (!html || html.trim() === '') { - console.error('getWikiPageById: Parsed HTML is empty for id:', id, 'event:', event, 'asciidoc:', asciidoc, 'pharosHtml:', pharosHtml); - } - } catch (err) { - console.error('getWikiPageById: Error parsing content:', err, 'event:', event); - return null; - } - - return { title, pubhex, eventId: event.id, summary, hashtags, html, content: event.content }; -} - -/** - * Search wiki pages by d-tag. - */ -export async function searchWikiPagesByDTag(dtag: string) { - const events = await fetchWikiEventsByDTag(dtag); - return Promise.all(events.map(async (event: NDKEvent) => { - const pubhex = event.pubkey || ''; - const titleTag = event.tags?.find((tag: string[]) => tag[0] === 't'); - const title = titleTag ? titleTag[1] : 'Untitled'; - const summaryTag = event.tags?.find((tag: string[]) => tag[0] === 'summary'); - const summary = summaryTag ? summaryTag[1] : ''; - const metadata = await getUserMetadata(pubhex); - const nip05 = metadata.nip05 || ''; - const urlPath = nip05 ? `${dtag}/${nip05}` : `${dtag}*${pubhex}`; - return { - title, - pubhex, - eventId: event.id, - summary, - urlPath - }; - })); -} - -/** - * Parse wiki content using Pharos and basic markup parser. - */ -export async function parseWikiContent(content: string, ndk: NDK): Promise { - const pharos = new Pharos(ndk); - pharos.parse(content); - const pharosHtml = pharos.getHtml(); - return await parseBasicmarkup(pharosHtml); -} \ No newline at end of file diff --git a/src/routes/wiki/+page.svelte b/src/routes/wiki/+page.svelte deleted file mode 100644 index 466de75..0000000 --- a/src/routes/wiki/+page.svelte +++ /dev/null @@ -1,323 +0,0 @@ - - -
-
- { - if (wikiPage) { - wikiPage = null; - wikiContent = null; - } - fetchResults(searchInput); - }} - autocomplete="off" - class="w-full px-6 py-4 rounded-2xl border border-primary-200 shadow bg-primary-50 focus:outline-none focus:ring-2 focus:ring-primary-400 text-lg transition" - /> -
- - {#if loading} -
-
-

Loading wiki content...

-
- {:else if error} -
-

{error}

-
- {:else if wikiPage && wikiContent} -
-
{getNevent(wikiPage.eventId)}
-

{wikiPage.title}

-
- by -
- {#if wikiPage.hashtags.length} -
- {#each wikiPage.hashtags as tag} - #{tag} - {/each} -
- {/if} - {#if wikiPage.summary} -
{wikiPage.summary}
- {/if} -
- {#if wikiPage.html && wikiPage.html.trim().length > 0} - {@html wikiPage.html} - {:else} -
- No content found for this wiki page. - {#if wikiPage.content} -
-                {wikiPage.content}
-              
- {/if} -
-              {JSON.stringify(wikiPage, null, 2)}
-            
-
- {/if} -
-
- {:else if !searchInput} -
-

- Welcome to the Alexandria Wiki! -

-

- Use the search bar above to find wiki pages on any topic. - Alexandria wiki pages are stored on Nostr relays and can be collaboratively added to by anyone with a Nostr key. - Search by topic, and you'll see all relevant wiki pages, each signed by its author. -

-
- {:else if results.length === 0} -

No entries found for this topic.

- {:else} -
- {#each results as result} - - {/each} -
- {/if} -
\ No newline at end of file diff --git a/src/routes/wiki/+page.ts b/src/routes/wiki/+page.ts deleted file mode 100644 index c009f61..0000000 --- a/src/routes/wiki/+page.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { Load } from '@sveltejs/kit'; -import { getWikiPageById, searchWikiPagesByDTag } from '../../lib/wiki'; - -export const load: Load = async ({ url }) => { - const id = url.searchParams.get('id'); - const d = url.searchParams.get('d'); - - if (d) { - // Disambiguation/search page for d-tag - const results = await searchWikiPagesByDTag(d); - return { disambiguation: true, results, dtag: d }; - } - - if (id) { - // Single wiki page by event id (bech32 or hex) - const page = await getWikiPageById(id); - if (!page) { - return { status: 404, error: 'Wiki page not found.' }; - } - return { disambiguation: false, page }; - } - - // No query: show only the search bar - return { disambiguation: true, results: [], dtag: '' }; -}; \ No newline at end of file