Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 5547819

Browse files
committed
centinels changed
1 parent 95aa43a commit 5547819

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

TestVault/template/database.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ database-plugin: basic
44

55
---
66

7-
<%%
7+
%% dbfolder:yaml
88
name: new database
99
description: new description
1010
columns:
@@ -137,4 +137,4 @@ config:
137137
source_form_result:
138138
show_metadata_tasks: true
139139
filters:
140-
%%>
140+
%%

docs/docs/about.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ Each database has a yaml local configuration that is read when you open the data
3939
database-plugin: basic
4040

4141
---
42-
<%%
43-
---
44-
45-
database-plugin: basic
46-
47-
---
48-
<%%
42+
%% dbfolder:yaml
4943
name: Entertaiment
5044
description: All media contain that I consume
5145
columns:
@@ -173,5 +167,5 @@ config:
173167
source_data: current_folder
174168
source_form_result: zettelcaster/meet
175169
filters:
176-
%%>
170+
%%
177171
```

src/helpers/CommandsHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function generateNewDatabase(ddbbConfig: string, folder?: TFolder,
2020
.concat('\n')
2121
.concat(ddbbConfig)
2222
.concat('\n')
23-
.concat('%%>')
23+
.concat('%%')
2424
);
2525
await app.workspace.getMostRecentLeaf().setViewState({
2626
type: DatabaseCore.FRONTMATTER_KEY,

src/helpers/Constants.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const DatabaseFrontmatterOptions = Object.freeze({
203203
'',
204204
'---',
205205
'',
206-
'<%%',
206+
'%% dbfolder:yaml',
207207
'name: new database',
208208
'description: new description',
209209
'columns:',
@@ -354,7 +354,18 @@ export const DEFAULT_SETTINGS: DatabaseSettings = {
354354
}
355355
};
356356
/******************************************************************************
357-
* SUGGESTER CONSTANTS
357+
* DATABASE_CONFIG REGEX
358+
******************************************************************************/
359+
export const DATABASE_CONFIG = Object.freeze({
360+
YAML: /%%\sdbfolder:yaml\s+([\w\W]+?)\s+%%/,
361+
REPLACE_YAML_REGEX: new RegExp(`<%%\\s+([\\w\\W]+?)\\s+%%>`, "g"),
362+
START_CENTINEL: '%% dbfolder:yaml',
363+
END_CENTINEL: '%%',
364+
START_CENTINEL_LEGACY: '<%%',
365+
END_CENTINEL_LEGACY: '%%>',
366+
});
367+
/******************************************************************************
368+
* SUGGESTER REGEX
358369
******************************************************************************/
359370
export const SUGGESTER_REGEX = Object.freeze({
360371
LINK: /\B\[\[([^\]]*)$/,
@@ -368,7 +379,7 @@ export const SUGGESTER_REGEX = Object.freeze({
368379
});
369380

370381
/******************************************************************************
371-
* ICONS CONSTANTS
382+
* ICONS
372383
******************************************************************************/
373384
export const DB_ICONS = Object.freeze({
374385
NAME: 'database-folder-icon',

src/services/DatabaseInfo.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ConfigColumn, NoteContentAction } from 'cdm/FolderModel';
1010
import { FilterCondition, FilterSettings, LocalSettings } from 'cdm/SettingsModel';
1111
import { isDatabaseNote } from 'helpers/VaultManagement';
1212
import DatabaseStringToYamlParser from 'parsers/DatabaseStringToYamlParser';
13+
import { DATABASE_CONFIG } from 'helpers/Constants';
1314

1415
export default class DatabaseInfo {
1516
private file: TFile;
@@ -25,10 +26,13 @@ export default class DatabaseInfo {
2526
*/
2627
async initDatabaseconfigYaml(default_local_settings: LocalSettings): Promise<void> {
2728
LOGGER.info(`=>initDatabaseconfigYaml`, `file:${this.file.path}`);
28-
const databaseRaw = await VaultManagerDB.obtainContentFromTfile(this.file);
29+
let databaseRaw = await VaultManagerDB.obtainContentFromTfile(this.file);
2930
if (!databaseRaw || !isDatabaseNote(databaseRaw)) throw new Error('No frontmatter found');
31+
// Temporal migration centinels code
32+
databaseRaw = databaseRaw.replaceAll(DATABASE_CONFIG.START_CENTINEL_LEGACY, DATABASE_CONFIG.START_CENTINEL);
33+
databaseRaw = databaseRaw.replaceAll(DATABASE_CONFIG.END_CENTINEL_LEGACY, DATABASE_CONFIG.END_CENTINEL);
3034

31-
const match = databaseRaw.match(/<%%\s+([\w\W]+?)\s+%%>/);
35+
const match = databaseRaw.match(DATABASE_CONFIG.YAML);
3236

3337
if (!match) {
3438
return null;
@@ -52,14 +56,13 @@ export default class DatabaseInfo {
5256
*/
5357
async saveOnDisk(): Promise<void> {
5458
LOGGER.debug(`=>setDatabaseconfigYaml`, `file:${this.file.path}`);
55-
const configRegex = new RegExp(`<%%\\s+([\\w\\W]+?)\\s+%%>`, "g");
5659
const databaseFilePath = this.file.path;
5760
const databaseConfigUpdated = DatabaseYamlToStringParser(this.yaml).join("\n");
5861
const noteObject: NoteContentAction = {
5962
action: 'replace',
6063
file: this.file,
61-
regexp: configRegex,
62-
newValue: `<%%\n${databaseConfigUpdated}\n%%>`
64+
regexp: DATABASE_CONFIG.REPLACE_YAML_REGEX,
65+
newValue: `${DATABASE_CONFIG.START_CENTINEL}\n${databaseConfigUpdated}\n${DATABASE_CONFIG.END_CENTINEL}`
6366
};
6467
// Update configuration file
6568
await VaultManagerDB.editNoteContent(noteObject);

0 commit comments

Comments
 (0)