Skip to content

πŸ“ˆ Open source, privacy-first web analytics β€” a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

better tables style, SWETRIX_LOGO and CTA:TIME_TO_SWITCH markers

Blue Mouse8f77091561c9
diff --git a/web/app/pages/Blog/Post.tsx b/web/app/pages/Blog/Post.tsx
index ce14fb9bc..8b008ae22 100644
--- a/web/app/pages/Blog/Post.tsx
+++ b/web/app/pages/Blog/Post.tsx
@@ -48,7 +48,7 @@ export default function PostSlug() {
<ExitIntentPopup isStandalone={post.standalone} />
<div className='mx-auto max-w-[52rem] px-4 pb-28 sm:px-6 md:px-8 lg:max-w-6xl xl:px-12'>
<div className='overflow-hidden'>
- <div className='mx-auto max-w-4xl pb-28'>
+ <div className='mx-auto max-w-4xl'>
<main className='bg-gray-50 dark:bg-slate-900'>
{post.standalone ? (
<div className='mt-10 mb-6' />
diff --git a/web/app/utils/getPosts.ts b/web/app/utils/getPosts.ts
index ea288be6f..9159b8b13 100644
--- a/web/app/utils/getPosts.ts
+++ b/web/app/utils/getPosts.ts
@@ -3,6 +3,7 @@ import { marked, type Tokens } from 'marked'
import { getBlogPost, getBlogPostWithCategory } from '~/api'
+import { renderTimeToSwitchCta } from './renderCtaHtml'
import { extractTableOfContents, ensureHeaderIds, generateSlug, renderTocAsHtml } from './toc'
const renderer = new marked.Renderer()
@@ -23,6 +24,74 @@ renderer.heading = ({ text, depth }: Tokens.Heading) => {
return `<h${depth} id="${id}">${text}</h${depth}>`
}
+// Helper to parse inline markdown in table cells
+function parseInlineMarkdown(text: string): string {
+ return marked.parseInline(text) as string
+}
+
+// Check if a row is a section header (first cell is bold, other cells are empty)
+function isSectionHeaderRow(row: Tokens.TableCell[]): boolean {
+ const firstCellText = row[0]?.text?.trim() || ''
+ const isBold = firstCellText.startsWith('**') && firstCellText.endsWith('**')
+ const otherCellsEmpty = row.slice(1).every((cell) => !cell.text?.trim())
+ return isBold && otherCellsEmpty
+}
+
+// Custom table rendering with improved styling
+renderer.table = ({ header, rows }: Tokens.Table) => {
+ const headerCells = header
+ .map(
+ (cell) =>
+ `<th class="px-4 py-3.5 text-left text-base font-semibold text-slate-900 dark:text-slate-100 bg-slate-100 dark:bg-slate-800 first:rounded-tl-lg last:rounded-tr-lg">${parseInlineMarkdown(cell.text)}</th>`,
+ )
+ .join('')
+
+ const bodyRows = rows
+ .map((row) => {
+ const isHeader = isSectionHeaderRow(row)
+
+ if (isHeader) {
+ // Section header row - spans all columns with background
+ const cellContent = parseInlineMarkdown(row[0].text)
+ return `<tr class="bg-slate-50 dark:bg-slate-800/70"><td colspan="${row.length}" class="px-4 py-3 text-sm font-semibold text-slate-900 dark:text-slate-100">${cellContent}</td></tr>`
+ }
+
+ // Regular row
+ return `<tr class="border-b border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors">${row
+ .map(
+ (cell) =>
+ `<td class="px-4 py-3 text-sm text-slate-700 dark:text-slate-300">${parseInlineMarkdown(cell.text)}</td>`,
+ )
+ .join('')}</tr>`
+ })
+ .join('')
+
+ return `<div class="not-prose my-6 overflow-x-auto rounded-xl border border-slate-200 dark:border-slate-700">
+ <table class="min-w-full divide-y divide-slate-200 dark:divide-slate-700">
+ <thead><tr>${headerCells}</tr></thead>
+ <tbody class="divide-y divide-slate-200 dark:divide-slate-700 bg-white dark:bg-slate-900">${bodyRows}</tbody>
+ </table>
+ </div>`
+}
+
+// SVG icons for checkmark and cross
+const CHECK_ICON_SVG = `<span class="inline-flex items-center justify-center size-6 rounded-full bg-emerald-100 dark:bg-emerald-900/30"><svg class="w-4 h-4 text-emerald-600 dark:text-emerald-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="Yes"><path d="M20 6 9 17l-5-5"/></svg></span>`
+
+const CROSS_ICON_SVG = `<span class="inline-flex items-center justify-center size-6 rounded-full bg-red-100 dark:bg-red-900/30"><svg class="w-4 h-4 text-red-600 dark:text-red-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="No"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></span>`
+
+// Inline Swetrix logo that inherits font size
+const SWETRIX_LOGO_HTML = `<span class="inline-flex items-center gap-[0.15em] select-none whitespace-nowrap align-baseline"><img class="h-[0.9em] w-auto dark:hidden" src="/assets/logo/blue.png" alt="" /><img class="h-[0.9em] w-auto hidden dark:inline" src="/assets/logo/white.png" alt="" /><span class="font-bold text-indigo-950 dark:text-white">Swetrix</span></span>`
+
+// Function to replace emoji with styled icons
+function replaceEmojiWithIcons(html: string): string {
+ return html.replace(/βœ…/g, CHECK_ICON_SVG).replace(/❌/g, CROSS_ICON_SVG)
+}
+
+// Function to replace ::SWETRIX_LOGO:: placeholder
+function replaceSwetrixLogo(html: string): string {
+ return html.replace(/::SWETRIX_LOGO::/g, SWETRIX_LOGO_HTML)
+}
+
// Removes first 10 characters from the string (i.e. 2023-10-07-)
export const getSlugFromFilename = (filename: string) => filename.substring(11)
export const getDateFromFilename = (filename: string) => filename.substring(0, 10)
@@ -61,12 +130,20 @@ export async function getPost(slug: string, category?: string, tryStandalone?: b
}
const tocPlaceholder = '::TABLE_OF_CONTENTS::'
+ const ctaTimeToSwitchPlaceholder = '::CTA:TIME_TO_SWITCH::'
const hasTocPlaceholder = post.body.includes(tocPlaceholder)
+ const hasCtaTimeToSwitch = post.body.includes(ctaTimeToSwitchPlaceholder)
let html = marked(post.body, { renderer }) as string
html = ensureHeaderIds(html)
+ // Replace emoji icons with styled SVG icons
+ html = replaceEmojiWithIcons(html)
+
+ // Replace ::SWETRIX_LOGO:: with inline logo
+ html = replaceSwetrixLogo(html)
+
const toc = extractTableOfContents(html)
if (hasTocPlaceholder && toc.length > 0) {
@@ -74,6 +151,12 @@ export async function getPost(slug: string, category?: string, tryStandalone?: b
html = html.replace(new RegExp(tocPlaceholder, 'gi'), tocHtml)
}
+ // Handle CTA:TIME_TO_SWITCH placeholder
+ if (hasCtaTimeToSwitch) {
+ const ctaHtml = renderTimeToSwitchCta()
+ html = html.replace(new RegExp(ctaTimeToSwitchPlaceholder, 'gi'), ctaHtml)
+ }
+
return {
slug,
title: post.attributes?.title,
diff --git a/web/app/utils/renderCtaHtml.ts b/web/app/utils/renderCtaHtml.ts
new file mode 100644
index 000000000..8beff9f11
--- /dev/null
+++ b/web/app/utils/renderCtaHtml.ts
@@ -0,0 +1,54 @@
+import routes from './routes'
+
+/**
+ * Renders the "Time to Switch" CTA component as static HTML
+ * This is used in blog posts via the ::CTA:TIME_TO_SWITCH:: placeholder
+ */
+export function renderTimeToSwitchCta(): string {
+ const checkIconSvg = `<svg class="mr-1 size-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>`
+
+ const arrowRightSvg = `<svg class="mt-[1px] h-4 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M3 10a.75.75 0 01.75-.75h10.638L10.23 5.29a.75.75 0 111.04-1.08l5.5 5.25a.75.75 0 010 1.08l-5.5 5.25a.75.75 0 11-1.04-1.08l4.158-3.96H3.75A.75.75 0 013 10z" clip-rule="evenodd" /></svg>`
+
+ return `
+<div class="not-prose relative mx-auto my-10 max-w-4xl px-2 lg:px-0">
+ <div class="relative mx-auto overflow-hidden rounded-3xl p-1 text-center sm:p-2 lg:p-3">
+ <div aria-hidden="true" class="pointer-events-none absolute inset-0">
+ <div class="absolute inset-0 rounded-4xl bg-linear-115 from-red-500/50 to-orange-300/30 sm:bg-linear-145 dark:from-red-500/40 dark:to-orange-300/20"></div>
+ </div>
+ <div class="rounded-xl p-8 backdrop-blur-xl sm:p-10 lg:p-12">
+ <div class="mx-auto max-w-3xl">
+ <h2 class="mb-4 text-3xl font-bold tracking-tight text-slate-900 sm:text-4xl lg:text-5xl dark:text-white">
+ The web analytics your site deserves.
+ </h2>
+ <p class="mx-auto mb-8 max-w-2xl text-lg leading-relaxed text-slate-800 dark:text-slate-200">
+ Tired of bloated dashboards, privacy concerns, and data you can't trust? Switch to Swetrix and get simple, powerful analytics that respects your users.
+ </p>
+ <div class="mb-6 flex flex-col items-center justify-center gap-4 sm:flex-row">
+ <a
+ href="${routes.signup}"
+ class="flex items-center justify-center rounded-md border-2 border-slate-900 bg-slate-900 px-6 py-3 text-white transition-all hover:bg-transparent hover:text-slate-900 dark:border-slate-50 dark:bg-gray-50 dark:text-slate-900 dark:hover:bg-transparent dark:hover:text-gray-50"
+ >
+ <span class="mr-1 text-center text-base font-semibold">Start your free trial</span>
+ ${arrowRightSvg}
+ </a>
+ </div>
+ <div class="flex flex-wrap items-center justify-center gap-x-6 gap-y-3 text-sm text-slate-800 dark:text-slate-200">
+ <div class="flex items-center">
+ ${checkIconSvg}
+ No credit card required
+ </div>
+ <div class="flex items-center">
+ ${checkIconSvg}
+ 5 minute setup
+ </div>
+ <div class="flex items-center">
+ ${checkIconSvg}
+ GDPR compliant
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+`
+}