Skip to content

Commit 012f962

Browse files
committed
Merge branch 'mobile_support'
2 parents f771758 + 86ca437 commit 012f962

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

manifest-beta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "3.0.1",
4+
"version": "3.2.3",
55
"minAppVersion": "1.0.3",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "3.2.2",
5-
"minAppVersion": "1.1.1",
4+
"version": "3.2.3",
5+
"minAppVersion": "1.0.3",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",
88
"authorUrl": "https://github.com/RafaelGB/obsidian-bd-folder",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-dbfolder",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {

src/services/EditEngineService.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RowDataType, TableColumn } from "cdm/FolderModel";
22
import { LocalSettings } from "cdm/SettingsModel";
3-
import { TFile } from "obsidian";
3+
import { requireApiVersion, TFile } from "obsidian";
44
import { LOGGER } from "services/Logger";
55
import { ParseService } from "services/ParseService";
66
import { InputType, UpdateRowOptions } from "helpers/Constants";
@@ -10,6 +10,8 @@ import { EditionError, showDBError } from "errors/ErrorTypes";
1010
import obtainRowDatabaseFields from "parsers/FileToRowDatabaseFields";
1111
import { EditArguments } from "cdm/ServicesModel";
1212
import NoteContentActionBuilder from "patterns/builders/NoteContentActionBuilder";
13+
import { parseFrontmatterFieldsToString } from "parsers/RowDatabaseFieldsToFile";
14+
import { hasFrontmatter } from "helpers/VaultManagement";
1315

1416
class EditEngine {
1517
private static instance: EditEngine;
@@ -109,6 +111,7 @@ class EditEngine {
109111
const content = await VaultManagerDB.obtainContentFromTfile(file);
110112
const frontmatterKeys = VaultManagerDB.obtainFrontmatterKeys(content);
111113
const rowFields = obtainRowDatabaseFields(file, columns, frontmatterKeys);
114+
const contentHasFrontmatter = hasFrontmatter(content);
112115
const column = columns.find(
113116
c => c.key === (UpdateRowOptions.COLUMN_KEY === option ? newValue : columnId)
114117
);
@@ -157,18 +160,30 @@ class EditEngine {
157160
}
158161

159162
async function persistFrontmatter(deletedColumn?: string): Promise<void> {
160-
await app.fileManager.processFrontMatter(file, (frontmatter) => {
161-
frontmatter[columnId] = ParseService.parseLiteral(
162-
rowFields.frontmatter[columnId],
163-
InputType.MARKDOWN,
164-
ddbbConfig
165-
);
166-
167-
if (deletedColumn) {
168-
delete frontmatter[deletedColumn];
169-
}
170-
});
163+
if (requireApiVersion("1.1.1")) {
164+
await app.fileManager.processFrontMatter(file, (frontmatter) => {
165+
frontmatter[columnId] = ParseService.parseLiteral(
166+
rowFields.frontmatter[columnId],
167+
InputType.MARKDOWN,
168+
ddbbConfig
169+
);
171170

171+
if (deletedColumn) {
172+
delete frontmatter[deletedColumn];
173+
}
174+
});
175+
} else {
176+
const frontmatterGroupRegex = contentHasFrontmatter ? /^---[\s\S]+?---\n*/g : /(^[\s\S]*$)/g;
177+
const frontmatterFieldsText = parseFrontmatterFieldsToString(rowFields, ddbbConfig, deletedColumn);
178+
const newContent = contentHasFrontmatter ? `${frontmatterFieldsText}\n` : `${frontmatterFieldsText ? frontmatterFieldsText.concat('\n') : frontmatterFieldsText}$1`;
179+
const builder = new NoteContentActionBuilder()
180+
.setContent(content)
181+
.setFile(file)
182+
.addRegExp(frontmatterGroupRegex)
183+
.addRegExpNewValue(newContent)
184+
.build();
185+
await VaultManagerDB.editNoteContent(builder);
186+
}
172187
}
173188

174189
/*******************************************************************************************

0 commit comments

Comments
 (0)