This commit is contained in:
parent
a3366a6513
commit
165aa5636f
30 changed files with 718 additions and 499 deletions
88
src/remark-callouts.mjs
Normal file
88
src/remark-callouts.mjs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
const CALLOUT_LABELS = new Map([
|
||||
["aside", "Aside"],
|
||||
["caution", "Caution"],
|
||||
["note", "Note"],
|
||||
["tip", "Tip"],
|
||||
["warning", "Warning"],
|
||||
]);
|
||||
|
||||
function textFromInline(node) {
|
||||
if (!node) return "";
|
||||
if (typeof node.value === "string") return node.value;
|
||||
if (!Array.isArray(node.children)) return "";
|
||||
return node.children.map(textFromInline).join("");
|
||||
}
|
||||
|
||||
function normalizeLabel(value) {
|
||||
return value
|
||||
.trim()
|
||||
.replace(/^["“”]+|["“”]+$/g, "")
|
||||
.replace(/:$/, "")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
function paragraphCalloutLabel(paragraph) {
|
||||
if (paragraph?.type !== "paragraph") return null;
|
||||
|
||||
const first = paragraph.children?.[0];
|
||||
if (first?.type !== "strong") return null;
|
||||
|
||||
const label = CALLOUT_LABELS.get(normalizeLabel(textFromInline(first)));
|
||||
if (!label) return null;
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
function removeLeadingLabel(paragraph, label) {
|
||||
if (paragraph?.type !== "paragraph") return;
|
||||
|
||||
const first = paragraph.children?.[0];
|
||||
const firstText = normalizeLabel(textFromInline(first));
|
||||
if (!first || first.type !== "strong" || firstText !== label.toLowerCase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
paragraph.children.shift();
|
||||
|
||||
const next = paragraph.children[0];
|
||||
if (next?.type === "text") {
|
||||
next.value = next.value.replace(/^:\s*/, "").replace(/^\s+/, "");
|
||||
if (!next.value) paragraph.children.shift();
|
||||
}
|
||||
}
|
||||
|
||||
function transformBlockquote(node) {
|
||||
if (node.type !== "blockquote") return;
|
||||
|
||||
const first = node.children?.[0];
|
||||
const label = paragraphCalloutLabel(first);
|
||||
if (!label) return;
|
||||
|
||||
removeLeadingLabel(first, label);
|
||||
if (first.children?.length === 0) {
|
||||
node.children.shift();
|
||||
}
|
||||
|
||||
node.data = {
|
||||
hName: "aside",
|
||||
hProperties: {
|
||||
className: ["callout", `callout-${label.toLowerCase()}`],
|
||||
dataCalloutLabel: label,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function visit(node) {
|
||||
transformBlockquote(node);
|
||||
|
||||
if (!Array.isArray(node.children)) return;
|
||||
for (const child of node.children) {
|
||||
visit(child);
|
||||
}
|
||||
}
|
||||
|
||||
export default function remarkCallouts() {
|
||||
return function transformer(tree) {
|
||||
visit(tree);
|
||||
};
|
||||
}
|
||||
264
src/styles/article.css
Normal file
264
src/styles/article.css
Normal file
|
|
@ -0,0 +1,264 @@
|
|||
.blog-post-shell {
|
||||
margin-inline: auto;
|
||||
max-width: 78rem;
|
||||
padding: 3rem 1.75rem 4.5rem;
|
||||
}
|
||||
|
||||
.blog-article {
|
||||
margin-inline: auto;
|
||||
max-width: 68rem;
|
||||
}
|
||||
|
||||
.blog-post-header {
|
||||
margin-bottom: 2rem;
|
||||
border-bottom: 1px solid hsl(var(--border));
|
||||
padding-bottom: 1.35rem;
|
||||
}
|
||||
|
||||
.blog-post-meta {
|
||||
color: hsl(var(--muted-foreground));
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.blog-post-header .blog-post-title {
|
||||
margin-top: 0.65rem;
|
||||
color: hsl(var(--foreground));
|
||||
font-size: clamp(1.9rem, 3.2vw, 2.45rem);
|
||||
font-weight: 650;
|
||||
line-height: 1.08;
|
||||
}
|
||||
|
||||
.blog-post-description {
|
||||
margin-top: 0.8rem;
|
||||
max-width: 42rem;
|
||||
color: hsl(var(--muted-foreground));
|
||||
font-size: 1rem;
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.blog-post-hero-image {
|
||||
margin: 2rem auto;
|
||||
overflow: hidden;
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.blog-post-hero-image img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
color: hsl(var(--foreground));
|
||||
font-family: var(--font-heliotrope);
|
||||
font-size: 1.0625rem;
|
||||
line-height: 1.78;
|
||||
}
|
||||
|
||||
.article-content > * + * {
|
||||
margin-top: 1.2rem;
|
||||
}
|
||||
|
||||
.article-content :where(h1, h2, h3, h4, h5, h6) {
|
||||
color: hsl(var(--foreground));
|
||||
font-family: var(--font-fraunces);
|
||||
font-style: normal;
|
||||
font-weight: 650;
|
||||
letter-spacing: 0;
|
||||
line-height: 1.18;
|
||||
}
|
||||
|
||||
.article-content :where(h1) {
|
||||
margin-top: 2.4rem;
|
||||
font-size: clamp(1.65rem, 2.5vw, 2.1rem);
|
||||
}
|
||||
|
||||
.article-content :where(h2) {
|
||||
margin-top: 2.15rem;
|
||||
font-size: clamp(1.38rem, 2.1vw, 1.72rem);
|
||||
}
|
||||
|
||||
.article-content :where(h3) {
|
||||
margin-top: 1.85rem;
|
||||
font-size: clamp(1.15rem, 1.75vw, 1.35rem);
|
||||
}
|
||||
|
||||
.article-content :where(h4, h5, h6) {
|
||||
margin-top: 1.5rem;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.article-content :where(p, ul, ol, blockquote, pre, table, figure, iframe) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.article-content :where(ul, ol) {
|
||||
padding-left: 1.35rem;
|
||||
}
|
||||
|
||||
.article-content :where(li + li) {
|
||||
margin-top: 0.35rem;
|
||||
}
|
||||
|
||||
.article-content :where(a) {
|
||||
color: hsl(var(--primary));
|
||||
text-decoration-line: underline;
|
||||
text-decoration-thickness: 0.08em;
|
||||
text-underline-offset: 0.18em;
|
||||
}
|
||||
|
||||
.article-content :where(code) {
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.25rem;
|
||||
background: hsl(var(--muted));
|
||||
padding: 0.08rem 0.28rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.88em;
|
||||
}
|
||||
|
||||
.article-content :where(pre) {
|
||||
overflow-x: auto;
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.65rem;
|
||||
background: hsl(var(--muted));
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.article-content :where(pre code) {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.article-content :where(blockquote) {
|
||||
margin-inline: 0;
|
||||
border-left: 3px solid hsl(var(--border));
|
||||
padding: 0.15rem 0 0.15rem 1rem;
|
||||
color: color-mix(in srgb, hsl(var(--foreground)) 82%, transparent);
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.article-content :where(blockquote p) {
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.article-content :where(blockquote h1) {
|
||||
font-size: 1.45rem;
|
||||
}
|
||||
|
||||
.article-content :where(blockquote h2) {
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.article-content :where(blockquote h3) {
|
||||
font-size: 1.12rem;
|
||||
}
|
||||
|
||||
.article-content :where(.callout) {
|
||||
margin-block: 1.5rem;
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-left: 4px solid hsl(var(--primary));
|
||||
border-radius: 0.7rem;
|
||||
background: color-mix(in srgb, hsl(var(--accent)) 54%, transparent);
|
||||
padding: 1rem 1.15rem;
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
.article-content :where(.callout > *:first-child) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.article-content :where(.callout h1) {
|
||||
font-size: 1.35rem;
|
||||
}
|
||||
|
||||
.article-content :where(.callout h2) {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.article-content :where(.callout h3) {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.article-content :where(aside:not(.callout)) {
|
||||
margin-block: 1.5rem;
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.7rem;
|
||||
background: hsl(var(--muted));
|
||||
padding: 1rem 1.15rem;
|
||||
}
|
||||
|
||||
.article-content :where(img) {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin-inline: auto;
|
||||
border-radius: 0.35rem;
|
||||
}
|
||||
|
||||
.article-content :where(figure) {
|
||||
margin-inline: 0;
|
||||
}
|
||||
|
||||
.article-content :where(figcaption) {
|
||||
color: hsl(var(--muted-foreground));
|
||||
font-size: 0.92rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.article-content :where(iframe) {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
aspect-ratio: 16 / 9;
|
||||
height: auto;
|
||||
margin-inline: auto;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.article-content :where(table) {
|
||||
display: block;
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.article-content :where(th, td) {
|
||||
border: 1px solid hsl(var(--border));
|
||||
padding: 0.45rem 0.6rem;
|
||||
}
|
||||
|
||||
.article-content :where(.twitter-tweet) {
|
||||
max-width: 100% !important;
|
||||
margin: 1.5rem auto !important;
|
||||
}
|
||||
|
||||
.article-content :where(.katex) {
|
||||
font-size: 1.02em;
|
||||
}
|
||||
|
||||
.article-content :where(.katex-display) {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding: 0.25rem 0;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.blog-post-shell {
|
||||
padding-top: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.blog-post-shell {
|
||||
padding-inline: 1.15rem;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue