Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: some dataviewjs query not being converted into plain text #369

Open
2 tasks done
ThinkWithPbody opened this issue Nov 27, 2024 · 1 comment
Open
2 tasks done
Assignees
Labels

Comments

@ThinkWithPbody
Copy link

Issue validation

  • I checked the issue to prevent duplicate
  • I checked my configurations files and the documentation

Command used

Upload single current active note

Plugin version

7.4.0

Describe the bug

In my test files there are two dataviewjs queries, the simple one works and the other doesn't. Both queries have been provided in the example section, the relevant options are turned on under plugin settings, and the result is this:

Image

The field looks as such in Obsidian:

Image

There are no errors in the console. Thanks again for actively maintaining this plugin!

How to reproduce ?

No response

Minimal Reproducible Example

## Tagged 
`#Courses/2024/ARC2047H-Building_Science_Materials_and_Construction_3`



// Load pages and fetch content
const pagesWithQuotes = await Promise.all(
  dv.pages("#Courses/2024/ARC2047H-Building_Science_Materials_and_Construction_3").map(pageWithQuote =>
    dv.io.load(pageWithQuote.file.path).then(content => ({
      link: pageWithQuote.file.link,
      content,
      created: pageWithQuote.file.ctime,
      modified: pageWithQuote.file.mtime,
    }))
  )
);

// Sort pages by modification date
const sortedPages = pagesWithQuotes.sort((a, b) => b.modified - a.modified);

