@@ -3,16 +3,20 @@ import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
 | 
				
			|||||||
import readingTime from "reading-time"
 | 
					import readingTime from "reading-time"
 | 
				
			||||||
import { classNames } from "../util/lang"
 | 
					import { classNames } from "../util/lang"
 | 
				
			||||||
import { i18n } from "../i18n"
 | 
					import { i18n } from "../i18n"
 | 
				
			||||||
 | 
					import { JSX } from "preact"
 | 
				
			||||||
 | 
					import style from "./styles/contentMeta.scss"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface ContentMetaOptions {
 | 
					interface ContentMetaOptions {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Whether to display reading time
 | 
					   * Whether to display reading time
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  showReadingTime: boolean
 | 
					  showReadingTime: boolean
 | 
				
			||||||
 | 
					  showComma: boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const defaultOptions: ContentMetaOptions = {
 | 
					const defaultOptions: ContentMetaOptions = {
 | 
				
			||||||
  showReadingTime: true,
 | 
					  showReadingTime: true,
 | 
				
			||||||
 | 
					  showComma: true,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default ((opts?: Partial<ContentMetaOptions>) => {
 | 
					export default ((opts?: Partial<ContentMetaOptions>) => {
 | 
				
			||||||
@@ -23,7 +27,7 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
 | 
				
			|||||||
    const text = fileData.text
 | 
					    const text = fileData.text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (text) {
 | 
					    if (text) {
 | 
				
			||||||
      const segments: string[] = []
 | 
					      const segments: (string | JSX.Element)[] = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (fileData.dates) {
 | 
					      if (fileData.dates) {
 | 
				
			||||||
        segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
 | 
					        segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
 | 
				
			||||||
@@ -38,17 +42,19 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
 | 
				
			|||||||
        segments.push(displayedTime)
 | 
					        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 {
 | 
					    } else {
 | 
				
			||||||
      return null
 | 
					      return null
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ContentMetadata.css = `
 | 
					  ContentMetadata.css = style
 | 
				
			||||||
  .content-meta {
 | 
					
 | 
				
			||||||
    margin-top: 0;
 | 
					 | 
				
			||||||
    color: var(--gray);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  `
 | 
					 | 
				
			||||||
  return ContentMetadata
 | 
					  return ContentMetadata
 | 
				
			||||||
}) satisfies QuartzComponentConstructor
 | 
					}) satisfies QuartzComponentConstructor
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								quartz/components/styles/contentMeta.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								quartz/components/styles/contentMeta.scss
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					.content-meta {
 | 
				
			||||||
 | 
					  margin-top: 0;
 | 
				
			||||||
 | 
					  color: var(--gray);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  &[show-comma="true"] {
 | 
				
			||||||
 | 
					    > span:not(:last-child) {
 | 
				
			||||||
 | 
					      margin-right: 8px;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      &::after {
 | 
				
			||||||
 | 
					        content: ",";
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user