@quartz-community/obsidian-plugin-excalidraw 1.0.1 → 1.1.0

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
@@ -488,8 +488,6 @@ var require_lz_string = __commonJS({
488
488
  }
489
489
  }
490
490
  });
491
-
492
- // node_modules/@quartz-community/utils/dist/path.js
493
491
  function isRelativeURL(s4) {
494
492
  const validStart = /^\.{1,2}/.test(s4);
495
493
  const validEnding = !endsWith(s4, "index");
@@ -4789,19 +4787,28 @@ var ExcalidrawBody_default = ((userOpts) => {
4789
4787
  var excalidrawMatcher = ({ fileData }) => {
4790
4788
  return "excalidrawData" in fileData;
4791
4789
  };
4790
+ var isDrawing = (path) => path.endsWith(".excalidraw.md") || path.endsWith(".excalidraw");
4791
+ var drawingNotesBuild;
4792
+ var drawingNotes = /* @__PURE__ */ new Map();
4793
+ function drawingNotesOf(ctx) {
4794
+ if (drawingNotesBuild !== ctx.buildId) {
4795
+ drawingNotesBuild = ctx.buildId;
4796
+ drawingNotes.clear();
4797
+ }
4798
+ return drawingNotes;
4799
+ }
4792
4800
  var ExcalidrawPage = (opts) => ({
4793
4801
  name: "ExcalidrawPage",
4794
4802
  priority: 25,
4795
4803
  fileExtensions: [".excalidraw.md", ".excalidraw"],
4796
4804
  match: excalidrawMatcher,
4797
4805
  generate({ ctx }) {
4798
- const excalidrawFiles = ctx.allFiles.filter(
4799
- (fp) => fp.endsWith(".excalidraw.md") || fp.endsWith(".excalidraw")
4800
- );
4806
+ const excalidrawFiles = ctx.allFiles.filter(isDrawing);
4801
4807
  const imageFiles = ctx.allFiles.filter(
4802
4808
  (fp) => /\.(png|jpe?g|gif|svg|webp|avif|bmp|ico)$/i.test(fp)
4803
4809
  );
4804
4810
  const virtualPages = [];
4811
+ const notes = drawingNotesOf(ctx);
4805
4812
  for (const filePath of excalidrawFiles) {
4806
4813
  const fullPath = join(ctx.argv.directory, filePath);
4807
4814
  let content;
@@ -4810,6 +4817,9 @@ var ExcalidrawPage = (opts) => ({
4810
4817
  } catch {
4811
4818
  continue;
4812
4819
  }
4820
+ const isNote = filePath.endsWith(".md");
4821
+ const noteFrontmatter = isNote ? notes.get(filePath) : void 0;
4822
+ if (isNote && !noteFrontmatter) continue;
4813
4823
  const data = parseExcalidraw(content, filePath);
4814
4824
  if (!data) continue;
4815
4825
  const resolvedImagePaths = {};
@@ -4827,12 +4837,18 @@ var ExcalidrawPage = (opts) => ({
4827
4837
  }
4828
4838
  }
4829
4839
  const baseName = filePath.replace(/\.excalidraw\.md$/, "").replace(/\.excalidraw$/, "").split("/").pop() ?? "Excalidraw Drawing";
4830
- const slug2 = slugifyFilePath(filePath);
4840
+ const slug = slugifyFilePath(filePath);
4831
4841
  virtualPages.push({
4832
- slug: slug2,
4842
+ slug,
4833
4843
  title: baseName,
4834
4844
  data: {
4835
- frontmatter: { title: baseName, tags: ["excalidraw"] },
4845
+ // The page stands for the drawing file: give it the source paths Quartz's parser
4846
+ // sets on notes (instead of the synthetic `<slug>.md`), so bases list it as that
4847
+ // file (file.ext "excalidraw", or "md" for a drawing stored as Markdown), and
4848
+ // folder listings and the content index see its real path.
4849
+ filePath: joinSegments(ctx.argv.directory, filePath),
4850
+ relativePath: filePath,
4851
+ frontmatter: { ...noteFrontmatter, title: baseName, tags: ["excalidraw"] },
4836
4852
  excalidrawData: data,
4837
4853
  excalidrawOptions: opts,
4838
4854
  excalidrawImagePaths: resolvedImagePaths
@@ -4841,12 +4857,13 @@ var ExcalidrawPage = (opts) => ({
4841
4857
  }
4842
4858
  return virtualPages;
4843
4859
  },
4844
- shouldPublish(_ctx, content) {
4845
- const relativePath = content[1].data.relativePath ?? "";
4846
- if (relativePath.endsWith(".excalidraw.md") || relativePath.endsWith(".excalidraw")) {
4847
- return false;
4848
- }
4849
- return true;
4860
+ shouldPublish(ctx, content) {
4861
+ const data = content[1].data;
4862
+ if ("excalidrawData" in data) return true;
4863
+ const relativePath = data.relativePath ?? "";
4864
+ if (!isDrawing(relativePath)) return true;
4865
+ drawingNotesOf(ctx).set(relativePath, { ...data.frontmatter ?? {} });
4866
+ return false;
4850
4867
  },
4851
4868
  layout: "excalidraw",
4852
4869
  frame: "excalidraw",