Skip to content

Commit

Permalink
🔄 synced local 'quartz/' with remote 'quartz/'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Feb 28, 2024
1 parent 5d6b94f commit 2646942
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 236 deletions.
128 changes: 64 additions & 64 deletions quartz/components/PageList.tsx
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
import { FullSlug, resolveRelative } from "../util/path"
import { QuartzPluginData } from "../plugins/vfile"
import { Date, getDate } from "./Date"
import { QuartzComponent, QuartzComponentProps } from "./types"
import { GlobalConfiguration } from "../cfg"
import { GlobalConfiguration } from "../cfg";
import { QuartzPluginData } from "../plugins/vfile";
import { FullSlug, resolveRelative } from "../util/path";
import { Date, getDate } from "./Date";
import { QuartzComponent, QuartzComponentProps } from "./types";

export function byDateAndAlphabetical(
cfg: GlobalConfiguration,
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
}
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;
}

// otherwise, sort lexographically by title
const f1Title = f1.frontmatter?.title.toLowerCase() ?? ""
const f2Title = f2.frontmatter?.title.toLowerCase() ?? ""
return f1Title.localeCompare(f2Title)
}
// otherwise, sort lexographically by title
const f1Title = f1.frontmatter?.title?.toLowerCase() ?? "";
const f2Title = f2.frontmatter?.title?.toLowerCase() ?? "";
return f1Title.localeCompare(f2Title);
};
}

type Props = {
limit?: number
} & QuartzComponentProps

export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit }: Props) => {
let list = allFiles.sort(byDateAndAlphabetical(cfg))
if (limit) {
list = list.slice(0, limit)
}
let list = allFiles.sort(byDateAndAlphabetical(cfg));
if (limit) {
list = list.slice(0, limit);
}

return (
<ul class="section-ul">
{list.map((page) => {
const title = page.frontmatter?.title
const tags = page.frontmatter?.tags ?? []
return (
<ul class="section-ul">
{list.map((page) => {
const title = page.frontmatter?.title;
const tags = page.frontmatter?.tags ?? [];

return (
<li class="section-li">
<div class="section">
{page.dates && (
<p class="meta">
<Date date={getDate(cfg, page)!} locale={cfg.locale} />
</p>
)}
<div class="desc">
<h3>
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
{title}
</a>
</h3>
</div>
<ul class="tags">
{tags.map((tag) => (
<li>
<a
class="internal tag-link"
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
>
return (
<li class="section-li">
<div class="section">
{page.dates && (
<p class="meta">
<Date date={getDate(cfg, page)!} locale={cfg.locale} />
</p>
)}
<div class="desc">
<h3>
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
{title}
</a>
</h3>
</div>
<ul class="tags">
{tags.map((tag) => (
<li>
<a
class="internal tag-link"
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
>
#{tag}
</a>
</li>
))}
</ul>
</div>
</li>
)
})}
</ul>
)
}
</a>
</li>
))}
</ul>
</div>
</li>
);
})}
</ul>
);
};

PageList.css = `
.section h3 {
Expand All @@ -84,4 +84,4 @@ PageList.css = `
.section > .tags {
margin: 0;
}
`
`;
28 changes: 14 additions & 14 deletions quartz/components/PageTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { pathToRoot } from "../util/path"
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
import { classNames } from "../util/lang"
import { i18n } from "../i18n"
import { i18n } from "../i18n";
import { classNames } from "../util/lang";
import { pathToRoot } from "../util/path";
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types";

const PageTitle: QuartzComponent = ({ fileData, cfg, displayClass }: QuartzComponentProps) => {
const title = cfg?.pageTitle ?? i18n(cfg.locale).propertyDefaults.title
const baseDir = pathToRoot(fileData.slug!)
return (
<h1 class={classNames(displayClass, "page-title")}>
<a href={baseDir}>{title}</a>
</h1>
)
}
const title = cfg?.pageTitle ?? i18n(cfg.locale).propertyDefaults.title;
const baseDir = pathToRoot(fileData.slug!);
return (
<h1 class={classNames(displayClass, "page-title")}>
<a href={baseDir}>{title}</a>
</h1>
);
};

