2023-08-20 05:52:25 +07:00
|
|
|
import { FullSlug, resolveRelative } from "../util/path"
|
2023-07-01 14:03:01 +07:00
|
|
|
import { QuartzPluginData } from "../plugins/vfile"
|
2023-08-24 22:56:40 +07:00
|
|
|
import { Date, getDate } from "./Date"
|
2023-07-01 14:03:01 +07:00
|
|
|
import { QuartzComponentProps } from "./types"
|
2023-08-24 22:56:40 +07:00
|
|
|
import { GlobalConfiguration } from "../cfg"
|
2023-07-01 14:03:01 +07:00
|
|
|
|
2023-08-24 22:56:40 +07:00
|
|
|
export function byDateAndAlphabetical(
|
|
|
|
cfg: GlobalConfiguration,
|
|
|
|
): (f1: QuartzPluginData, f2: QuartzPluginData) => number {
|
|
|
|
return (f1, f2) => {
|
|
|
|
if (f1.dates && f2.dates) {
|
|
|
|
// sort descending
|
|
|
|
return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime()
|
|
|
|
} else if (f1.dates && !f2.dates) {
|
|
|
|
// prioritize files with dates
|
|
|
|
return -1
|
|
|
|
} else if (!f1.dates && f2.dates) {
|
|
|
|
return 1
|
|
|
|
}
|
2023-07-01 14:03:01 +07:00
|
|
|
|
2023-08-24 22:56:40 +07:00
|
|
|
// otherwise, sort lexographically by title
|
|
|
|
const f1Title = f1.frontmatter?.title.toLowerCase() ?? ""
|
|
|
|
const f2Title = f2.frontmatter?.title.toLowerCase() ?? ""
|
|
|
|
return f1Title.localeCompare(f2Title)
|
|
|
|
}
|
2023-07-01 14:03:01 +07:00
|
|
|
}
|
|
|
|
|
2023-07-26 11:10:37 +07:00
|
|
|
type Props = {
|
|
|
|
limit?: number
|
|
|
|
} & QuartzComponentProps
|
|
|
|
|
2023-08-24 22:56:40 +07:00
|
|
|
export function PageList({ cfg, fileData, allFiles, limit }: Props) {
|
|
|
|
let list = allFiles.sort(byDateAndAlphabetical(cfg))
|
2023-07-26 11:10:37 +07:00
|
|
|
if (limit) {
|
|
|
|
list = list.slice(0, limit)
|
|
|
|
}
|
|
|
|
|
2023-07-23 07:27:41 +07:00
|
|
|
return (
|
|
|
|
<ul class="section-ul">
|
2023-07-26 11:10:37 +07:00
|
|
|
{list.map((page) => {
|
2023-07-23 07:27:41 +07:00
|
|
|
const title = page.frontmatter?.title
|
|
|
|
const tags = page.frontmatter?.tags ?? []
|
2023-07-16 13:02:12 +07:00
|
|
|
|
2023-07-23 07:27:41 +07:00
|
|
|
return (
|
|
|
|
<li class="section-li">
|
|
|
|
<div class="section">
|
|
|
|
{page.dates && (
|
|
|
|
<p class="meta">
|
2024-01-29 13:13:59 +07:00
|
|
|
<Date date={getDate(cfg, page)!} locale={cfg.locale} />
|
2023-07-23 07:27:41 +07:00
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
<div class="desc">
|
|
|
|
<h3>
|
2023-08-20 05:52:25 +07:00
|
|
|
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
2023-07-23 07:27:41 +07:00
|
|
|
{title}
|
|
|
|
</a>
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
<ul class="tags">
|
|
|
|
{tags.map((tag) => (
|
|
|
|
<li>
|
|
|
|
<a
|
2023-07-24 11:41:09 +07:00
|
|
|
class="internal tag-link"
|
2023-08-20 06:28:44 +07:00
|
|
|
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
|
2023-07-23 07:27:41 +07:00
|
|
|
>
|
|
|
|
#{tag}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
)
|
2023-07-01 14:03:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
PageList.css = `
|
|
|
|
.section h3 {
|
|
|
|
margin: 0;
|
|
|
|
}
|
2023-07-24 11:41:09 +07:00
|
|
|
|
|
|
|
.section > .tags {
|
|
|
|
margin: 0;
|
|
|
|
}
|
2023-07-01 14:03:01 +07:00
|
|
|
`
|