complete the custom ui design

This commit is contained in:
Jiaxin Peng
2024-01-28 00:11:11 +00:00
parent 8c65e471eb
commit 2a58dd3258
10 changed files with 289 additions and 167 deletions

View File

@@ -100,13 +100,13 @@ export async function uploadCommandCustom(
return;
}
const { markDownData, nowFile, cover, tags ,customValues} = await getNowFileMarkdownContentCustom(app, settings)
const { markDownData, nowFile, cover, customValues} = await getNowFileMarkdownContentCustom(app, dbDetails, settings)
if (markDownData) {
const { basename } = nowFile;
const upload = new Upload2NotionCustom(plugin,dbDetails);
const res = await upload.syncMarkdownToNotionCustom(basename, cover, tags, customValues, markDownData, nowFile, this.app);
const res = await upload.syncMarkdownToNotionCustom(basename, cover, customValues, markDownData, nowFile, this.app);
if (res.status === 200) {
new Notice(`${i18nConfig["sync-success"]}${basename}`);

View File

@@ -23,7 +23,6 @@ export class Upload2NotionCustom extends UploadBaseCustom {
notionID: string,
title: string,
cover: string,
tags: string[],
customValues: Record<string, string>,
childArr: any,
) {
@@ -39,13 +38,12 @@ export class Upload2NotionCustom extends UploadBaseCustom {
cover = databaseCover;
}
return await this.createPage(title, cover, tags, customValues, childArr);
return await this.createPage(title, cover, customValues, childArr);
}
async createPage(
title: string,
cover: string,
tags: string[],
customValues: Record<string, string>,
childArr: any,
) {
@@ -54,7 +52,6 @@ export class Upload2NotionCustom extends UploadBaseCustom {
databaseID,
customTitleButton,
customTitleName,
tagButton,
notionAPI
} = this.dbDetails;
@@ -129,7 +126,6 @@ export class Upload2NotionCustom extends UploadBaseCustom {
async syncMarkdownToNotionCustom(
title: string,
cover: string,
tags: string[],
customValues: Record<string, string>,
markdown: string,
nowFile: TFile,
@@ -153,12 +149,11 @@ export class Upload2NotionCustom extends UploadBaseCustom {
notionID,
title,
cover,
tags,
customValues,
file2Block,
);
} else {
res = await this.createPage(title, cover, tags, customValues, file2Block);
res = await this.createPage(title, cover, customValues, file2Block);
}
if (res.status === 200) {
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);

View File

@@ -1,28 +1,29 @@
import {App, Notice} from "obsidian";
import {i18nConfig} from "../../lang/I18n";
import {PluginSettings} from "../../ui/settingTabs";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
export async function getNowFileMarkdownContentCustom(
app: App,
dbDetails: DatabaseDetails,
settings: PluginSettings,
) {
const nowFile = app.workspace.getActiveFile();
let cover = '';
let tags = [];
let customValues: Record<string, string> = {};
let customValues: Record<string, any> = {}; // Change 'any' to a more specific type if possible
const FileCache = app.metadataCache.getFileCache(nowFile);
try {
cover = FileCache.frontmatter.coverurl;
tags = FileCache.frontmatter.tags;
// split the CustomValues into an array
const customValuesNames = settings.CustomValues.split('\n').map(value => value.trim());
// Get custom property names from dbDetails
const customPropertyNames = dbDetails.customProperties.map(property => property.customValue);
// get the custom values from the frontmatter
customValuesNames.forEach(valueName => {
customValues[valueName] = FileCache.frontmatter[valueName];
});
// Extract custom values from the frontmatter based on the names
customPropertyNames.forEach(propertyName => {
if (FileCache.frontmatter[propertyName] !== undefined) {
customValues[propertyName] = FileCache.frontmatter[propertyName];
}
});
} catch (error) {
new Notice(i18nConfig["set-tags-fail"]);
}
@@ -33,7 +34,6 @@ export async function getNowFileMarkdownContentCustom(
markDownData,
nowFile,
cover,
tags,
customValues,
};
} else {