Skip to content

Commit

Permalink
refactor: separate metadata handling in ObsidianFormatService
Browse files Browse the repository at this point in the history
- Split generateMarkdownContent into three distinct methods
- Use Java text blocks for better readability
- Separate frontmatter (metadata) from note content generation
- Improve code organization and maintainability
  • Loading branch information
Neo Kusanagi committed Jan 10, 2025
1 parent a753e2b commit 1b1d014
Showing 1 changed file with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,30 @@ private String generateFilePath(String path, Note note) {
}

private String generateMarkdownContent(Note note) {
return "---\n"
+ "note_id: "
+ note.getId()
+ "\n"
+ "created_at: "
+ note.getCreatedAt()
+ "\n"
+ "updated_at: "
+ note.getUpdatedAt()
+ "\n"
+ "---\n"
+ "# "
+ note.getTopicConstructor()
+ "\n"
+ note.getDetails();
return generateFrontMatter(note) + generateNoteContent(note);
}

private String generateFrontMatter(Note note) {
return """
---
note_id: %d
created_at: %s
updated_at: %s
---
""".formatted(
note.getId(),
note.getCreatedAt(),
note.getUpdatedAt()
);
}

private String generateNoteContent(Note note) {
return """
# %s
%s""".formatted(
note.getTopicConstructor(),
note.getDetails()
);
}

private String sanitizeFileName(String fileName) {
Expand Down

0 comments on commit 1b1d014

Please sign in to comment.