Skip to content

Commit

Permalink
feat: separated content meta (jackyzha0#929)
Browse files Browse the repository at this point in the history
to allow for CSS styling
  • Loading branch information
8bitgentleman authored Mar 10, 2024
1 parent b4236e5 commit 0f5a9d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
22 changes: 14 additions & 8 deletions quartz/components/ContentMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
import readingTime from "reading-time"
import { classNames } from "../util/lang"
import { i18n } from "../i18n"
import { JSX } from "preact"
import style from "./styles/contentMeta.scss"

interface ContentMetaOptions {
/**
* Whether to display reading time
*/
showReadingTime: boolean
showComma: boolean
}

const defaultOptions: ContentMetaOptions = {
showReadingTime: true,
showComma: true,
}

export default ((opts?: Partial<ContentMetaOptions>) => {
Expand All @@ -23,7 +27,7 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
const text = fileData.text

if (text) {
const segments: string[] = []
const segments: (string | JSX.Element)[] = []

if (fileData.dates) {
segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
Expand All @@ -38,17 +42,19 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
segments.push(displayedTime)
}

return <p class={classNames(displayClass, "content-meta")}>{segments.join(", ")}</p>
const segmentsElements = segments.map((segment) => <span>{segment}</span>)

return (
<p show-comma={options.showComma} class={classNames(displayClass, "content-meta")}>
{segmentsElements}
</p>
)
} else {
return null
}
}

ContentMetadata.css = `
.content-meta {
margin-top: 0;
color: var(--gray);
}
`
ContentMetadata.css = style

return ContentMetadata
}) satisfies QuartzComponentConstructor
14 changes: 14 additions & 0 deletions quartz/components/styles/contentMeta.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.content-meta {
margin-top: 0;
color: var(--gray);

&[show-comma="true"] {
> span:not(:last-child) {
margin-right: 8px;

&::after {
content: ",";
}
}
}
}

0 comments on commit 0f5a9d7

Please sign in to comment.