Complete the basic function of customisation

This commit is contained in:
Jiaxin Peng
2024-01-29 11:12:07 +00:00
parent a179d3da52
commit 8c6aea8250
6 changed files with 54 additions and 36 deletions

View File

@@ -13,19 +13,28 @@ Thanks to the [original author](https://github.com/EasyChris/obsidian-to-notion)
Thus, based on the [original author's work](https://github.com/EasyChris/obsidian-to-notion), I've added a feature to match the [NotionNext](https://github.com/tangly1024/NotionNext) template. This way, you can edit directly in Obsidian and publish with a single click after organizing.
**Now, support both NotionNext and General databases.**
**Now, support both NotionNext and General databases with customised properties.**
**现在支持NotionNext和普通Notion数据库。**
**现在支持NotionNext和普通Notion数据库,可自定义数据库列表。**
## TODO List
- [ ] Support custom properties for Notion General database. 支持自定义属性
- [x] Support custom properties for Notion General database. 支持自定义属性
- [ ] Support group upload with one click 支持一键多数据库上传
- [x] Support preview for database details in plugin settings. 支持预览数据库详情
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情
## Update
### 2.2.0
- add the support for custom properties in the Notion General database. 支持自定义属性
![](https://minioapi.pjx.ac.cn/img1/2024/01/039760ee966c6c1e04410d3f69787f85.png)
- Once you create the properties, you can preview the database details in the plugin settings.
Once you add the custom properties in the Notion General database, you can add the corresponding properties in the YAML frontmatter. **The name of the properties is case sensitive. You should use small letter.**
### 2.1.0
- add confirmation interface for deleting a database 增加删除数据库的确认界面

View File

@@ -1,6 +1,6 @@
import { App, Notice, TFile } from "obsidian";
import ObsidianSyncNotionPlugin from "../main";
import {DatabaseDetails, PluginSettings} from "../ui/settingTabs";
import {DatabaseDetails} from "../ui/settingTabs";
export async function updateYamlInfo(
yamlContent: string,

View File

@@ -139,7 +139,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
const frontmasster =
app.metadataCache.getFileCache(nowFile)?.frontmatter;
const {abName} = this.dbDetails
const notionIDKey = `${abName}-NotionID`;
const notionIDKey = `NotionID-${abName}`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null;

View File

@@ -228,7 +228,7 @@ export class Upload2NotionNext extends UploadBaseNext {
const file2Block = markdownToBlocks(__content, options);
const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter
const {abName} = this.dbDetails
const notionIDKey = `${abName}-NotionID`;
const notionIDKey = `NotionID-${abName}`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null;

View File

@@ -107,7 +107,9 @@ export class Upload2NotionCustom extends UploadBaseCustom {
const file2Block = markdownToBlocks(__content, options);
const frontmasster =
app.metadataCache.getFileCache(nowFile)?.frontmatter;
const notionID = frontmasster ? frontmasster.notionID : null;
const {abName} = this.dbDetails
const notionIDKey = `NotionID-${abName}`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
if (notionID) {
res = await this.updatePage(

View File

@@ -1,11 +1,10 @@
import {App, Notice, TAbstractFile, TFile} from "obsidian";
import {App, Notice} from "obsidian";
import {i18nConfig} from "../../lang/I18n";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
import {DatabaseDetails} from "../../ui/settingTabs";
export async function getNowFileMarkdownContentCustom(
app: App,
dbDetails: DatabaseDetails,
settings: PluginSettings,
) {
const nowFile = app.workspace.getActiveFile();
if (!nowFile) {
@@ -19,17 +18,25 @@ export async function getNowFileMarkdownContentCustom(
try {
cover = FileCache.frontmatter.coverurl;
// Get custom property names from dbDetails
const customPropertyValues = dbDetails.customProperties.map(property => property.customName);
// Get custom property names from dbDetails excluding the title type property
const customPropertyNames = dbDetails.customProperties
.filter(property => property.customType !== 'title') // Exclude 'title' type property
.map(property => property.customName);
// Extract custom values from the front matter based on the names
customPropertyValues.forEach( propertyName => {
if (FileCache.frontmatter[propertyName] !== undefined) {
customPropertyNames.forEach(propertyName => {
if (FileCache.frontmatter && FileCache.frontmatter[propertyName] !== undefined) {
customValues[propertyName] = FileCache.frontmatter[propertyName];
}
});
customValues['title'] = nowFile.basename; // Use 'basename' for the file name without extension
// Check if any of the customProperties has a customType of 'title'
const titleProperty = dbDetails.customProperties.find(property => property.customType === 'title');
// If a 'title' type property exists, use the file's basename as its value
if (titleProperty) {
customValues[titleProperty.customName] = nowFile.basename; // Use 'basename' for the file name without extension
}
} catch (error) {
new Notice(i18nConfig["set-tags-fail"]);