Skip to content

Commit

Permalink
fix bug with recognizing frontmatter topic tags (led to missing cards…
Browse files Browse the repository at this point in the history
… shown for review) (#920)

* Fixed and ready for beta testing

* Updated comment
  • Loading branch information
ronzulu authored Mar 27, 2024
1 parent 52a66a1 commit 46fbdf9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased]

- [BUG] Plugin not picking up certain flashcards https://github.com/st3v3nmw/obsidian-spaced-repetition/issues/915

#### [1.12.1](https://github.com/st3v3nmw/obsidian-spaced-repetition/compare/1.12.0...1.12.1)

- [Overhaul] Implementation of a more consistent & modern UI [`#899`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/899)
Expand Down
7 changes: 4 additions & 3 deletions src/SRFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MetadataCache, TFile, Vault, HeadingCache, TagCache, FrontMatterCache } from "obsidian";
import { parseObsidianFrontmatterTag } from "./util/utils";

export interface ISRFile {
get path(): string;
Expand Down Expand Up @@ -52,11 +53,11 @@ export class SrTFile implements ISRFile {
// in the file)
const line: number = 1;

// Frontmatter tags are comma separated and don't include the "#", so we need to add that in
const tagStrList: string[] = frontmatterTags.split(",");
// Parse the frontmatter tag string into a list, each entry including the leading "#"
const tagStrList: string[] = parseObsidianFrontmatterTag(frontmatterTags);
for (const str of tagStrList) {
const tag: TagCache = {
tag: "#" + str,
tag: str,
position: {
start: { line: line, col: null, offset: null },
end: { line: line, col: null, offset: null },
Expand Down
62 changes: 62 additions & 0 deletions src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,65 @@ export function findLineIndexOfSearchStringIgnoringWs(
}
return result;
}

/*
Prompted by flashcards being missed, here are some "experiments" with different frontmatter,
showing the difference in the value of CachedMetadata.frontmatter["tags"]
----------------- EXPERIMENT 1
---
tags:
- flashcards/philosophy/philosophers
- flashcards/toes
---
CachedMetadata.frontmatter["tags"]: flashcards/philosophy/philosophers,flashcards/toes
----------------- EXPERIMENT 2
---
tags:
- "#flashcards/philosophy/philosophers"
---
CachedMetadata.frontmatter["tags"]: #flashcards/philosophy/philosophers
----------------- EXPERIMENT 3
---
tags:
- "#flashcards/philosophy/philosophers"
- "#flashcards/toes"
---
CachedMetadata.frontmatter["tags"]: #flashcardsX/philosophy/philosophers,#flashcardsX/toes
----------------- EXPERIMENT 4
---
tags:
- #flashcards/philosophy/philosophers
---
Obsidian does not recognize that the frontmatter has any tags
(i.e. if the frontmatter includes the "#" it must be enclosed in quotes)
----------------- CONCLUSION
CachedMetadata.frontmatter["tags"]: tags are comma separated. They may or may not include the "#".
Any double quotes in the frontmatter are stripped by Obsidian and not present in this variable.
*/

export function parseObsidianFrontmatterTag(tagStr: string): string[] {
const result: string[] = [] as string[];
const tagStrList: string[] = tagStr.split(",");
for (const tag of tagStrList) {
result.push(tag.startsWith("#") ? tag : "#" + tag);
}
return result;
}

0 comments on commit 46fbdf9

Please sign in to comment.