Browse Source

Add auto-author functionality and move publish button

- Auto-add author identity when not publishing on behalf of others
- Check for existing :author: and :p: tags, only add if missing
- Add ["author", displayName] and ["p", pubkey] tags automatically
- Move publish button from top gradient to underneath text area
- Preserve smart color functionality: blue for articles, green for notes
- Position publish button next to preview button for better UX

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
master
limina1 7 months ago
parent
commit
088dc453bb
  1. 45
      src/lib/components/ZettelEditor.svelte
  2. 19
      src/lib/services/publisher.ts

45
src/lib/components/ZettelEditor.svelte

@ -185,29 +185,6 @@ Understanding the nature of knowledge itself...
{/if} {/if}
</div> </div>
<!-- Unified Publishing Button -->
<div class="flex space-x-2">
{#if generatedEvents && contentType !== 'none'}
<Button
color={contentType === 'article' ? 'blue' : 'green'}
size="sm"
on:click={handlePublish}
class="flex items-center space-x-1"
>
{#if contentType === 'article'}
<span>📚 Publish Article</span>
<span class="text-xs opacity-75">({generatedEvents.contentEvents.length + 1} events)</span>
{:else}
<span>📝 Publish Notes</span>
<span class="text-xs opacity-75">({generatedEvents.contentEvents.length} events)</span>
{/if}
</Button>
{:else}
<div class="text-xs text-gray-500 dark:text-gray-400 italic">
Add content to enable publishing
</div>
{/if}
</div>
</div> </div>
</div> </div>
</div> </div>
@ -227,6 +204,28 @@ Understanding the nature of knowledge itself...
<span>Show Preview</span> <span>Show Preview</span>
{/if} {/if}
</Button> </Button>
<!-- Smart Publishing Button -->
{#if generatedEvents && contentType !== 'none'}
<Button
color={contentType === 'article' ? 'blue' : 'green'}
size="sm"
on:click={handlePublish}
class="flex items-center space-x-1"
>
{#if contentType === 'article'}
<span>📚 Publish Article</span>
<span class="text-xs opacity-75">({generatedEvents.contentEvents.length + 1} events)</span>
{:else}
<span>📝 Publish Notes</span>
<span class="text-xs opacity-75">({generatedEvents.contentEvents.length} events)</span>
{/if}
</Button>
{:else}
<div class="text-xs text-gray-500 dark:text-gray-400 italic">
Add content to enable publishing
</div>
{/if}
</div> </div>
<div class="flex space-x-4 {showPreview ? 'h-96' : ''}"> <div class="flex space-x-4 {showPreview ? 'h-96' : ''}">

19
src/lib/services/publisher.ts

@ -143,11 +143,28 @@ export async function publishSingleEvent(
return tag; return tag;
}); });
// Auto-add author identity if not publishing on behalf of others
const hasAuthorTag = fixedTags.some(tag => tag[0] === 'author');
const hasPTag = fixedTags.some(tag => tag[0] === 'p');
const finalTags = [...fixedTags];
if (!hasAuthorTag && ndk.activeUser) {
// Add display name as author
const displayName = ndk.activeUser.profile?.displayName || ndk.activeUser.profile?.name || 'Anonymous';
finalTags.push(['author', displayName]);
}
if (!hasPTag && ndk.activeUser) {
// Add pubkey as p-tag
finalTags.push(['p', ndk.activeUser.pubkey]);
}
// Create and sign NDK event // Create and sign NDK event
const ndkEvent = new NDKEvent(ndk); const ndkEvent = new NDKEvent(ndk);
ndkEvent.kind = kind; ndkEvent.kind = kind;
ndkEvent.created_at = Math.floor(Date.now() / 1000); ndkEvent.created_at = Math.floor(Date.now() / 1000);
ndkEvent.tags = fixedTags; ndkEvent.tags = finalTags;
ndkEvent.content = content; ndkEvent.content = content;
ndkEvent.pubkey = ndk.activeUser.pubkey; ndkEvent.pubkey = ndk.activeUser.pubkey;

Loading…
Cancel
Save