Posted on:February 2, 2025 at 02:30 AM

Collecting Work Related Sections from Journals in Obsidian using Dataviewjs

Collecting Work Related Sections from Journals in Obsidian using Dataviewjs

When writing daily journals in Obsidian, if you want to collect only the work-related sections and display them on a separate page, you can do the following:

  1. Create a work log section in your journal:
## Work

- Meeting
- Emails
- Emails
- Emails
- Emails

## Fun
  1. Create a page for your work log:
pages/work2025.md
  1. Go to community plugin settings, select Dataview and enable “Enable Javascript Queries”: dataview settings

  2. Copy and paste the following code into your work log page, pages/work2025.md


```dataviewjs
const files = dv.pages('"journals/2025"').sort(page => page.file.name);
for (let page of files) {
  try {
    // Get the TFile object
    const tfile = app.vault.getAbstractFileByPath(page.file.path);
    
    if (tfile) {
      // Read the file content
      const content = await app.vault.read(tfile);
      if (content) {
        // Look for Work section
        const workMatch = content.match(/#+.*Work\n([\s\S]*?)(?=\n#+|$)/i);
        if (workMatch) {
          // Parse date from filename (assuming format YYYY-MM-DD)
          const dateMatch = page.file.name.match(/\d{4}-\d{2}-\d{2}/);
          if (dateMatch) {
            const date = new Date(dateMatch[0]);
            const dayOfWeek = date.toLocaleDateString('en-US', { weekday: 'short' });
            dv.header(3, `[[${page.file.name}]] ${dayOfWeek}`);
          } else {
            dv.header(3, `[[${page.file.name}]]`);
          }
          dv.el("div", workMatch[1].trim());
        }
      }
    }
  } catch (error) {
      dv.paragraph(`Error processing ${page.file.name}: ${error.message}`);
  }
}

This will collect all entries from the ## Work Log section in all documents within the journal/2025 directory and display them in /pages/work2025. obsidian result

This page is read-only. If you want to make changes, you need to edit the original journal entry.

This method allows you to continue writing in your journal while being able to review your work progress at a glance when needed.