PageTitle.css = `
.page-title {
margin: 0;
}
`
`;

export default (() => PageTitle) satisfies QuartzComponentConstructor
export default (() => PageTitle) satisfies QuartzComponentConstructor;
120 changes: 61 additions & 59 deletions quartz/components/pages/FolderContent.tsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,73 @@
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
import path from "path"
import { Root } from "hast";
import path from "path";

import style from "../styles/listPage.scss"
import { PageList } from "../PageList"
import { stripSlashes, simplifySlug } from "../../util/path"
import { Root } from "hast"
import { classNames } from "../../util/lang"
import { htmlToJsx } from "../../util/jsx"
import { i18n } from "../../i18n"
import { i18n } from "../../i18n";
import { htmlToJsx } from "../../util/jsx";
import { classNames } from "../../util/lang";
import { simplifySlug,stripSlashes } from "../../util/path";
import { PageList } from "../PageList";
import style from "../styles/listPage.scss";
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types";

interface FolderContentOptions {
/**
* Whether to display number of folders
*/
showFolderCount: boolean
/**
* Whether to display number of folders
*/
showFolderCount: boolean
}

const defaultOptions: FolderContentOptions = {
showFolderCount: true,
}
showFolderCount: true,
};

export default ((opts?: Partial<FolderContentOptions>) => {
const options: FolderContentOptions = { ...defaultOptions, ...opts }
const options: FolderContentOptions = { ...defaultOptions, ...opts };

const FolderContent: QuartzComponent = (props: QuartzComponentProps) => {
const { tree, fileData, allFiles, cfg } = props
const folderSlug = stripSlashes(simplifySlug(fileData.slug!))
const allPagesInFolder = allFiles.filter((file) => {
const fileSlug = stripSlashes(simplifySlug(file.slug!))
const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug
const folderParts = folderSlug.split(path.posix.sep)
const fileParts = fileSlug.split(path.posix.sep)
const isDirectChild = fileParts.length === folderParts.length + 1
return prefixed && isDirectChild
})
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
const listProps = {
...props,
allFiles: allPagesInFolder,
}
const FolderContent: QuartzComponent = (props: QuartzComponentProps) => {
const { tree, fileData, allFiles, cfg } = props;
const folderSlug = stripSlashes(simplifySlug(fileData.slug!));
const allPagesInFolder = allFiles.filter((file) => {
const fileSlug = stripSlashes(simplifySlug(file.slug!));
const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug;
const folderParts = folderSlug.split(path.posix.sep);
const fileParts = fileSlug.split(path.posix.sep);
const isDirectChild = fileParts.length === folderParts.length + 1;
return prefixed && isDirectChild;
});
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? [];
const listProps = {
...props,
allFiles: allPagesInFolder,
};

const content =
(tree as Root).children.length === 0
? fileData.description
: htmlToJsx(fileData.filePath!, tree)
const content =
(tree as Root).children.length === 0
? fileData.description
: htmlToJsx(fileData.filePath!, tree);

return (
<div class={classNames(undefined, "popover-hint", ...cssClasses)}>
<article>
<p>{content}</p>
</article>
<div class="page-listing">
{options.showFolderCount && (
<p>
{i18n(cfg.locale).pages.folderContent.itemsUnderFolder({
count: allPagesInFolder.length,
})}
</p>
)}
<div>
<PageList {...listProps} />
</div>
</div>
</div>
)
}
return (
<div class={classNames(undefined, "popover-hint", ...cssClasses)}>
<article>
<p>{content}</p>
</article>
{(!content || content?.props?.children?.length === 0) && (
<div class="page-listing">
{options.showFolderCount && (
<p>
{i18n(cfg.locale).pages.folderContent.itemsUnderFolder({
count: allPagesInFolder.length,
})}
</p>
)}
<div>
<PageList {...listProps} />
</div>
</div>
)}
</div>
);
};

FolderContent.css = style + PageList.css
return FolderContent
}) satisfies QuartzComponentConstructor
FolderContent.css = style + PageList.css;
return FolderContent;
}) satisfies QuartzComponentConstructor;
Loading

0 comments on commit 2646942

Please sign in to comment.