feat: add version history drawer with release notes

Introduce a footer-triggered Version History drawer with categorized release notes, hardcoded release data, and semver tracking at v0.3.0. Also ships blog blockquote/table styling, site-wide typography, home page image updates, header refinements, and related bug fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
alirez.br
2026-07-02 02:46:20 +03:30
co-authored by Cursor
parent 62163c4ab9
commit a47ec493c5
92 changed files with 4574 additions and 507 deletions
+137 -6
View File
@@ -8,11 +8,22 @@
*/
import * as cheerio from "cheerio";
import type { Element } from "domhandler";
import { sanitizeBlockquoteContent } from "@/lib/blockquote-content";
import {
detectTableVariant,
sanitizeTableCellContent,
} from "@/lib/table-content";
// ─── انواع بلاک (برای گسترش بعدی) ───────────────────────────────────────────
/** نام نوع بلاک؛ با افزودن بلاک جدید این یونیون را گسترش دهید. */
export type BlockType = "collapse" | "blockquote" | "pullquote" | "tip" | "code";
export type BlockType =
| "collapse"
| "blockquote"
| "pullquote"
| "tip"
| "table"
| "code";
/** Payload بلاک collapse (سوالات متداول / accordion). */
export interface CollapseBlockPayload {
@@ -20,11 +31,16 @@ export interface CollapseBlockPayload {
items: { question: string; answer: string }[];
}
/** استایل رنگی نقل‌قول: زرد (accent)، سبز (primary)، طوسی (muted). */
export type BlockquoteVariant = "yellow" | "green" | "gray";
/** Payload بلاک blockquote (نقل‌قول و منبع). content به صورت HTML است و باید با dangerouslySetInnerHTML رندر شود. */
export interface BlockquoteBlockPayload {
/** HTML محتوای نقل‌قول (بدون تگ cite). */
content: string;
citation?: string;
/** استایل رنگی؛ پیش‌فرض طوسی. از کلاس‌های quote-yellow | quote-green | quote-gray در وردپرس. */
variant?: BlockquoteVariant;
}
/** Payload بلاک tip (نکته / اینفو با variant: info, warn, danger). */
@@ -34,6 +50,19 @@ export interface TipBlockPayload {
content: string;
}
/** استایل UI جدول: one (primary/سبز) یا two (accent/زرد) — هر دو با چیدمان کلاسیک. */
export type TableVariant = "one" | "two";
/** Payload بلاک table (جدول وردپرس). */
export interface TableBlockPayload {
variant: TableVariant;
/** HTML محتوای هر ستون در سطر سرستون. */
headers: string[];
/** سطرهای بدنه؛ هر سلول HTML است. */
rows: string[][];
caption?: string;
}
/** Payload بلاک code؛ بعداً پیاده‌سازی می‌شود. */
// export interface CodeBlockPayload { ... }
@@ -41,7 +70,8 @@ export interface TipBlockPayload {
export type BlockPayload =
| CollapseBlockPayload
| BlockquoteBlockPayload
| TipBlockPayload;
| TipBlockPayload
| TableBlockPayload;
// | CodeBlockPayload
// ─── سگمنت خروجی برای لایه رندر ─────────────────────────────────────────────
@@ -311,16 +341,43 @@ function discoverFaqCollapseBlocks(
return faqEntries;
}
const BLOCKQUOTE_VARIANT_CYCLE: BlockquoteVariant[] = ["yellow", "green", "gray"];
function parseExplicitBlockquoteVariant(
classList: string[]
): BlockquoteVariant | undefined {
if (
classList.some(
(c) => c === "quote-yellow" || c === "is-style-yellow"
)
) {
return "yellow";
}
if (
classList.some((c) => c === "quote-green" || c === "is-style-green")
) {
return "green";
}
if (
classList.some((c) => c === "quote-gray" || c === "is-style-gray")
) {
return "gray";
}
return undefined;
}
function extractBlockquotePayload(
$: cheerio.CheerioAPI,
el: Element
): BlockquoteBlockPayload {
const $el = $(el);
const classList = ($el.attr("class") ?? "").split(/\s+/);
const variant = parseExplicitBlockquoteVariant(classList);
const citation = $el.find("cite").first().text().trim() || undefined;
const $body = $el.clone();
$body.find("cite").remove();
const content = ($body.html() ?? "").trim();
return { content, citation };
const content = sanitizeBlockquoteContent($body.html() ?? "");
return { content, citation, ...(variant ? { variant } : {}) };
}
/**
@@ -332,17 +389,71 @@ function extractPullquotePayload(
el: Element
): BlockquoteBlockPayload {
const $el = $(el);
const classList = [
...($el.attr("class") ?? "").split(/\s+/),
...($el.find("blockquote").first().attr("class") ?? "").split(/\s+/),
];
const variant = parseExplicitBlockquoteVariant(classList);
const $blockquote = $el.find("blockquote").first();
const citation = $blockquote.find("cite").first().text().trim() || undefined;
const $body = $blockquote.clone();
$body.find("cite").remove();
const content = ($body.html() ?? "").trim();
return { content, citation };
const content = sanitizeBlockquoteContent($body.html() ?? "");
return { content, citation, ...(variant ? { variant } : {}) };
}
/**
* استخراج از بلاک tip وردپرس: div.wp-block-group.tip با کلاس tip-info | tip-warn | tip-danger.
*/
function extractTablePayload(
$: cheerio.CheerioAPI,
el: Element
): TableBlockPayload {
const $el = $(el);
const variant = detectTableVariant($el.text());
const captionRaw = $el.find("figcaption").first().text().trim();
const caption = captionRaw
? sanitizeTableCellContent(captionRaw)
: undefined;
const $table = $el.find("table").first();
const headers: string[] = [];
const rows: string[][] = [];
$table.find("thead tr").first().find("th, td").each((_, cell) => {
headers.push(sanitizeTableCellContent($(cell).html() ?? ""));
});
const bodyRowEls = $table.find("tbody tr").toArray().filter(isElement);
const allRowEls = bodyRowEls.length
? bodyRowEls
: $table.find("tr").toArray().filter(isElement);
let bodyStart = 0;
if (!headers.length && allRowEls.length) {
$(allRowEls[0])
.find("th, td")
.each((_, cell) => {
headers.push(sanitizeTableCellContent($(cell).html() ?? ""));
});
bodyStart = 1;
}
for (let i = bodyStart; i < allRowEls.length; i++) {
const row: string[] = [];
$(allRowEls[i])
.find("th, td")
.each((_, cell) => {
row.push(sanitizeTableCellContent($(cell).html() ?? ""));
});
if (row.some((cell) => cell.replace(/<[^>]*>/g, "").trim())) {
rows.push(row);
}
}
return { variant, headers, rows, ...(caption ? { caption } : {}) };
}
function extractTipPayload($: cheerio.CheerioAPI, el: Element): TipBlockPayload {
const $el = $(el);
const classList = ($el.attr("class") ?? "").split(/\s+/);
@@ -384,6 +495,11 @@ export const BLOCK_DEFINITIONS: BlockDefinition[] = [
selector: "div.wp-block-group.tip",
extract: extractTipPayload as BlockDefinition["extract"],
},
{
blockType: "table",
selector: "figure.wp-block-table",
extract: extractTablePayload as BlockDefinition["extract"],
},
// { blockType: "code", selector: "pre.wp-block-code", extract: extractCodePayload },
];
@@ -433,6 +549,7 @@ export function discoverBlocks(html: string): DiscoveredContent {
blockquote: [],
pullquote: [],
tip: [],
table: [],
code: [],
};
@@ -459,6 +576,20 @@ export function discoverBlocks(html: string): DiscoveredContent {
// مرتب‌سازی بر اساس ترتیب در سند (از آخر به اول جایگزین می‌کنیم تا ایندکس‌ها جابجا نشوند)
entries.sort((a, b) => orderMap.get(a.el)! - orderMap.get(b.el)!);
// اگر وردپرس کلاس رنگی نفرستاده، به‌ترتیب زرد → سبز → طوسی چرخش می‌دهد
let quoteAutoIndex = 0;
for (const entry of entries) {
if (entry.blockType !== "blockquote" && entry.blockType !== "pullquote") {
continue;
}
const payload = entry.payload as BlockquoteBlockPayload;
if (!payload.variant) {
payload.variant =
BLOCKQUOTE_VARIANT_CYCLE[quoteAutoIndex % BLOCKQUOTE_VARIANT_CYCLE.length];
}
quoteAutoIndex++;
}
// جایگزینی با placeholder از آخر به اول
for (let i = entries.length - 1; i >= 0; i--) {
const { el, blockType, blockId, removeNodes } = entries[i];