Compare commits

..

4 Commits

Author SHA1 Message Date
edaf5f5c71
Improve deno tasks 2024-10-22 19:42:02 +02:00
f15e845825
Config UX 2024-10-22 19:41:49 +02:00
453a0f14d3
Support multiple relays for fetching content 2024-10-22 19:41:38 +02:00
856b10358c
Improve layout 2024-10-22 19:16:58 +02:00
6 changed files with 48 additions and 23 deletions

View File

@ -1,6 +1,4 @@
PORT=8000 RELAY_URLS=wss://nostr.kosmos.org,wss://nostr.x0f.org
BASE_URL=http://localhost:8000
HOME_RELAY_URL=wss://nostr.kosmos.org
LDAP_URL=ldap://10.1.1.116:389 LDAP_URL=ldap://10.1.1.116:389
LDAP_BIND_DN=uid=service,ou=kosmos.org,cn=applications,dc=kosmos,dc=org LDAP_BIND_DN=uid=service,ou=kosmos.org,cn=applications,dc=kosmos,dc=org
LDAP_PASSWORD=123456abcdef LDAP_PASSWORD=123456abcdef

View File

@ -108,8 +108,8 @@ main header .meta .name a {
text-decoration: none; text-decoration: none;
} }
main .article-list .item { main.profile-page {
margin-bottom: 3rem; margin-top: 6rem;
} }
main .article-list .item h3 { main .article-list .item h3 {
@ -120,12 +120,16 @@ main .article-list p {
margin-top: 0.5rem; margin-top: 0.5rem;
} }
main .article-list p.meta {
font-size: 1rem;
}
main article footer { main article footer {
margin-top: 5rem; margin-top: 5rem;
} }
.profile-page .about { .profile-page header {
margin-bottom: 3rem; margin-bottom: 2rem;
} }
/* Dropdown menu */ /* Dropdown menu */
@ -194,7 +198,7 @@ main article footer {
main { main {
max-width: 100%; max-width: 100%;
margin: 4rem 1rem 8rem 1rem; margin: 4rem 1rem 8rem 1rem !important;
} }
.profile-page h1 { .profile-page h1 {

View File

@ -10,17 +10,18 @@ let staticUsers;
try { try {
const yamlContent = await Deno.readTextFile(`${dirname}/users.yaml`); const yamlContent = await Deno.readTextFile(`${dirname}/users.yaml`);
staticUsers = parse(yamlContent); staticUsers = parse(yamlContent);
log("Static user config:", "blue"); log(`Serving content for ${Object.keys(staticUsers).length} pubkeys from users.yaml`, "blue");
log(Deno.inspect(staticUsers), "blue");
} catch { } catch {
staticUsers = {}; staticUsers = {};
log(`Could not find or parse a "users.yaml" config`, "yellow"); log(`Could not find or parse a users.yaml config`, "yellow");
} }
const relay_urls = Deno.env.get("RELAY_URLS")?.split(",");
const config = { const config = {
port: Deno.env.get("PORT") || 8000, port: Deno.env.get("PORT") || 8000,
base_url: Deno.env.get("BASE_URL") || `http://localhost:8000`, base_url: Deno.env.get("BASE_URL") || `http://localhost:8000`,
home_relay_url: Deno.env.get("HOME_RELAY_URL") || "", relay_urls,
staticUsers: staticUsers, staticUsers: staticUsers,
ldapEnabled: !!Deno.env.get("LDAP_URL"), ldapEnabled: !!Deno.env.get("LDAP_URL"),
ldap: { ldap: {
@ -31,6 +32,22 @@ const config = {
}, },
}; };
log(`LDAP enabled: ${config.ldapEnabled}`, "blue"); if (config.ldapEnabled && config.ldap.url) {
log(`Serving content for pubkeys from ${config.ldap.url}`, "blue");
} else {
log(`LDAP not enabled`, "blue");
}
if (Object.keys(staticUsers).length === 0 && !config.ldapEnabled) {
log(`Neither static users nor LDAP configured. Nothing to serve.`);
Deno.exit(1);
}
if (config.relay_urls?.length > 0) {
log(`Relays: ${config.relay_urls.join(", ")}`, "green");
} else {
log(`No relays configured. Please add at least one relay to RELAY_URLS.`);
Deno.exit(1);
}
export default config; export default config;

View File

@ -1,7 +1,7 @@
{ {
"tasks": { "tasks": {
"dev": "deno run server", "dev": "deno run --allow-net --allow-read --allow-env --watch server.ts",
"server": "deno run --allow-net --allow-read --allow-env --watch server.ts" "server": "deno run --allow-net --allow-read --allow-env server.ts"
}, },
"imports": { "imports": {
"@deno/gfm": "jsr:@deno/gfm@^0.9.0", "@deno/gfm": "jsr:@deno/gfm@^0.9.0",

View File

@ -77,7 +77,9 @@ function articleListItemHtml(article: Article): string {
return ` return `
<div class="item"> <div class="item">
<h3><a href="/${article.naddr}">${article.title}</a></h3> <h3><a href="/${article.naddr}">${article.title}</a></h3>
<p>${formattedDate}</p> <p class="meta">
${formattedDate}
</p>
</div> </div>
`; `;
} }
@ -111,7 +113,6 @@ export function profilePageHtml(profile: Profile, articles: Article[]): string {
<p class="about"> <p class="about">
${profile.about} ${profile.about}
</p> </p>
</p>
</div> </div>
</header> </header>
<section> <section>

View File

@ -1,4 +1,4 @@
import { NRelay1 } from "@nostrify/nostrify"; import { NPool, NRelay1 } from "@nostrify/nostrify";
import config from "./config.ts"; import config from "./config.ts";
export interface NEvent { export interface NEvent {
@ -11,13 +11,18 @@ export interface NEvent {
tags: Array<[string, string, string?]>; tags: Array<[string, string, string?]>;
} }
export const relay = new NRelay1(config.home_relay_url); const relayPool = new NPool({
open: (url) => new NRelay1(url),
reqRouter: async (filters) => new Map(
config.relay_urls.map(url => [ url, filters ])
)
});
export async function fetchReplaceableEvent( export async function fetchReplaceableEvent(
pubkey: string, pubkey: string,
identifier: string, identifier: string,
) { ) {
let events = await relay.query([{ let events = await relayPool.query([{
authors: [pubkey], authors: [pubkey],
kinds: [30023], kinds: [30023],
"#d": [identifier], "#d": [identifier],
@ -27,7 +32,7 @@ export async function fetchReplaceableEvent(
if (events.length > 0) { if (events.length > 0) {
return events[0]; return events[0];
} else { } else {
events = await relay.query([{ events = await relayPool.query([{
authors: [pubkey], authors: [pubkey],
kinds: [30024], kinds: [30024],
"#d": [identifier], "#d": [identifier],
@ -39,7 +44,7 @@ export async function fetchReplaceableEvent(
} }
export async function fetchArticlesByAuthor(pubkey: string) { export async function fetchArticlesByAuthor(pubkey: string) {
const events = await relay.query([{ const events = await relayPool.query([{
authors: [pubkey], authors: [pubkey],
kinds: [30023], kinds: [30023],
limit: 10, limit: 10,
@ -49,7 +54,7 @@ export async function fetchArticlesByAuthor(pubkey: string) {
} }
export async function fetchProfileEvent(pubkey: string) { export async function fetchProfileEvent(pubkey: string) {
const events = await relay.query([{ const events = await relayPool.query([{
authors: [pubkey], authors: [pubkey],
kinds: [0], kinds: [0],
limit: 1, limit: 1,