mirror of
				https://github.com/jackyzha0/quartz.git
				synced 2025-11-04 04:49:49 +01:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			f334e78ed6
			...
			685c06ce2e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					685c06ce2e | ||
| 
						 | 
					3ae89a1d16 | ||
| 
						 | 
					4d6e7ccba9 | 
@ -131,7 +131,8 @@ Using this example, the display names of all `FileNodes` (folders + files) will
 | 
				
			|||||||
```ts title="quartz.layout.ts"
 | 
					```ts title="quartz.layout.ts"
 | 
				
			||||||
Component.Explorer({
 | 
					Component.Explorer({
 | 
				
			||||||
  mapFn: (node) => {
 | 
					  mapFn: (node) => {
 | 
				
			||||||
    return (node.displayName = node.displayName.toUpperCase())
 | 
					    node.displayName = node.displayName.toUpperCase()
 | 
				
			||||||
 | 
					    return node
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
@ -145,8 +146,12 @@ Note that this example filters on the title but you can also do it via slug or a
 | 
				
			|||||||
Component.Explorer({
 | 
					Component.Explorer({
 | 
				
			||||||
  filterFn: (node) => {
 | 
					  filterFn: (node) => {
 | 
				
			||||||
    // set containing names of everything you want to filter out
 | 
					    // set containing names of everything you want to filter out
 | 
				
			||||||
    const omit = new Set(["authoring content", "tags", "hosting"])
 | 
					    const omit = new Set(["authoring content", "tags", "advanced"])
 | 
				
			||||||
    return !omit.has(node.data.title.toLowerCase())
 | 
					
 | 
				
			||||||
 | 
					    // can also use node.slug or by anything on node.data
 | 
				
			||||||
 | 
					    // note that node.data is only present for files that exist on disk
 | 
				
			||||||
 | 
					    // (e.g. implicit folder nodes that have no associated index.md)
 | 
				
			||||||
 | 
					    return !omit.has(node.displayName.toLowerCase())
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
@ -159,7 +164,7 @@ You can access the tags of a file by `node.data.tags`.
 | 
				
			|||||||
Component.Explorer({
 | 
					Component.Explorer({
 | 
				
			||||||
  filterFn: (node) => {
 | 
					  filterFn: (node) => {
 | 
				
			||||||
    // exclude files with the tag "explorerexclude"
 | 
					    // exclude files with the tag "explorerexclude"
 | 
				
			||||||
    return node.data.tags.includes("explorerexclude") !== true
 | 
					    return node.data.tags?.includes("explorerexclude") !== true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,26 @@ import { GlobalConfiguration } from "../cfg"
 | 
				
			|||||||
export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number
 | 
					export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
 | 
					export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
 | 
				
			||||||
 | 
					  return (f1, f2) => {
 | 
				
			||||||
 | 
					    // Sort by date/alphabetical
 | 
				
			||||||
 | 
					    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
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // otherwise, sort lexographically by title
 | 
				
			||||||
 | 
					    const f1Title = f1.frontmatter?.title.toLowerCase() ?? ""
 | 
				
			||||||
 | 
					    const f2Title = f2.frontmatter?.title.toLowerCase() ?? ""
 | 
				
			||||||
 | 
					    return f1Title.localeCompare(f2Title)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function byDateAndAlphabeticalFolderFirst(cfg: GlobalConfiguration): SortFn {
 | 
				
			||||||
  return (f1, f2) => {
 | 
					  return (f1, f2) => {
 | 
				
			||||||
    // Sort folders first
 | 
					    // Sort folders first
 | 
				
			||||||
    const f1IsFolder = isFolderPath(f1.slug ?? "")
 | 
					    const f1IsFolder = isFolderPath(f1.slug ?? "")
 | 
				
			||||||
@ -38,7 +58,7 @@ type Props = {
 | 
				
			|||||||
} & QuartzComponentProps
 | 
					} & QuartzComponentProps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => {
 | 
					export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => {
 | 
				
			||||||
  const sorter = sort ?? byDateAndAlphabetical(cfg)
 | 
					  const sorter = sort ?? byDateAndAlphabeticalFolderFirst(cfg)
 | 
				
			||||||
  let list = allFiles.sort(sorter)
 | 
					  let list = allFiles.sort(sorter)
 | 
				
			||||||
  if (limit) {
 | 
					  if (limit) {
 | 
				
			||||||
    list = list.slice(0, limit)
 | 
					    list = list.slice(0, limit)
 | 
				
			||||||
 | 
				
			|||||||
@ -147,8 +147,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
 | 
				
			|||||||
  const container = searchElement.querySelector(".search-container") as HTMLElement
 | 
					  const container = searchElement.querySelector(".search-container") as HTMLElement
 | 
				
			||||||
  if (!container) return
 | 
					  if (!container) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const sidebar = container.closest(".sidebar") as HTMLElement
 | 
					  const sidebar = container.closest(".sidebar") as HTMLElement | null
 | 
				
			||||||
  if (!sidebar) return
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const searchButton = searchElement.querySelector(".search-button") as HTMLButtonElement
 | 
					  const searchButton = searchElement.querySelector(".search-button") as HTMLButtonElement
 | 
				
			||||||
  if (!searchButton) return
 | 
					  if (!searchButton) return
 | 
				
			||||||
@ -180,7 +179,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
 | 
				
			|||||||
  function hideSearch() {
 | 
					  function hideSearch() {
 | 
				
			||||||
    container.classList.remove("active")
 | 
					    container.classList.remove("active")
 | 
				
			||||||
    searchBar.value = "" // clear the input when we dismiss the search
 | 
					    searchBar.value = "" // clear the input when we dismiss the search
 | 
				
			||||||
    sidebar.style.zIndex = ""
 | 
					    if (sidebar) sidebar.style.zIndex = ""
 | 
				
			||||||
    removeAllChildren(results)
 | 
					    removeAllChildren(results)
 | 
				
			||||||
    if (preview) {
 | 
					    if (preview) {
 | 
				
			||||||
      removeAllChildren(preview)
 | 
					      removeAllChildren(preview)
 | 
				
			||||||
@ -192,7 +191,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  function showSearch(searchTypeNew: SearchType) {
 | 
					  function showSearch(searchTypeNew: SearchType) {
 | 
				
			||||||
    searchType = searchTypeNew
 | 
					    searchType = searchTypeNew
 | 
				
			||||||
    sidebar.style.zIndex = "1"
 | 
					    if (sidebar) sidebar.style.zIndex = "1"
 | 
				
			||||||
    container.classList.add("active")
 | 
					    container.classList.add("active")
 | 
				
			||||||
    searchBar.focus()
 | 
					    searchBar.focus()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user