rename slack message markdown transformer

This commit is contained in:
Riku Rouvila
2020-09-23 21:24:44 +03:00
parent ab869aaaa6
commit 2316bdbea7

View File

@@ -10,22 +10,26 @@ import { getChannels } from "../data/channels";
import emoji from "emoji-dictionary"; import emoji from "emoji-dictionary";
import ReactMarkdown from "react-markdown"; import ReactMarkdown from "react-markdown";
const emojiSupport = (text: { value: string }) => { const slackMarkdownRenderer = (text: { value: string }) => {
const emojiText = text.value.replace(/:\w+:/gi, (name) => const emojiText = text.value.replace(/:\w+:/gi, (name) =>
emoji.getUnicode(name) emoji.getUnicode(name)
); );
return emojiText.split(/(<#[A-Z0-9]+\|[A-Za-z0-9]+>)/).map((str) => { return (
const matches = str.match(/<#([A-Z0-9]+)\|([A-Za-z0-9]+)>/); <span>
if (matches) { {emojiText.split(/(<#[A-Z0-9]+\|[A-Za-z0-9]+>)/).map((str) => {
return ( const matches = str.match(/<#([A-Z0-9]+)\|([A-Za-z0-9]+)>/);
<a href={`https://app.slack.com/client/T03BQ3NU9/${matches[1]}`}> if (matches) {
{matches[2]} return (
</a> <a href={`https://app.slack.com/client/T03BQ3NU9/${matches[1]}`}>
); {matches[2]}
} </a>
return str; );
}); }
return str;
})}
</span>
);
}; };
export async function getStaticProps() { export async function getStaticProps() {
@@ -161,7 +165,7 @@ const IndexContent = (props: IndexProps) => (
<ReactMarkdown <ReactMarkdown
className="channel-topic" className="channel-topic"
source={channel.topic} source={channel.topic}
renderers={{ text: emojiSupport }} renderers={{ text: slackMarkdownRenderer }}
/> />
</span> </span>
</td> </td>