Using iMessage Components in Astro.js

This is a must.

Message bubble is a must for migrating to Astro. I had a horribly coded version on my Jekyll blog, but I was always too lazy to optimize it. Now with the power of Astro.js, I have the chance to design one from ground up.

I’ve created a reusable component that mimics the familiar iOS iMessage style. Here’s how it looks in action:

Basic Conversation Example

Add a conversation by using a code block with the message language:

明天被辞退也不是没可能 😮‍💨

他会记你小本本吗

我今天下午去上班

门卡卡住了几秒

Private Chat with Chat Title

Display a chat title for a private conversation:

X
X. Wang

How's your day going?

Pretty good! Just finished that project.

The client was very happy with the results.

That's great news!

Let's celebrate this weekend.

You can also set a custom chat title:

C
Coffee-Chat

Are we still on for coffee?

Yes, see you at 3pm at the usual place

I might be 5 minutes late though

Group Chat Example

Group chats automatically show avatars for each person’s last message in a sequence:

Has everyone reviewed the document?

Yes, I added my comments yesterday

X

I also fixed some formatting issues

I'll finish my review today

J

Just a few more sections to go through

Showing Names in Group Chats

You can show names above message groups:

When is the next team meeting?

X. Wang

Thursday at 2pm

X

Should be about an hour long

John Smith

I have a conflict then

J

Can we move it to Friday?

Showing Message Tails

By default, message tails are hidden. You can enable them:

I just got the project specs

Can you share them with me?

I'd like to review before the meeting

Custom Timestamp

Set a custom timestamp that will appear only on the final message:

Are you still awake?

Yes, just working on some late-night coding

23:45

Combined Options

You can combine multiple options:

T
Team-Meeting
X. Wang
X

What's up?

Meeting in 5 minutes!

X. Wang

I'll be there, just finishing up something

X

Should I bring my laptop?

John Smith
J

Yes, we'll need it for the presentation

14:30

How It Works

The plugin automatically:

  1. Parses messages from the text format
  2. Identifies your messages based on the myMessageName in site configuration (Dylan Xu)
  3. Shows your messages as outgoing (blue bubbles) and others as incoming (gray bubbles)
  4. Automatically shows avatars for the last message in each group from each sender
  5. Adds increased spacing between different people’s message groups
  6. Shows custom time only on the final message of the conversation (when specified)

Configuration Options

  • chatTitle: Show a chat title header (true, false, or a custom title)
  • time: Show a custom time on the final message only (time=14:30)
  • tails: Show message tails (true or false, default is false)
  • showNames: Show sender names above message groups (true or false)

Advanced Usage in MDX Files

For more control, you can use components in MDX files:

import MessageConversation from '../components/MessageConversation';

 Settings > Export', sender: 'Dylan Xu', showTimestamp: true, timestamp: '10:32 AM' },
    { message: 'Found it, thanks!', sender: 'John Smith', showTimestamp: true, timestamp: '10:33 AM' }
  ]}
/>

Or parse raw text:

import MessageParser from '../components/MessageParser';

Read Next

从 Jekyll 到 Astro

修修补补又是一年
我的博客在 Github Pages 上运行了很多年, 直到我不再是学生以后, GitHub Education 过期, 我再也无法用 Private repo 创建页面, 于是开始寻找替代品. 今年年初我开始用 CloudFlare Pa...

“春天就应该在阳光里前行”

但最好还是不要把自己走死。
这个博客俨然已经成为了我记录内心纠结、思考的地方, 但反思和规划、太多的 melancholia 似乎都不是非常适合输出的内容, 即便读者恐怕只有未来的我自己。而且, 如果说最近关于我和原生家庭的思考有哪些值得我质疑的点, 那就是我总记住那...