@quartz-community/folder-page 1.0.0 → 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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - bdb1aaa: Generate folder pages for folders that hold only virtual pages, such as `.base` or `.canvas` files rendered by bases-page / canvas-page, so going up a level no longer gives a 404 (jackyzha0/quartz#2576). Folder listings now also list a subfolder that has its own index page, and fall back to all pages when the folder is not in Quartz's folder hierarchy.
8
+ - 398001e: Bundles `@quartz-community/utils` 1.1.0: a short wikilink to an Obsidian folder note (`[[Topic]]` for `Topic/Topic.md`) reaches the folder page, and anchors to headings use the same slug as heading ids. `github-slugger` is no longer a dependency of this plugin.
9
+
10
+ ## 1.0.1
11
+
12
+ ### Patch Changes
13
+
14
+ - e7de665: A note with a frontmatter `permalink` (published at its permalink, Quartz 5.1+) stays in its folder in the folder listings, as in Obsidian Publish: pages are placed by their file path and linked by their address.
15
+
3
16
  ## 1.0.0
4
17
 
5
18
  ### Major Changes
@@ -287,12 +287,26 @@ function byDateAndAlphabetical() {
287
287
  return f1Title.localeCompare(f2Title);
288
288
  };
289
289
  }
290
-
291
- // node_modules/@quartz-community/utils/dist/path.js
292
290
  function simplifySlug(fp) {
293
291
  const res = stripSlashes(trimSuffix(fp, "index"), true);
294
292
  return res.length === 0 ? "/" : res;
295
293
  }
294
+ function slugifyFilePath(fp, excludeExt) {
295
+ fp = stripSlashes(fp);
296
+ const ext = getFileExtension(fp);
297
+ const withoutFileExt = fp.replace(new RegExp(ext + "$"), "");
298
+ const finalExt = [".md", ".html", void 0].includes(ext) ? "" : ext;
299
+ let slug2 = _sluggify(withoutFileExt);
300
+ if (endsWith(slug2, "_index")) {
301
+ slug2 = slug2.replace(/_index$/, "index");
302
+ }
303
+ const segments = slug2.split("/");
304
+ if (segments.length >= 2 && segments[segments.length - 1] === segments[segments.length - 2]) {
305
+ segments[segments.length - 1] = "index";
306
+ slug2 = segments.join("/");
307
+ }
308
+ return slug2 + (finalExt ?? "");
309
+ }
296
310
  function joinSegments(...args) {
297
311
  if (args.length === 0) {
298
312
  return "";
@@ -326,6 +340,9 @@ function stripSlashes(s2, onlyStripPrefix) {
326
340
  }
327
341
  return s2;
328
342
  }
343
+ function getFileExtension(s2) {
344
+ return s2.match(/\.[A-Za-z0-9]+$/)?.[0];
345
+ }
329
346
  function isFolderPath(fplike) {
330
347
  return fplike.endsWith("/") || endsWith(fplike, "index") || endsWith(fplike, "index.md") || endsWith(fplike, "index.html");
331
348
  }
@@ -340,6 +357,14 @@ function resolveRelative(current, target) {
340
357
  const res = joinSegments(pathToRoot(current), simplifySlug(target));
341
358
  return res;
342
359
  }
360
+ function slugifyPath(s2) {
361
+ return s2.split("/").map(
362
+ (segment) => segment.replace(/\s/g, "-").replace(/&/g, "-and-").replace(/%/g, "-percent").replace(/\?/g, "").replace(/#/g, "").replace(/[<>:"|*]/g, "").toLowerCase()
363
+ ).join("/").replace(/\/$/, "");
364
+ }
365
+ function _sluggify(s2) {
366
+ return slugifyPath(s2);
367
+ }
343
368
 
344
369
  // node_modules/preact/dist/preact.mjs
345
370
  var n;
@@ -2737,7 +2762,8 @@ function pagesFromAllFiles(allFiles, folderSlug, showSubfolders) {
2737
2762
  const subfolderFiles = /* @__PURE__ */ new Map();
2738
2763
  for (const file of allFiles) {
2739
2764
  if (file.unlisted === true) continue;
2740
- const fileSlug = file.slug;
2765
+ const rel = file.relativePath;
2766
+ const fileSlug = rel ? slugifyFilePath(rel) : file.slug;
2741
2767
  if (!fileSlug || !fileSlug.startsWith(folderPrefix)) continue;
2742
2768
  const relativePath = fileSlug.slice(folderPrefix.length);
2743
2769
  if (!relativePath || relativePath === "index") continue;
@@ -2754,7 +2780,10 @@ function pagesFromAllFiles(allFiles, folderSlug, showSubfolders) {
2754
2780
  }
2755
2781
  for (const [subfolderName, files] of subfolderFiles) {
2756
2782
  const indexFile = files.find((f3) => f3.slug === `${folderPrefix}${subfolderName}/index`);
2757
- if (indexFile) continue;
2783
+ if (indexFile) {
2784
+ if (indexFile.unlisted !== true) directChildren.push(indexFile);
2785
+ continue;
2786
+ }
2758
2787
  directChildren.push({
2759
2788
  slug: `${folderPrefix}${subfolderName}/index`,
2760
2789
  dates: mostRecentDatesFromEntries(files),
@@ -2801,16 +2830,15 @@ var FolderContent_default = ((opts) => {
2801
2830
  const FolderContent = (props) => {
2802
2831
  const { tree, fileData, allFiles, cfg } = props;
2803
2832
  const ctx = props.ctx;
2804
- const slug2 = fileData?.slug;
2805
- if (!slug2) return null;
2833
+ const slug = fileData?.slug;
2834
+ if (!slug) return null;
2806
2835
  const trie = ctx?.trie;
2807
2836
  let allPagesInFolder;
2808
- if (trie) {
2809
- const folder = trie.findNode(slug2.split("/"));
2810
- if (!folder) return null;
2837
+ const folder = trie?.findNode(slug.split("/"));
2838
+ if (folder) {
2811
2839
  allPagesInFolder = pagesFromTrie(folder, options.showSubfolders);
2812
2840
  } else {
2813
- allPagesInFolder = pagesFromAllFiles(allFiles ?? [], slug2, options.showSubfolders);
2841
+ allPagesInFolder = pagesFromAllFiles(allFiles ?? [], slug, options.showSubfolders);
2814
2842
  }
2815
2843
  const cssClasses = fileData?.frontmatter?.cssclasses ?? [];
2816
2844
  const classes = cssClasses.join(" ");