Merge pull request #4875 from urbit/lf/snippets

publish: fix snippet generation
This commit is contained in:
matildepark 2021-05-07 01:18:43 -04:00 committed by GitHub
commit f32caa87c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
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';
@ -118,8 +118,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);