1
0

[frontmatter]: Include todo-list-completed

This commit is contained in:
Jon Michael Aanes 2024-10-01 11:50:33 +02:00
parent a962170436
commit 7cd847ce64
3 changed files with 31 additions and 13 deletions

View File

@ -200,6 +200,7 @@ class FavroFuse(fuse.Fuse):
org_id=card.organization_id.raw_id,
seq_id=card.seq_id.raw_id,
),
todo_list_completed = card.todo_list_completed,
)
return self.formatter.format_card_contents(card_contents)

View File

@ -5,6 +5,17 @@ import frontmatter
import marko
import marko.md_renderer
################################################################################
# FrontMatter keys
FM_KEY_TODO_LIST_COMPLETED = 'todo-list-completed'
FM_KEY_TAGS = 'tags'
FM_KEY_ASSIGNMENTS = 'assignments'
FM_KEY_DEPENDENCIES = 'dependencies'
FM_KEY_URL = 'url'
FM_KEY_ALIASES = 'aliases'
################################################################################
@dataclasses.dataclass(frozen=True)
class CardContents:
@ -15,6 +26,7 @@ class CardContents:
assignments: list[str]
card_dependencies: list[str]
url: str
todo_list_completed: bool | None
def format_obsidian_link(text: str) -> str:
@ -53,26 +65,28 @@ class CardFileFormatter:
if card.identifier and card.name:
aliases.append(f'{card.identifier}: {card.name}')
if aliases:
frontmatter_data['aliases'] = aliases
frontmatter_data[FM_KEY_ALIASES] = aliases
del aliases
if card.tags:
frontmatter_data['tags'] = card.tags
frontmatter_data[FM_KEY_TAGS] = card.tags
if card.url and self.obsidian_mode:
frontmatter_data['url'] = card.url
frontmatter_data[FM_KEY_URL] = card.url
if card.assignments:
frontmatter_data['assignments'] = card.assignments
frontmatter_data[FM_KEY_ASSIGNMENTS] = card.assignments
if self.obsidian_mode:
frontmatter_data['assignments'] = [
frontmatter_data[FM_KEY_ASSIGNMENTS] = [
format_obsidian_link(name)
for name in frontmatter_data['assignments']
for name in frontmatter_data[FM_KEY_ASSIGNMENTS]
]
if card.card_dependencies:
frontmatter_data['dependencies'] = card.card_dependencies
frontmatter_data[FM_KEY_DEPENDENCIES] = card.card_dependencies
if self.obsidian_mode:
frontmatter_data['dependencies'] = [
frontmatter_data[FM_KEY_DEPENDENCIES] = [
format_obsidian_link(name)
for name in frontmatter_data['dependencies']
for name in frontmatter_data[FM_KEY_DEPENDENCIES]
]
if card.todo_list_completed:
frontmatter_data[FM_KEY_TODO_LIST_COMPLETED] = card.todo_list_completed
# Card name
ls = []
@ -110,15 +124,16 @@ class CardFileFormatter:
document.children.remove(elem)
break
tags: list[str] = fm.metadata.get('tags', [])
tags: list[str] = fm.metadata.get(FM_KEY_TAGS, [])
assignments: list[str] = fm.metadata.get('assignments', [])
assignments: list[str] = fm.metadata.get(FM_KEY_ASSIGNMENTS, [])
assignments = [parse_obsidian_link(text) for text in assignments]
card_dependencies: list[str] = fm.metadata.get('dependencies', [])
card_dependencies: list[str] = fm.metadata.get(FM_KEY_DEPENDENCIES, [])
card_dependencies = [parse_obsidian_link(text) for text in card_dependencies]
url: list[str] = fm.metadata.get('url')
url: list[str] = fm.metadata.get(FM_KEY_URL)
todo_list_completed: bool | None = fm.metadata.get(FM_KEY_TODO_LIST_COMPLETED)
description = self.renderer.render_children(document).strip()
return CardContents(
@ -129,4 +144,5 @@ class CardFileFormatter:
assignments=assignments,
card_dependencies=card_dependencies,
url=url,
todo_list_completed=todo_list_completed,
)

View File

@ -32,6 +32,7 @@ dependencies:
tags:
- tag1
- tag2
todo-list-completed: true
---
# Name of Card