Skip to content

Commit

Permalink
Merge branch 'mobile_support'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed Jan 8, 2023
2 parents f771758 + 86ca437 commit 012f962
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "dbfolder",
"name": "DB Folder",
"version": "3.0.1",
"version": "3.2.3",
"minAppVersion": "1.0.3",
"description": "Folder with the capability to store and retrieve data from a folder like database",
"author": "RafaelGB",
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "dbfolder",
"name": "DB Folder",
"version": "3.2.2",
"minAppVersion": "1.1.1",
"version": "3.2.3",
"minAppVersion": "1.0.3",
"description": "Folder with the capability to store and retrieve data from a folder like database",
"author": "RafaelGB",
"authorUrl": "https://github.com/RafaelGB/obsidian-bd-folder",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dbfolder",
"version": "3.2.2",
"version": "3.2.3",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
39 changes: 27 additions & 12 deletions src/services/EditEngineService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RowDataType, TableColumn } from "cdm/FolderModel";
import { LocalSettings } from "cdm/SettingsModel";
import { TFile } from "obsidian";
import { requireApiVersion, TFile } from "obsidian";
import { LOGGER } from "services/Logger";
import { ParseService } from "services/ParseService";
import { InputType, UpdateRowOptions } from "helpers/Constants";
Expand All @@ -10,6 +10,8 @@ import { EditionError, showDBError } from "errors/ErrorTypes";
import obtainRowDatabaseFields from "parsers/FileToRowDatabaseFields";
import { EditArguments } from "cdm/ServicesModel";
import NoteContentActionBuilder from "patterns/builders/NoteContentActionBuilder";
import { parseFrontmatterFieldsToString } from "parsers/RowDatabaseFieldsToFile";
import { hasFrontmatter } from "helpers/VaultManagement";

class EditEngine {
private static instance: EditEngine;
Expand Down Expand Up @@ -109,6 +111,7 @@ class EditEngine {
const content = await VaultManagerDB.obtainContentFromTfile(file);
const frontmatterKeys = VaultManagerDB.obtainFrontmatterKeys(content);
const rowFields = obtainRowDatabaseFields(file, columns, frontmatterKeys);
const contentHasFrontmatter = hasFrontmatter(content);
const column = columns.find(
c => c.key === (UpdateRowOptions.COLUMN_KEY === option ? newValue : columnId)
);
Expand Down Expand Up @@ -157,18 +160,30 @@ class EditEngine {
}

async function persistFrontmatter(deletedColumn?: string): Promise<void> {
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter[columnId] = ParseService.parseLiteral(
rowFields.frontmatter[columnId],
InputType.MARKDOWN,
ddbbConfig
);

if (deletedColumn) {
delete frontmatter[deletedColumn];
}
});
if (requireApiVersion("1.1.1")) {
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter[columnId] = ParseService.parseLiteral(
rowFields.frontmatter[columnId],
InputType.MARKDOWN,
ddbbConfig
);

if (deletedColumn) {
delete frontmatter[deletedColumn];
}
});
} else {
const frontmatterGroupRegex = contentHasFrontmatter ? /^---[\s\S]+?---\n*/g : /(^[\s\S]*$)/g;
const frontmatterFieldsText = parseFrontmatterFieldsToString(rowFields, ddbbConfig, deletedColumn);
const newContent = contentHasFrontmatter ? `${frontmatterFieldsText}\n` : `${frontmatterFieldsText ? frontmatterFieldsText.concat('\n') : frontmatterFieldsText}$1`;
const builder = new NoteContentActionBuilder()
.setContent(content)
.setFile(file)
.addRegExp(frontmatterGroupRegex)
.addRegExpNewValue(newContent)
.build();
await VaultManagerDB.editNoteContent(builder);
}
}

/*******************************************************************************************
Expand Down

0 comments on commit 012f962

Please sign in to comment.