Simplify social card chrome
This commit is contained in:
parent
b7f0198c17
commit
2be83d5199
2 changed files with 36 additions and 181 deletions
|
|
@ -6,9 +6,6 @@ import { JSXInternal } from "preact/src/jsx"
|
|||
import { FontSpecification, getFontSpecificationName, ThemeKey } from "./theme"
|
||||
import path from "path"
|
||||
import { QUARTZ } from "./path"
|
||||
import { formatDate, getDate } from "../components/Date"
|
||||
import readingTime from "reading-time"
|
||||
import { i18n } from "../i18n"
|
||||
import { styleText } from "util"
|
||||
|
||||
const defaultHeaderWeight = [700]
|
||||
|
|
@ -186,29 +183,17 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
|
|||
title,
|
||||
description,
|
||||
deck,
|
||||
section,
|
||||
fileData,
|
||||
iconBase64,
|
||||
imageBase64,
|
||||
}) => {
|
||||
const { colorScheme } = userOpts
|
||||
const fontBreakPoint = 30
|
||||
const useSmallerFont = title.length > fontBreakPoint
|
||||
|
||||
// Format date if available
|
||||
const rawDate = getDate(cfg, fileData)
|
||||
const date = rawDate ? formatDate(rawDate, cfg.locale) : null
|
||||
|
||||
// Calculate reading time
|
||||
const { minutes } = readingTime(fileData.text ?? "")
|
||||
const readingTimeText = i18n(cfg.locale).components.contentMeta.readingTime({
|
||||
minutes: Math.ceil(minutes),
|
||||
})
|
||||
|
||||
const bodyFont = getFontSpecificationName(cfg.theme.typography.body)
|
||||
const headerFont = getFontSpecificationName(cfg.theme.typography.header)
|
||||
const displayDeck = deck || description
|
||||
const displayDeck = deck || description || title
|
||||
const showImage = Boolean(imageBase64)
|
||||
const headerFont = getFontSpecificationName(cfg.theme.typography.header)
|
||||
const bodyFont = getFontSpecificationName(cfg.theme.typography.body)
|
||||
const chromeBackground = "rgba(0,0,0,0.25)"
|
||||
const deckLength = displayDeck.length
|
||||
const deckFontSize =
|
||||
deckLength > 85 ? 24 : deckLength > 65 ? 27 : deckLength > 50 ? 30 : deckLength > 36 ? 34 : 40
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
@ -260,14 +245,14 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
|
|||
style={{
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
background:
|
||||
"linear-gradient(180deg, rgba(7,17,26,0.2) 0%, rgba(7,17,26,0.4) 60%, rgba(7,17,26,0.78) 100%)",
|
||||
background: "linear-gradient(180deg, rgba(7,17,26,0.12) 0%, rgba(7,17,26,0.24) 100%)",
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
padding: "2.4rem",
|
||||
|
|
@ -277,163 +262,33 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
|
|||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "flex-start",
|
||||
justifyContent: "space-between",
|
||||
gap: "1rem",
|
||||
marginBottom: "2.2rem",
|
||||
maxWidth: "92%",
|
||||
padding: "1rem 1.7rem",
|
||||
borderRadius: "24px",
|
||||
backgroundColor: chromeBackground,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
<p
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "1rem",
|
||||
margin: 0,
|
||||
fontSize: deckFontSize,
|
||||
fontFamily: headerFont,
|
||||
fontWeight: 600,
|
||||
letterSpacing: "-0.03em",
|
||||
color: "rgba(248,250,252,0.98)",
|
||||
textAlign: "center",
|
||||
textShadow: "0 4px 18px rgba(0,0,0,0.78)",
|
||||
whiteSpace: "nowrap",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
lineHeight: 1.08,
|
||||
maxWidth: "100%",
|
||||
}}
|
||||
>
|
||||
{iconBase64 && (
|
||||
<img
|
||||
src={iconBase64}
|
||||
width={46}
|
||||
height={46}
|
||||
style={{
|
||||
borderRadius: "50%",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
fontSize: 28,
|
||||
color: cfg.theme.colors[colorScheme].darkgray,
|
||||
fontFamily: bodyFont,
|
||||
}}
|
||||
>
|
||||
{cfg.pageTitle}
|
||||
</div>
|
||||
</div>
|
||||
{section && (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
padding: "0.55rem 0.95rem",
|
||||
borderRadius: "999px",
|
||||
backgroundColor: "rgba(255, 138, 42, 0.16)",
|
||||
border: `1px solid ${cfg.theme.colors[colorScheme].secondary}`,
|
||||
color: cfg.theme.colors[colorScheme].secondary,
|
||||
fontSize: 22,
|
||||
fontFamily: bodyFont,
|
||||
}}
|
||||
>
|
||||
{section}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "flex-end",
|
||||
flex: 1,
|
||||
maxWidth: showImage ? "58%" : "100%",
|
||||
padding: showImage ? "1.8rem 1.9rem 1.55rem" : 0,
|
||||
borderRadius: showImage ? "28px" : 0,
|
||||
backgroundColor: showImage ? "rgba(7,17,26,0.62)" : "transparent",
|
||||
border: showImage ? "1px solid rgba(231,236,244,0.08)" : "none",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
marginBottom: "1.2rem",
|
||||
}}
|
||||
>
|
||||
<h1
|
||||
style={{
|
||||
margin: 0,
|
||||
fontSize: useSmallerFont ? 66 : 78,
|
||||
fontFamily: headerFont,
|
||||
fontWeight: 300,
|
||||
letterSpacing: "-0.04em",
|
||||
color: cfg.theme.colors[colorScheme].dark,
|
||||
lineHeight: 1.05,
|
||||
display: "-webkit-box",
|
||||
WebkitBoxOrient: "vertical",
|
||||
WebkitLineClamp: 2,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</h1>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
marginBottom: "2.4rem",
|
||||
}}
|
||||
>
|
||||
<p
|
||||
style={{
|
||||
margin: 0,
|
||||
fontSize: 31,
|
||||
color: cfg.theme.colors[colorScheme].darkgray,
|
||||
lineHeight: 1.25,
|
||||
maxWidth: "100%",
|
||||
display: "-webkit-box",
|
||||
WebkitBoxOrient: "vertical",
|
||||
WebkitLineClamp: 3,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
}}
|
||||
>
|
||||
{displayDeck}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "1.75rem",
|
||||
marginTop: "auto",
|
||||
paddingTop: "1.5rem",
|
||||
borderTop: `1px solid ${cfg.theme.colors[colorScheme].lightgray}`,
|
||||
color: cfg.theme.colors[colorScheme].gray,
|
||||
fontSize: 24,
|
||||
}}
|
||||
>
|
||||
{date && (
|
||||
<div style={{ display: "flex", alignItems: "center" }}>
|
||||
<svg
|
||||
style={{ marginRight: "0.45rem" }}
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
|
||||
<line x1="16" y1="2" x2="16" y2="6"></line>
|
||||
<line x1="8" y1="2" x2="8" y2="6"></line>
|
||||
<line x1="3" y1="10" x2="21" y2="10"></line>
|
||||
</svg>
|
||||
{date}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ display: "flex", alignItems: "center" }}>
|
||||
<svg
|
||||
style={{ marginRight: "0.45rem" }}
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<circle cx="12" cy="12" r="10"></circle>
|
||||
<polyline points="12 6 12 12 16 14"></polyline>
|
||||
</svg>
|
||||
{readingTimeText}
|
||||
</div>
|
||||
</div>
|
||||
{displayDeck}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -161,15 +161,15 @@ export function resolveSocialDeck(
|
|||
return explicitDeck.trim()
|
||||
}
|
||||
|
||||
if (siteMetadata.deck && siteMetadata.deck.trim().length > 0) {
|
||||
return siteMetadata.deck.trim()
|
||||
}
|
||||
|
||||
const tagline = extractTopTagline(fileData.htmlAst)
|
||||
if (tagline) {
|
||||
return tagline
|
||||
}
|
||||
|
||||
if (siteMetadata.deck && siteMetadata.deck.trim().length > 0) {
|
||||
return siteMetadata.deck.trim()
|
||||
}
|
||||
|
||||
return description
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue