You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a problem when using the "Digital Garden: Add Publish Flag" feature. It seems to corrupt the meta-tags in the frontmatter. For example: dg-metatags: { description: "some description" }
gets replaced by: dg-metatags: [object Object]
This breaks the structure and format of the metadata.
Suggested Solution
To avoid this issue, I propose modifying the setPublishFlagValue() function so that only the dg-publish flag is updated without affecting other frontmatter fields. Here's an updated version of the function:
setPublishFlagValue(value) {
return __async(this, null, function* () {
const activeFile = this.getActiveFile(this.app.workspace);
if (!activeFile) {
return;
}
const fileContent = yield this.app.vault.read(activeFile);
// Extract the frontmatter by matching the first three lines
const frontMatterMatch = fileContent.match(/^---\n([\s\S]+?)\n---/);
if (!frontMatterMatch) {
// If no frontmatter exists, add it
const newFrontMatter = `---\ndg-publish: ${value}\n---\n\n${fileContent}`;
yield this.app.vault.modify(activeFile, newFrontMatter);
return;
}
// Parse the frontmatter
let frontMatter = frontMatterMatch[1];
// Modify only the "dg-publish" flag
if (/dg-publish:\s*(true|false)/.test(frontMatter)) {
// Replace the existing "dg-publish" flag
frontMatter = frontMatter.replace(/dg-publish:\s*(true|false)/, `dg-publish: ${value}`);
} else {
// If the "dg-publish" flag doesn't exist, add it
frontMatter += `\ndg-publish: ${value}`;
}
// Create the new file content
const newFileContent = fileContent.replace(/^---\n[\s\S]+?\n---/, `---\n${frontMatter}\n---`);
// Save the file with the updated frontmatter
yield this.app.vault.modify(activeFile, newFileContent);
});
}
Why This Works:
It directly manipulates the frontmatter, ensuring other fields like dg-metatags remain intact.
Only the dg-publish flag is updated or added if it doesn’t exist.
The rest of the frontmatter stays unchanged, avoiding issues with formatting or data loss.
The text was updated successfully, but these errors were encountered:
I encountered a problem when using the "Digital Garden: Add Publish Flag" feature. It seems to corrupt the meta-tags in the frontmatter. For example:
dg-metatags: { description: "some description" }
gets replaced by:
dg-metatags: [object Object]
This breaks the structure and format of the metadata.
Suggested Solution
To avoid this issue, I propose modifying the setPublishFlagValue() function so that only the dg-publish flag is updated without affecting other frontmatter fields. Here's an updated version of the function:
Why This Works:
It directly manipulates the frontmatter, ensuring other fields like dg-metatags remain intact.
Only the dg-publish flag is updated or added if it doesn’t exist.
The rest of the frontmatter stays unchanged, avoiding issues with formatting or data loss.
The text was updated successfully, but these errors were encountered: