import * as React from 'preact'; import type { PostInfo } from "types/PostInfo"; export function splitSentence(str: string): [string, string] { const splitStr = str.split(" "); const splitBy = ( regex: RegExp, matchLast: boolean = true ): [string, string] | null => { const matches = splitStr.map((word, i) => ({ reg: regex.exec(word), i })); const match = (matchLast ? matches.reverse() : matches) .slice(1, -1) .find(({ reg }) => !!reg); // if match is not found, fail if (!match || !match.reg) return null; const firstHalf = [ ...splitStr.slice(0, match.i), match.reg.input.substring(0, match.reg.index), ].join(" "); const secondHalf = [match.reg[0], ...splitStr.slice(match.i + 1)].join(" "); return [firstHalf, secondHalf]; }; let ret; // try to split by "Topic[: Attribute]" or "Topic [- Attribute]" (hyphens/colons) if ((ret = splitBy(/(?<=^\w+):$|^[-—]$/))) return ret; // try to split by "Attribute in [Topic, Topic, and Topic]" (commas) if ((ret = splitBy(/^\w+,$/, false))) return ret; // try to split by "Topic['s Attribute]" (apostrophe) if ((ret = splitBy(/(?<=^\w+\'s?)$/))) return ret; // try to split by "Attribute [in Topic]" (lowercase words) if ((ret = splitBy(/^[a-z][A-Za-z]*$/))) return ret; // otherwise, don't split the string return [str, ""]; } interface TwitterCodeScreenProps { title: string; html: string; blur: boolean; } const TwitterCodeScreen = ({ title, html, blur }: TwitterCodeScreenProps) => { const rotations = [ "rotateX(-17deg) rotateY(32deg) rotateZ(-3deg) translate(16%, 0%)", "rotateX(5deg) rotateY(35deg) rotateZ(345deg) translate(18%, 0)", "rotateX(15deg) rotateY(25deg) rotateZ(12deg) translate(3%, -15%)", ]; // use second char of title as "deterministic" random value const transform = rotations[title.charCodeAt(1) % rotations.length]; return (
unicorn-utterances.com