// Function to extract quotes
const extractQuotes = (content, tag) =>
  content
    .split("# ")
    .filter((p) => p.includes(tag) && !p.includes("#timelog"))
    .map((quote) => quote.replace(tag, "").replace(/#/g, "").replace(/\n/g, "\n> > "));

// Function to extract timelog entries
const extractTimelog = (content, tag) =>
  content
    .split("\n")
    .filter((line) => line.includes(tag) && line.includes("#timelog"))
    .map((entry) => entry.replace("#timelog", "").replace(tag, ""));

// Initialize quote data
let notes = "";
sortedPages.forEach(({ link, content }) => {
  const quotes = extractQuotes(content, "#Courses/2024/ARC2047H-Building_Science_Materials_and_Construction_3");
  if (quotes.length > 0) {
    notes += `> \n> > [!grey]- Notes from ${link}: `;
    quotes.forEach((quote) => {
      notes += `${quote}\n> \n`;
    });
  }
});

// Initialize timelog data
let timelog = "";
let timelogSum = { hours: 0, minutes: 0 };

sortedPages.forEach(({ link, content }) => {
  const entries = extractTimelog(content, "#Courses/2024/ARC2047H-Building_Science_Materials_and_Construction_3");
  entries.forEach((entry) => {
    const regex = /date\(([^)]+)\)\s*-\s*date\(([^)]+)\)\s*`?(.*)/;
    const matches = entry.trim().match(regex);

    if (matches && matches.length === 4) {
      const [_, start, end, description] = matches;
      const durationMinutes = Math.floor((dv.date(end) - dv.date(start)) / (1000 * 60));
      const hours = Math.floor(durationMinutes / 60);
      const minutes = durationMinutes % 60;

      timelog += `> > ${link}    |    ${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}    |    ${description}\n`;
      timelogSum.hours += hours;
      timelogSum.minutes += minutes;
    }
  });
});

// Adjust total time to correct hours and minutes format
timelogSum.hours += Math.floor(timelogSum.minutes / 60);
timelogSum.minutes = timelogSum.minutes % 60;

// Display organized output
dv.paragraph(`> [!white]+ Notes:\n${notes}`);
dv.paragraph(
  `> [!white]+ Timelog:\n> Total: ${timelogSum.hours} Hours, ${timelogSum.minutes} Minutes\n> > [!grey]- Hours:\n${timelog}`
);




dv.paragraph("Test")

Configuration

{
  "github": {
    "branch": "v4",
    "automaticallyMergePR": true,
    "dryRun": {
      "enable": false,
      "folderName": "enveloppe"
    },
    "tokenPath": "%configDir%/plugins/%pluginID%/env",
    "api": {
      "tiersForApi": "Github Free/Pro/Team (default)",
      "hostname": ""
    },
    "workflow": {
      "commitMessage": "[ENVELOPPE] Merge",
      "name": ""
    },
    "verifiedRepo": true
  },
  "upload": {
    "behavior": "obsidian",
    "defaultName": "content",
    "rootFolder": "",
    "yamlFolderKey": "",
    "frontmatterTitle": {
      "enable": false,
      "key": "title"
    },
    "replaceTitle": [],
    "replacePath": [],
    "autoclean": {
      "includeAttachments": true,
      "enable": true,
      "excluded": []
    },
    "folderNote": {
      "enable": false,
      "rename": "index.md",
      "addTitle": {
        "enable": false,
        "key": "title"
      }
    },
    "metadataExtractorPath": ""
  },
  "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [],
    "tags": {
      "inline": true,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": true,
      "unshared": true,
      "wiki": false,
      "slugify": true,
      "unlink": false
    }
  },
  "embed": {
    "attachments": true,
    "overrideAttachments": [],
    "keySendFile": [],
    "notes": true,
    "folder": "",
    "convertEmbedToLinks": "keep",
    "charConvert": "->",
    "unHandledObsidianExt": [
      "py"
    ],
    "sendSimpleLinks": true,
    "forcePush": true,
    "useObsidianFolder": true
  },
  "plugin": {
    "shareKey": "share",
    "excludedFolder": [
      "Configs/Templater",
      "Family/Finance",
      "Family/Recipe"
    ],
    "copyLink": {
      "enable": true,
      "links": "https://thinkwithpbody.github.io/Yifu-Pages/",
      "removePart": [
        "content",
        ".md"
      ],
      "transform": {
        "toUri": true,
        "slugify": "disable",
        "applyRegex": [
          {
            "regex": "/(?!.*\\/)",
            "replacement": ""
          }
        ]
      }
    },
    "setFrontmatterKey": "Set"
  },
  "tabsId": "text-conversion"
}

Relevant log output

plugin:obsidian-mkdocs-publisher:202 2024-11-27 03:04:36.621	INFO		Enveloppe	Branch successfully created (status: 201) on ThinkWithPbody/Yifu-Pages

OS

Windows

Anything else?

No response

Obsidian information

SYSTEM INFO:
	Obsidian version: v1.7.7
	Installer version: v1.6.7
	Operating system: Windows 10 Enterprise 10.0.19045
	Login status: not logged in
	Language: en
	Insider build toggle: off
	Live preview: on
	Base theme: light
	Community theme: Minimal v7.4.6
	Snippets enabled: 3
	Restricted mode: off
	Plugins installed: 37
	Plugins enabled: 33
		1: Google Calendar v1.10.15
		2: Recent Files v1.7.2
		3: Tasks v7.13.0
		4: Advanced Tables v0.22.1
		5: Excalidraw v2.6.7
		6: Iconize v2.14.4
		7: Dataview v0.5.67
		8: Tag Wrangler v0.6.1
		9: Find orphaned files and broken links v1.10.1
		10: Better Word Count v0.10.1
		11: Emoji Toolbar v0.4.1
		12: Advanced Slides v1.20.0
		13: Periodic Notes v0.0.17
		14: Paste URL into selection v1.7.0
		15: Calendar v1.5.10
		16: Hover Editor v0.11.21
		17: Commander v0.5.2
		18: Minimal Theme Settings v8.1.1
		19: Sortable v0.3.1
		20: Templater v2.9.1
		21: Path Finder v1.1.7
		22: ExcaliBrain v0.2.15
		23: Omnisearch v1.25.1
		24: Text Extractor v0.5.2
		25: QuickAdd v1.11.5
		26: Map View v5.0.3
		27: Outliner v4.8.1
		28: Attachment Management v0.9.16
		29: Enveloppe v7.4.0
		30: April's Automatic Timelines v0.13.6
		31: Pandoc Plugin v0.4.1
		32: Better Search Views v0.2.2
		33: PDF++ v0.40.13

RECOMMENDATIONS:
	Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.
@ThinkWithPbody ThinkWithPbody added the 🐛 Bug Something isn't working label Nov 27, 2024
@Mara-Li
Copy link
Member

Mara-Li commented Nov 28, 2024

See multiple issue around Dataview…
I will try to check but I don't think I will :/. The API of Dataview is broken from more than 2 years now, and I needed to make a fork for this…

@Mara-Li Mara-Li added dataview and removed 🐛 Bug Something isn't working labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants