Ria Choi
← Portfolio

Older Blog

An early React blog that renders articles from typed content blocks and generates link previews through a small Express endpoint.

Older Blog

I built this blog with React, Vite, and Tailwind CSS, plus a small Express server, and deployed it on Vercel.

Server-side link previews: Fetching another site's metadata from the browser runs into CORS limits, so I built an Express endpoint that fetches the preview on the server and returns it as JSON.

PHP
app.get('/api/link-preview', async (req, res) => {
    const { url } = req.query;
    if (!url) return res.status(400).json({ error: 'URL required' });

    try {
        const preview = await getLinkPreview(url, { imagesPropertyType: 'og', timeout: 5000 });
        res.json(preview);
    } catch (err) {
        res.status(500).json({ error: 'Failed to fetch preview', message: err.message });
    }
});

Post rendering: Each post is structured data made of typed blocks, and a Template component renders each block with a switch.

JavaScript
switch (block.type) {
    case 'text':
        return <p key={index} className="whitespace-pre-line">{block.value}</p>;
    case 'code':
        return <CodeSnippet key={index} code={block.value} language={block.language} />;
    case 'link':
        return <LinkFetch key={index} url={block.url} />;
}

Line breaks: I write breaks as \n in the post data. Browsers collapse them by default, so Tailwind's whitespace-pre-line keeps them and the text displays as I wrote it. For JSX content, I use <br /> where needed.

CSS
content:
    "If you’re just getting started with building websites...\n" +
    "There’s so much to think about, and it’s not always clear where to begin.\n"