@quartz-community/folder-page 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/components/index.js +9 -9
- package/dist/components/index.js.map +1 -1
- package/dist/index.js +37 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -273,8 +273,6 @@ function getDate(data) {
|
|
|
273
273
|
const dates = data.dates;
|
|
274
274
|
return dates?.[defaultDateType];
|
|
275
275
|
}
|
|
276
|
-
|
|
277
|
-
// node_modules/@quartz-community/utils/dist/path.js
|
|
278
276
|
function simplifySlug(fp) {
|
|
279
277
|
const res = stripSlashes(trimSuffix(fp, "index"), true);
|
|
280
278
|
return res.length === 0 ? "/" : res;
|
|
@@ -2768,7 +2766,10 @@ function pagesFromAllFiles(allFiles, folderSlug, showSubfolders) {
|
|
|
2768
2766
|
}
|
|
2769
2767
|
for (const [subfolderName, files] of subfolderFiles) {
|
|
2770
2768
|
const indexFile = files.find((f3) => f3.slug === `${folderPrefix}${subfolderName}/index`);
|
|
2771
|
-
if (indexFile)
|
|
2769
|
+
if (indexFile) {
|
|
2770
|
+
if (indexFile.unlisted !== true) directChildren.push(indexFile);
|
|
2771
|
+
continue;
|
|
2772
|
+
}
|
|
2772
2773
|
directChildren.push({
|
|
2773
2774
|
slug: `${folderPrefix}${subfolderName}/index`,
|
|
2774
2775
|
dates: mostRecentDatesFromEntries(files),
|
|
@@ -2815,16 +2816,15 @@ var FolderContent_default = ((opts) => {
|
|
|
2815
2816
|
const FolderContent = (props) => {
|
|
2816
2817
|
const { tree, fileData, allFiles, cfg } = props;
|
|
2817
2818
|
const ctx = props.ctx;
|
|
2818
|
-
const
|
|
2819
|
-
if (!
|
|
2819
|
+
const slug = fileData?.slug;
|
|
2820
|
+
if (!slug) return null;
|
|
2820
2821
|
const trie = ctx?.trie;
|
|
2821
2822
|
let allPagesInFolder;
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
if (!folder) return null;
|
|
2823
|
+
const folder = trie?.findNode(slug.split("/"));
|
|
2824
|
+
if (folder) {
|
|
2825
2825
|
allPagesInFolder = pagesFromTrie(folder, options.showSubfolders);
|
|
2826
2826
|
} else {
|
|
2827
|
-
allPagesInFolder = pagesFromAllFiles(allFiles ?? [],
|
|
2827
|
+
allPagesInFolder = pagesFromAllFiles(allFiles ?? [], slug, options.showSubfolders);
|
|
2828
2828
|
}
|
|
2829
2829
|
const cssClasses = fileData?.frontmatter?.cssclasses ?? [];
|
|
2830
2830
|
const classes = cssClasses.join(" ");
|
|
@@ -2851,11 +2851,11 @@ var FolderContent_default = ((opts) => {
|
|
|
2851
2851
|
FolderContent.css = concatenateResources(listPage_default, PageList.css);
|
|
2852
2852
|
return FolderContent;
|
|
2853
2853
|
});
|
|
2854
|
-
var folderMatcher = ({ slug
|
|
2855
|
-
return
|
|
2854
|
+
var folderMatcher = ({ slug }) => {
|
|
2855
|
+
return slug.endsWith("/index");
|
|
2856
2856
|
};
|
|
2857
|
-
function getFolders(
|
|
2858
|
-
let folderName = path.dirname(
|
|
2857
|
+
function getFolders(slug) {
|
|
2858
|
+
let folderName = path.dirname(slug ?? "");
|
|
2859
2859
|
const parentFolderNames = [folderName];
|
|
2860
2860
|
while (folderName !== ".") {
|
|
2861
2861
|
folderName = path.dirname(folderName ?? "");
|
|
@@ -2863,29 +2863,38 @@ function getFolders(slug2) {
|
|
|
2863
2863
|
}
|
|
2864
2864
|
return parentFolderNames;
|
|
2865
2865
|
}
|
|
2866
|
+
function virtualPagesOf(ctx) {
|
|
2867
|
+
const pages = ctx?.virtualPages;
|
|
2868
|
+
return Array.isArray(pages) ? pages : [];
|
|
2869
|
+
}
|
|
2866
2870
|
var FolderPage = (opts) => {
|
|
2867
2871
|
const body = () => FolderContent_default(opts);
|
|
2868
2872
|
return {
|
|
2869
2873
|
name: "FolderPage",
|
|
2870
2874
|
priority: 10,
|
|
2871
2875
|
match: folderMatcher,
|
|
2872
|
-
generate({ content, cfg }) {
|
|
2873
|
-
const
|
|
2876
|
+
generate({ content, cfg, ctx }) {
|
|
2877
|
+
const virtual = virtualPagesOf(ctx).filter((c2) => {
|
|
2878
|
+
const slug = c2[1].data?.slug;
|
|
2879
|
+
return !!slug && slug !== "tags" && !slug.startsWith("tags/");
|
|
2880
|
+
});
|
|
2881
|
+
const files = [...content, ...virtual];
|
|
2882
|
+
const allFiles = files.map((c2) => c2[1].data).filter((d2) => d2?.unlisted !== true);
|
|
2874
2883
|
const locale = cfg?.locale ?? "en-US";
|
|
2875
2884
|
const folders = /* @__PURE__ */ new Set();
|
|
2876
2885
|
const folderDisplayNames = /* @__PURE__ */ new Map();
|
|
2877
2886
|
for (const file of allFiles) {
|
|
2878
|
-
const
|
|
2879
|
-
if (!
|
|
2887
|
+
const slug = file?.slug;
|
|
2888
|
+
if (!slug) continue;
|
|
2880
2889
|
const rel = file?.relativePath;
|
|
2881
|
-
const position3 = rel ? slugifyFilePath(rel) :
|
|
2890
|
+
const position3 = rel ? slugifyFilePath(rel) : slug;
|
|
2882
2891
|
const fileFolders = getFolders(position3).filter((f3) => f3 !== "." && f3 !== "tags");
|
|
2883
2892
|
for (const f3 of fileFolders) {
|
|
2884
2893
|
folders.add(f3);
|
|
2885
2894
|
}
|
|
2886
2895
|
const relativePath = file?.relativePath;
|
|
2887
2896
|
if (relativePath) {
|
|
2888
|
-
const slugParts = path.dirname(
|
|
2897
|
+
const slugParts = path.dirname(slug).split("/").filter((s2) => s2 !== ".");
|
|
2889
2898
|
const pathParts = path.dirname(relativePath).split("/").filter((s2) => s2 !== ".");
|
|
2890
2899
|
for (let i2 = 0; i2 < slugParts.length && i2 < pathParts.length; i2++) {
|
|
2891
2900
|
const slugPart = slugParts[i2];
|
|
@@ -2897,21 +2906,21 @@ var FolderPage = (opts) => {
|
|
|
2897
2906
|
}
|
|
2898
2907
|
}
|
|
2899
2908
|
const foldersWithIndex = /* @__PURE__ */ new Set();
|
|
2900
|
-
for (const [, file] of
|
|
2909
|
+
for (const [, file] of files) {
|
|
2901
2910
|
const data = file.data;
|
|
2902
2911
|
if (data?.unlisted === true) continue;
|
|
2903
|
-
const
|
|
2904
|
-
if (
|
|
2905
|
-
const folder =
|
|
2912
|
+
const slug = data?.slug;
|
|
2913
|
+
if (slug && slug.endsWith("/index")) {
|
|
2914
|
+
const folder = slug.slice(0, -"/index".length);
|
|
2906
2915
|
foldersWithIndex.add(folder);
|
|
2907
2916
|
}
|
|
2908
2917
|
}
|
|
2909
2918
|
for (const [, file] of content) {
|
|
2910
|
-
const
|
|
2911
|
-
if (!
|
|
2919
|
+
const slug = file.data?.slug;
|
|
2920
|
+
if (!slug || !slug.endsWith("/index")) continue;
|
|
2912
2921
|
const frontmatter = file.data.frontmatter;
|
|
2913
2922
|
if (!frontmatter || frontmatter.title && frontmatter.title !== "index") continue;
|
|
2914
|
-
const folder =
|
|
2923
|
+
const folder = slug.slice(0, -"/index".length);
|
|
2915
2924
|
const slugSegment = folder.split("/").pop() ?? folder;
|
|
2916
2925
|
const folderName = folderDisplayNames.get(slugSegment) ?? slugSegment;
|
|
2917
2926
|
frontmatter.title = opts?.prefixFolders ? `${i18n(locale).pages.folderContent.folder}: ${folderName}` : folderName;
|
|
@@ -2919,12 +2928,12 @@ var FolderPage = (opts) => {
|
|
|
2919
2928
|
const virtualPages = [];
|
|
2920
2929
|
for (const folder of folders) {
|
|
2921
2930
|
if (foldersWithIndex.has(folder)) continue;
|
|
2922
|
-
const
|
|
2931
|
+
const slug = joinSegments(folder, "index");
|
|
2923
2932
|
const slugSegment = folder.split("/").pop() ?? folder;
|
|
2924
2933
|
const folderName = folderDisplayNames.get(slugSegment) ?? slugSegment;
|
|
2925
2934
|
const title = opts?.prefixFolders ? `${i18n(locale).pages.folderContent.folder}: ${folderName}` : folderName;
|
|
2926
2935
|
virtualPages.push({
|
|
2927
|
-
slug
|
|
2936
|
+
slug,
|
|
2928
2937
|
title,
|
|
2929
2938
|
data: {}
|
|
2930
2939
|
});
|