Skip to content

Commit

Permalink
fix: Uploading note without frontmatter lead to empty notes
Browse files Browse the repository at this point in the history
closes #276
  • Loading branch information
Mara-Li committed Jan 18, 2024
1 parent 53a1f11 commit f5bbed1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/conversion/convert_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,22 @@ function tagsToYaml(toAdd: string[], settings: GitHubPublisherSettings, yaml: an
*/

export function addToYaml(text: string, toAdd: string[], settings: GitHubPublisherSettings, folderNoteParaMeters?: { properties: MultiProperties, file: TFile}): string {
const yaml = text.split("---")[1];
const yaml = text.split("---")?.[1];
let yamlObject = yaml ? parseYaml(yaml) : {};
if (toAdd.length > 0) {
if (yamlObject && toAdd.length > 0) {
yamlObject = tagsToYaml(toAdd, settings, yamlObject);
}
if (folderNoteParaMeters) {
yamlObject = titleToYaml(yamlObject, folderNoteParaMeters.properties, folderNoteParaMeters.file);
}
const returnToYaml = stringifyYaml(yamlObject);
const fileContentsOnly = text.split("---").slice(2).join("---");
return `---\n${returnToYaml}---\n${fileContentsOnly}`;
if (Object.keys(yamlObject).length > 0) {
const returnToYaml = stringifyYaml(yamlObject);
if (yaml){
const fileContentsOnly = text.split("---").slice(2).join("---");
return `---\n${returnToYaml}---\n${fileContentsOnly}`;
} else return `---\n${returnToYaml}---\n${text}`;
}
return text;
}

//eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit f5bbed1

Please sign in to comment.