@quartz-community/folder-page 1.0.0 → 1.0.1

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/dist/index.js CHANGED
@@ -279,6 +279,22 @@ function simplifySlug(fp) {
279
279
  const res = stripSlashes(trimSuffix(fp, "index"), true);
280
280
  return res.length === 0 ? "/" : res;
281
281
  }
282
+ function slugifyFilePath(fp, excludeExt) {
283
+ fp = stripSlashes(fp);
284
+ const ext = getFileExtension(fp);
285
+ const withoutFileExt = fp.replace(new RegExp(ext + "$"), "");
286
+ const finalExt = [".md", ".html", void 0].includes(ext) ? "" : ext;
287
+ let slug2 = _sluggify(withoutFileExt);
288
+ if (endsWith(slug2, "_index")) {
289
+ slug2 = slug2.replace(/_index$/, "index");
290
+ }
291
+ const segments = slug2.split("/");
292
+ if (segments.length >= 2 && segments[segments.length - 1] === segments[segments.length - 2]) {
293
+ segments[segments.length - 1] = "index";
294
+ slug2 = segments.join("/");
295
+ }
296
+ return slug2 + (finalExt ?? "");
297
+ }
282
298
  function joinSegments(...args) {
283
299
  if (args.length === 0) {
284
300
  return "";
@@ -312,6 +328,9 @@ function stripSlashes(s2, onlyStripPrefix) {
312
328
  }
313
329
  return s2;
314
330
  }
331
+ function getFileExtension(s2) {
332
+ return s2.match(/\.[A-Za-z0-9]+$/)?.[0];
333
+ }
315
334
  function isFolderPath(fplike) {
316
335
  return fplike.endsWith("/") || endsWith(fplike, "index") || endsWith(fplike, "index.md") || endsWith(fplike, "index.html");
317
336
  }
@@ -326,6 +345,14 @@ function resolveRelative(current, target) {
326
345
  const res = joinSegments(pathToRoot(current), simplifySlug(target));
327
346
  return res;
328
347
  }
348
+ function slugifyPath(s2) {
349
+ return s2.split("/").map(
350
+ (segment) => segment.replace(/\s/g, "-").replace(/&/g, "-and-").replace(/%/g, "-percent").replace(/\?/g, "").replace(/#/g, "").replace(/[<>:"|*]/g, "").toLowerCase()
351
+ ).join("/").replace(/\/$/, "");
352
+ }
353
+ function _sluggify(s2) {
354
+ return slugifyPath(s2);
355
+ }
329
356
 
330
357
  // node_modules/preact/dist/preact.mjs
331
358
  var n;
@@ -2723,7 +2750,8 @@ function pagesFromAllFiles(allFiles, folderSlug, showSubfolders) {
2723
2750
  const subfolderFiles = /* @__PURE__ */ new Map();
2724
2751
  for (const file of allFiles) {
2725
2752
  if (file.unlisted === true) continue;
2726
- const fileSlug = file.slug;
2753
+ const rel = file.relativePath;
2754
+ const fileSlug = rel ? slugifyFilePath(rel) : file.slug;
2727
2755
  if (!fileSlug || !fileSlug.startsWith(folderPrefix)) continue;
2728
2756
  const relativePath = fileSlug.slice(folderPrefix.length);
2729
2757
  if (!relativePath || relativePath === "index") continue;
@@ -2849,7 +2877,9 @@ var FolderPage = (opts) => {
2849
2877
  for (const file of allFiles) {
2850
2878
  const slug2 = file?.slug;
2851
2879
  if (!slug2) continue;
2852
- const fileFolders = getFolders(slug2).filter((f3) => f3 !== "." && f3 !== "tags");
2880
+ const rel = file?.relativePath;
2881
+ const position3 = rel ? slugifyFilePath(rel) : slug2;
2882
+ const fileFolders = getFolders(position3).filter((f3) => f3 !== "." && f3 !== "tags");
2853
2883
  for (const f3 of fileFolders) {
2854
2884
  folders.add(f3);
2855
2885
  }