A calm place to write long-form, and publish it to the open social web. skypress.blog/
0

Configure Feed

Select the types of activity you want to include in your feed.

Add edit-link helpers for dashboard→editor editing

+41
+23
src/lib/editor/edit-link.test.ts
··· 1 + import { describe, expect, it } from 'vitest'; 2 + import { editLinkFor, editRkeyFromSearch } from './edit-link'; 3 + 4 + describe( 'editLinkFor', () => { 5 + it( 'builds the editor edit URL for an rkey', () => { 6 + expect( editLinkFor( '3kabc123' ) ).toBe( '/editor?edit=3kabc123' ); 7 + } ); 8 + } ); 9 + 10 + describe( 'editRkeyFromSearch', () => { 11 + it( 'reads the rkey from the edit param', () => { 12 + expect( editRkeyFromSearch( '?edit=3kabc123' ) ).toBe( '3kabc123' ); 13 + } ); 14 + 15 + it( 'returns null when the param is absent', () => { 16 + expect( editRkeyFromSearch( '?foo=bar' ) ).toBeNull(); 17 + expect( editRkeyFromSearch( '' ) ).toBeNull(); 18 + } ); 19 + 20 + it( 'returns null when the param is present but empty', () => { 21 + expect( editRkeyFromSearch( '?edit=' ) ).toBeNull(); 22 + } ); 23 + } );
+18
src/lib/editor/edit-link.ts
··· 1 + /** 2 + * The dashboard→editor "edit this article" link, and the editor-side parser for 3 + * it. Kept together so the `?edit=` param name has a single source of truth. 4 + * `rkey` uniquely identifies a document within the writer's repo, so it is all 5 + * the editor needs to re-fetch the article on load. 6 + */ 7 + const EDIT_PARAM = 'edit'; 8 + 9 + /** The editor URL that opens an existing article for editing. */ 10 + export function editLinkFor( rkey: string ): string { 11 + return `/editor?${ EDIT_PARAM }=${ rkey }`; 12 + } 13 + 14 + /** The rkey to edit, parsed from a URL search string (e.g. `window.location.search`). Null when absent or empty. */ 15 + export function editRkeyFromSearch( search: string ): string | null { 16 + const rkey = new URLSearchParams( search ).get( EDIT_PARAM ); 17 + return rkey && rkey.length > 0 ? rkey : null; 18 + }