From f9b1856da8c17755a2387e8cf6a2642831acc46c Mon Sep 17 00:00:00 2001 From: vintro Date: Fri, 13 Dec 2024 23:38:30 -0800 Subject: [PATCH 1/8] simple cards for folder view with tag sorting --- quartz/components/PageList.tsx | 14 +--- quartz/components/pages/FolderContent.tsx | 61 +++++++++++++- quartz/styles/base.scss | 97 +++++++++++++++++++++++ 3 files changed, 158 insertions(+), 14 deletions(-) diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index 1e5d232df0691..28e35d8b96945 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -42,7 +42,7 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit }: Pr const tags = page.frontmatter?.tags ?? [] return ( -
  • +
  • {page.dates && (

    @@ -56,18 +56,6 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit }: Pr

    -
  • ) diff --git a/quartz/components/pages/FolderContent.tsx b/quartz/components/pages/FolderContent.tsx index 55f1e427da35e..ab3338b3638bb 100644 --- a/quartz/components/pages/FolderContent.tsx +++ b/quartz/components/pages/FolderContent.tsx @@ -33,6 +33,15 @@ export default ((opts?: Partial) => { const isDirectChild = fileParts.length === folderParts.length + 1 return prefixed && isDirectChild }) + + // Get all unique tags + const allTags = new Set() + allPagesInFolder.forEach(file => { + const tags = file.frontmatter?.tags ?? [] + tags.forEach(tag => allTags.add(tag)) + }) + const sortedTags = Array.from(allTags).sort() + const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? [] const classes = ["popover-hint", ...cssClasses].join(" ") const listProps = { @@ -45,14 +54,63 @@ export default ((opts?: Partial) => { ? fileData.description : htmlToJsx(fileData.filePath!, tree) + // Add client-side filtering script + const filterScript = ` + document.addEventListener('DOMContentLoaded', () => { + const selectedTags = new Set() + const cards = document.querySelectorAll('.section-li') + const countEl = document.querySelector('.folder-count') + const originalCount = ${allPagesInFolder.length} + + function updateVisibility() { + let visibleCount = 0 + cards.forEach(card => { + const tags = JSON.parse(card.dataset.tags || '[]') + const shouldShow = selectedTags.size === 0 || + tags.some(tag => selectedTags.has(tag)) + card.style.display = shouldShow ? '' : 'none' + if (shouldShow) visibleCount++ + }) + if (countEl) { + countEl.textContent = ${JSON.stringify(i18n(cfg.locale).pages.folderContent.itemsUnderFolder({count: 0}))} + .replace('0', visibleCount.toString()) + } + } + + document.querySelectorAll('.tag-filter-btn').forEach(btn => { + btn.addEventListener('click', () => { + const tag = btn.dataset.tag + if (selectedTags.has(tag)) { + selectedTags.delete(tag) + btn.classList.remove('selected') + } else { + selectedTags.add(tag) + btn.classList.add('selected') + } + updateVisibility() + }) + }) + }) + ` + return (

    {content}

    +
    + {sortedTags.map(tag => ( + + ))} +
    {options.showFolderCount && ( -

    +

    {i18n(cfg.locale).pages.folderContent.itemsUnderFolder({ count: allPagesInFolder.length, })} @@ -62,6 +120,7 @@ export default ((opts?: Partial) => {

    +