1- import { RowDataType , NormalizedPath , TableDataType , TableColumn } from 'cdm/FolderModel' ;
1+ import { RowDataType , NormalizedPath , TableColumn } from 'cdm/FolderModel' ;
22import { Notice , TFile } from 'obsidian' ;
33import { VaultManagerDB } from 'services/FileManagerService' ;
44import { LOGGER } from "services/Logger" ;
@@ -12,7 +12,6 @@ import { DatabaseYaml } from 'cdm/DatabaseModel';
1212import { Literal } from 'obsidian-dataview/lib/data-model/value' ;
1313import { DataArray } from 'obsidian-dataview/lib/api/data-array' ;
1414import { EditionError } from 'errors/ErrorTypes' ;
15- import { TableStateInterface } from 'cdm/TableStateInterface' ;
1615import { LocalSettings } from 'cdm/SettingsModel' ;
1716
1817const noBreakSpace = / \u00A0 / g;
@@ -22,35 +21,34 @@ const noBreakSpace = /\u00A0/g;
2221 * @param data
2322 * @returns
2423 */
25- export function hasFrontmatterKey ( data : string | TFile ) : boolean {
24+ export function hasFrontmatter ( data : string ) : boolean {
2625 if ( ! data ) return false ;
2726
28- if ( typeof data === 'string' ) {
29- const frontmatterRegex = / ^ - - - [ \s \S ] + ?- - - / g;
30- return frontmatterRegex . test ( data ) ;
31- }
27+ const frontmatterRegex = / ^ - - - [ \s \S ] + ?- - - / g;
28+ return frontmatterRegex . test ( data ) ;
29+ }
3230
31+ /** Check if file is a database note */
32+ export function isDatabaseNote ( data : string | TFile ) {
3333 if ( data instanceof TFile ) {
34+ if ( ! data ) return false ;
35+
3436 const cache = app . metadataCache . getFileCache ( data ) ;
35- return ! ! cache ?. frontmatter && ! ! cache ?. frontmatter [ 'kanban-plugin' ] ;
36- }
3737
38- return false ;
39- }
38+ return ! ! cache ?. frontmatter && ! ! cache ?. frontmatter [ DatabaseCore . FRONTMATTER_KEY ] ;
39+ } else {
40+ const match = data . match ( / - - - \s + ( [ \w \W ] + ?) \s + - - - / ) ;
4041
41- /** Check if file is a database note */
42- export function isDatabaseNote ( data : string ) : boolean {
43- if ( ! data ) return false ;
44- const match = data . match ( / - - - \s + ( [ \w \W ] + ?) \s + - - - / ) ;
42+ if ( ! match ) {
43+ return false ;
44+ }
4545
46- if ( ! match ) {
47- return false ;
48- }
46+ if ( ! match [ 1 ] . contains ( DatabaseCore . FRONTMATTER_KEY ) ) {
47+ return false ;
48+ }
4949
50- if ( ! match [ 1 ] . contains ( DatabaseCore . FRONTMATTER_KEY ) ) {
51- return false ;
50+ return true ;
5251 }
53- return true ;
5452}
5553
5654export function getNormalizedPath ( path : string ) : NormalizedPath {
@@ -336,7 +334,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
336334 // Execute action
337335 if ( updateOptions [ option ] ) {
338336 // Check if file has frontmatter
339- if ( ! hasFrontmatterKey ( content ) ) {
337+ if ( ! hasFrontmatter ( content ) ) {
340338 // If not, add it
341339 await addFrontmatter ( ) ;
342340 }
0 commit comments