I am using Obsidian and it uses ysml grammar. I want a command that shows the document…
Private research annotation
Sign in to add a private research label or note.
- User
I am using Obsidian and it uses ysml grammar. I want a command that shows the document created date'. Can you suggest?
- Assistant
Unfortunately, Obsidian uses its own proprietary metadata format called YAML, which is not a standardized markup language. Therefore, there's no built-in way to access the creation date of a document.
However, you can add a custom field to the YAML front matter of your documents to store the creation date. To do this, you could add the following code at the beginning of each of your documents:
yaml--- created_date: 2023-02-11 ---Then, you could create a custom command or plugin in Obsidian to extract and display the
created_datefield from the YAML front matter of your documents. The exact implementation of this would depend on your specific needs and the capabilities of the platform or tools you're using. - User
How can I make it automatically added?
- Assistant
If you want the creation date to be automatically added to the YAML front matter of your documents, you could write a custom plugin for Obsidian.
Here's an example of how you could do this in JavaScript, using the Obsidian API:
javascriptasync function addCreationDate(vaultPath) { const files = await obsidian.vault.listFiles(vaultPath); for (const file of files) { const filePath = path.join(vaultPath, file); const fileContent = await obsidian.vault.readFile(filePath); const parsed = matter(fileContent); if (!parsed.data.created_date) { parsed.data.created_date = new Date().toISOString().split("T")[0]; const newContent = matter.stringify(parsed.content, parsed.data); await obsidian.vault.writeFile(filePath, newContent); } } } - User
Where should add the code to?
- Assistant
To add the code, you will need to create a custom plugin for Obsidian. Here's a step-by-step guide on how to do that:
- Create a new directory for your plugin. You can name it anything you like, for example
obsidian-creation-date-plugin. - Create a new file in the plugin directory. You can name it
index.js, for example. - Open the
index.jsfile in a text editor and paste the code I provided earlier into the file. - Save the changes to the
index.jsfile. - Open Obsidian and navigate to the "Plugins" section of the settings.
- Click the "Install Local Plugin" button and select the plugin directory you created earlier.
- The plugin should now be installed and available in Obsidian.
You can run the
addCreationDatefunction whenever you want to update the creation dates of your documents. For example, you could run the function when your vault is opened, or you could trigger it manually using a custom command or button in the Obsidian interface.Note that you'll need to have Node.js and npm installed on your system to create and run a custom plugin for Obsidian. You'll also need to install the
gray-matterlibrary, which you can do by running the following command in the plugin directory: - Create a new directory for your plugin. You can name it anything you like, for example