mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 11:36:23 +00:00
feat: pluralize things in lists
This commit is contained in:
parent
23f43045c4
commit
505673acd7
3 changed files with 12 additions and 3 deletions
|
@ -7,6 +7,7 @@ import style from "../styles/listPage.scss"
|
|||
import { PageList } from "../PageList"
|
||||
import { _stripSlashes, simplifySlug } from "../../util/path"
|
||||
import { Root } from "hast"
|
||||
import { pluralize } from "../../util/lang"
|
||||
|
||||
function FolderContent(props: QuartzComponentProps) {
|
||||
const { tree, fileData, allFiles } = props
|
||||
|
@ -36,7 +37,7 @@ function FolderContent(props: QuartzComponentProps) {
|
|||
<article>
|
||||
<p>{content}</p>
|
||||
</article>
|
||||
<p>{allPagesInFolder.length} items under this folder.</p>
|
||||
<p>{pluralize(allPagesInFolder.length, "item")} under this folder.</p>
|
||||
<div>
|
||||
<PageList {...listProps} />
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,7 @@ import { PageList } from "../PageList"
|
|||
import { FullSlug, getAllSegmentPrefixes, simplifySlug } from "../../util/path"
|
||||
import { QuartzPluginData } from "../../plugins/vfile"
|
||||
import { Root } from "hast"
|
||||
import { pluralize } from "../../util/lang"
|
||||
|
||||
const numPages = 10
|
||||
function TagContent(props: QuartzComponentProps) {
|
||||
|
@ -60,7 +61,7 @@ function TagContent(props: QuartzComponentProps) {
|
|||
</h2>
|
||||
{content && <p>{content}</p>}
|
||||
<p>
|
||||
{pages.length} items with this tag.{" "}
|
||||
{pluralize(pages.length, "item")} with this tag.{" "}
|
||||
{pages.length > numPages && `Showing first ${numPages}.`}
|
||||
</p>
|
||||
<PageList limit={numPages} {...listProps} />
|
||||
|
@ -80,7 +81,7 @@ function TagContent(props: QuartzComponentProps) {
|
|||
return (
|
||||
<div class="popover-hint">
|
||||
<article>{content}</article>
|
||||
<p>{pages.length} items with this tag.</p>
|
||||
<p>{pluralize(pages.length, "item")} with this tag.</p>
|
||||
<div>
|
||||
<PageList {...listProps} />
|
||||
</div>
|
||||
|
|
7
quartz/util/lang.ts
Normal file
7
quartz/util/lang.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export function pluralize(count: number, s: string): string {
|
||||
if (count === 1) {
|
||||
return `1 ${s}`
|
||||
} else {
|
||||
return `${count} ${s}s`
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue