Skip to content

Commit

Permalink
Merge pull request #1511 from SnowCait/fix-ogp
Browse files Browse the repository at this point in the history
Fix OGP
  • Loading branch information
SnowCait authored Nov 12, 2024
2 parents 1a1f27d + 73b21c9 commit 87c501b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 34 deletions.
3 changes: 3 additions & 0 deletions web/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"app": {
"description": "Nostr client for web."
},
"layout": {
"header": {
"home": "Home",
Expand Down
3 changes: 3 additions & 0 deletions web/src/lib/i18n/locales/ja.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"app": {
"description": "Web 向け Nostr クライアント。"
},
"layout": {
"header": {
"home": "ホーム",
Expand Down
29 changes: 24 additions & 5 deletions web/src/routes/(app)/[slug=npub]/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
import type { Event } from 'nostr-typedef';
import type { LayoutServerLoad } from './$types';
import { storeMetadata } from '$lib/cache/Events';
import { metadataStore, storeMetadata } from '$lib/cache/Events';
import { checkRestriction } from '$lib/server/Restriction';
import { fetchMetadata } from '$lib/Api';
import { defaultRelays } from '$lib/Constants';
import { appName, defaultRelays } from '$lib/Constants';
import { User } from '$lib/User';

export const load: LayoutServerLoad<{
type Data = {
pubkey: string;
relays: string[];
metadataEvent: Event | undefined;
}> = async ({ params }) => {
title: string;
description: string;
image?: string;
};

export const load: LayoutServerLoad<Data> = async ({ params }) => {
console.log('[npub page load]', params.slug);
console.time('[npub decode]');
const { pubkey, relays } = await User.decode(params.slug);
Expand All @@ -33,5 +39,18 @@ export const load: LayoutServerLoad<{
storeMetadata(metadataEvent);
}

return { pubkey, relays, metadataEvent };
const $metadataStore = get(metadataStore);
const metadata = $metadataStore.get(pubkey);

const data: Data = {
pubkey,
relays,
metadataEvent,
title: `${appName} - ${metadata?.displayName ?? 'ghost'}`,
description: metadata?.about ?? ''
};
if (metadata?.picture) {
data.image = metadata.picture;
}
return data;
};
13 changes: 1 addition & 12 deletions web/src/routes/(app)/[slug=npub]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { pubkey as authorPubkey, readRelays } from '$lib/stores/Author';
import { Timeline } from '$lib/Timeline';
import { EventItem } from '$lib/Items';
import { appName, minTimelineLength } from '$lib/Constants';
import { minTimelineLength } from '$lib/Constants';
import { replaceableEvents, replaceableEventsReqEmit } from '$lib/Profile';
import type { LayoutData } from './$types';
import { developerMode } from '$lib/stores/Preference';
Expand Down Expand Up @@ -157,17 +157,6 @@
}
</script>

<svelte:head>
{#if metadata !== undefined}
<title>{appName} - {metadata.displayName} (@{metadata.name})</title>
<meta property="og:title" content={metadata.displayName} />
<meta property="og:description" content={metadata.about} />
<meta property="og:image" content={metadata.picture} />
{:else}
<title>{appName} - ghost</title>
{/if}
</svelte:head>

<section class="card profile-wrapper">
<Profile {slug} pubkey={data.pubkey} {metadata} {relays} />
</section>
Expand Down
6 changes: 0 additions & 6 deletions web/src/routes/(app)/home/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { onMount } from 'svelte';
import { _ } from 'svelte-i18n';
import { uniq, type LazyFilter, createRxBackwardReq } from 'rx-nostr';
import { tap } from 'rxjs';
import { Kind, type Relay } from 'nostr-tools';
Expand All @@ -14,7 +13,6 @@
import { referencesReqEmit, rxNostr, storeSeenOn } from '$lib/timelines/MainTimeline';
import { hasSubscribed, hometimelineReqEmit } from '$lib/timelines/HomeTimeline';
import {
appName,
notificationsFilterKinds,
minTimelineLength,
reverseChronologicalItem
Expand Down Expand Up @@ -238,10 +236,6 @@
}
</script>

<svelte:head>
<title>{appName} - {$_('layout.header.home')}</title>
</svelte:head>

<HomeTab selected="home" />

{#if $eventsPool.length > 0}
Expand Down
11 changes: 11 additions & 0 deletions web/src/routes/(app)/home/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { _ } from 'svelte-i18n';
import { appName } from '$lib/Constants';
import type { PageLoad } from './$types';
import { get } from 'svelte/store';

export const load: PageLoad = () => {
const $_ = get(_);
return {
title: `${appName} - ${$_('layout.header.home')}`
};
};
12 changes: 5 additions & 7 deletions web/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import { page } from '$app/stores';
import { appName } from '$lib/Constants';
import '../app.css';
const description = 'Nostr client for web.';
</script>

<svelte:head>
<title>{appName}</title>
<meta name="description" content={description} />
<meta property="og:title" content={appName} />
<title>{$page.data.title}</title>
<meta name="description" content={$page.data.description} />
<meta property="og:title" content={$page.data.title} />
<meta property="og:type" content="website" />
<meta property="og:image" content={`${$page.url.origin}/logo.png`} />
<meta property="og:image" content={$page.data.image} />
<meta property="og:url" content={$page.url.href} />
<meta property="og:description" content={description} />
<meta property="og:description" content={$page.data.description} />
<meta property="og:site_name" content={appName} />
<meta name="twitter:card" content="summary" />
<style>
Expand Down
12 changes: 8 additions & 4 deletions web/src/routes/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { get } from 'svelte/store';
import { locale, waitLocale } from 'svelte-i18n';
import { _, locale, waitLocale } from 'svelte-i18n';
import { browser } from '$app/environment';
import { Login } from '$lib/Login';
import { WebStorage } from '$lib/WebStorage';
import '$lib/i18n';
import { rxNostr } from '$lib/timelines/MainTimeline';
import { defaultRelays, localizedRelays } from '$lib/Constants';
import { appName, defaultRelays, localizedRelays } from '$lib/Constants';
import type { LayoutLoad } from './$types';
import { readRelays, writeRelays } from '$lib/stores/Author';

export const load: LayoutLoad = async () => {
export const load: LayoutLoad = async ({ url }) => {
console.debug('[layout load]');
let authenticated = false;
if (browser) {
Expand All @@ -32,9 +32,13 @@ export const load: LayoutLoad = async () => {
authenticated = await tryLogin();
}
await waitLocale();
const $_ = get(_);
return {
splash: !browser || authenticated,
authenticated
authenticated,
title: appName,
description: $_('app.description'),
image: `${url.origin}/logo.png`
};
};

Expand Down

0 comments on commit 87c501b

Please sign in to comment.