Add posts to latest story

This commit is contained in:
Bad Manners 2024-08-08 09:49:11 -03:00
parent 7bb8a952ef
commit 6dd8a92318
8 changed files with 51 additions and 31 deletions

View file

@ -29,12 +29,14 @@ function parseRegex<R extends { [key: string]: string }>(regex: RegExp) {
* from `website` - a pre-parsed object containing the link and username.
*/
const websiteLinks = z.object({
website: z
.string()
.url()
.transform((link) => {
link;
}),
website: z.object({ link: z.string().url() }).or(
z
.string()
.url()
.transform((link) => {
link;
}),
),
eka: z.object({ link: z.string().url(), username: z.string() }).or(
z.string().transform((link, ctx) => {
const { username } = parseRegex<{ username: string }>(
@ -189,6 +191,12 @@ const publishedContent = z.object({
)(link, ctx);
return { link, postId };
}),
twitter: z.string().transform((link, ctx) => {
const { user, postId } = parseRegex<{ user: string; postId: string }>(
/^(?:https?:\/\/)(?:www\.)?(?:twitter\.com|x\.com)\/(?<user>[a-zA-Z0-9_-]+)\/status\/(?<postId>[1-9]\d*)\/?$/,
)(link, ctx);
return { link, user, postId };
}),
bluesky: z.string().transform((link, ctx) => {
const { user, postId } = parseRegex<{ user: string; postId: string }>(
/^(?:https?:\/\/)bsky\.app\/profile\/(?<user>(?:[a-zA-Z0-9_-]+\.)+[a-z]+)\/post\/(?<postId>[a-z0-9]+)\/?$/,