mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-26 13:26:22 +00:00
603c181ad2
* fix: alt error mix with height/width More granular detection of alt and resize in image * fix: format * feat: allow to translate the date displayed * style: format * fix: rename to fusion dateLocale with locale (i18n support) * Update quartz/components/PageList.tsx Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * remove default key as it was already set * add docstring for locale --------- Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { formatDate, getDate } from "./Date"
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
|
import readingTime from "reading-time"
|
|
|
|
interface ContentMetaOptions {
|
|
/**
|
|
* Whether to display reading time
|
|
*/
|
|
showReadingTime: boolean
|
|
}
|
|
|
|
const defaultOptions: ContentMetaOptions = {
|
|
showReadingTime: true,
|
|
}
|
|
|
|
export default ((opts?: Partial<ContentMetaOptions>) => {
|
|
// Merge options with defaults
|
|
const options: ContentMetaOptions = { ...defaultOptions, ...opts }
|
|
|
|
function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) {
|
|
const text = fileData.text
|
|
|
|
if (text) {
|
|
const segments: string[] = []
|
|
|
|
if (fileData.dates) {
|
|
segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
|
|
}
|
|
|
|
// Display reading time if enabled
|
|
if (options.showReadingTime) {
|
|
const { text: timeTaken, words: _words } = readingTime(text)
|
|
segments.push(timeTaken)
|
|
}
|
|
|
|
return <p class={`content-meta ${displayClass ?? ""}`}>{segments.join(", ")}</p>
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
ContentMetadata.css = `
|
|
.content-meta {
|
|
margin-top: 0;
|
|
color: var(--gray);
|
|
}
|
|
`
|
|
return ContentMetadata
|
|
}) satisfies QuartzComponentConstructor
|