publish: fix snippet generation
Fixes urbit/landscape#853
-import { GraphNode, Post, TextContent } from '@urbit/api';
+import { Content, GraphNode, Post, TextContent } from '@urbit/api';
import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
import bigInt, { BigInteger } from 'big-integer';
import { buntPost } from '~/logic/lib/post';
@@ -122,8 +122,9 @@ export function getComments(node: GraphNode): GraphNode {
return comments;
}
-export function getSnippet(body: any) {
- const firstContent = Object.values(body[0])[0];
+export function getSnippet(body: Content[]) {
+ const firstContent = body
+ .filter((c: Content): c is TextContent => 'text' in c).map(c => c.text)[0] ?? '';
const newlineIdx = firstContent.indexOf('\n', 2);
const end = newlineIdx > -1 ? newlineIdx : firstContent.length;
const start = firstContent.substr(0, end);
