mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
Complete the basic function of customisation
This commit is contained in:
15
README.md
15
README.md
@@ -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.
|
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
|
## TODO List
|
||||||
|
|
||||||
- [ ] Support custom properties for Notion General database. 支持自定义属性
|
- [x] Support custom properties for Notion General database. 支持自定义属性
|
||||||
- [ ] Support group upload with one click 支持一键多数据库上传
|
- [ ] Support group upload with one click 支持一键多数据库上传
|
||||||
- [x] Support preview for database details in plugin settings. 支持预览数据库详情
|
- [x] Support preview for database details in plugin settings. 支持预览数据库详情
|
||||||
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情
|
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情
|
||||||
|
|
||||||
## Update
|
## Update
|
||||||
|
|
||||||
|
### 2.2.0
|
||||||
|
|
||||||
|
- add the support for custom properties in the Notion General database. 支持自定义属性
|
||||||
|
|
||||||
|

|
||||||
|
- 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
|
### 2.1.0
|
||||||
|
|
||||||
- add confirmation interface for deleting a database 增加删除数据库的确认界面
|
- add confirmation interface for deleting a database 增加删除数据库的确认界面
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { App, Notice, TFile } from "obsidian";
|
import { App, Notice, TFile } from "obsidian";
|
||||||
import ObsidianSyncNotionPlugin from "../main";
|
import ObsidianSyncNotionPlugin from "../main";
|
||||||
import {DatabaseDetails, PluginSettings} from "../ui/settingTabs";
|
import {DatabaseDetails} from "../ui/settingTabs";
|
||||||
|
|
||||||
export async function updateYamlInfo(
|
export async function updateYamlInfo(
|
||||||
yamlContent: string,
|
yamlContent: string,
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
const frontmasster =
|
const frontmasster =
|
||||||
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
||||||
const {abName} = this.dbDetails
|
const {abName} = this.dbDetails
|
||||||
const notionIDKey = `${abName}-NotionID`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
const file2Block = markdownToBlocks(__content, options);
|
const file2Block = markdownToBlocks(__content, options);
|
||||||
const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter
|
const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter
|
||||||
const {abName} = this.dbDetails
|
const {abName} = this.dbDetails
|
||||||
const notionIDKey = `${abName}-NotionID`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,9 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
const file2Block = markdownToBlocks(__content, options);
|
const file2Block = markdownToBlocks(__content, options);
|
||||||
const frontmasster =
|
const frontmasster =
|
||||||
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
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) {
|
if (notionID) {
|
||||||
res = await this.updatePage(
|
res = await this.updatePage(
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import {App, Notice, TAbstractFile, TFile} from "obsidian";
|
import {App, Notice} from "obsidian";
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
import {DatabaseDetails} from "../../ui/settingTabs";
|
||||||
|
|
||||||
export async function getNowFileMarkdownContentCustom(
|
export async function getNowFileMarkdownContentCustom(
|
||||||
app: App,
|
app: App,
|
||||||
dbDetails: DatabaseDetails,
|
dbDetails: DatabaseDetails,
|
||||||
settings: PluginSettings,
|
|
||||||
) {
|
) {
|
||||||
const nowFile = app.workspace.getActiveFile();
|
const nowFile = app.workspace.getActiveFile();
|
||||||
if (!nowFile) {
|
if (!nowFile) {
|
||||||
@@ -19,17 +18,25 @@ export async function getNowFileMarkdownContentCustom(
|
|||||||
try {
|
try {
|
||||||
cover = FileCache.frontmatter.coverurl;
|
cover = FileCache.frontmatter.coverurl;
|
||||||
|
|
||||||
// Get custom property names from dbDetails
|
// Get custom property names from dbDetails excluding the title type property
|
||||||
const customPropertyValues = dbDetails.customProperties.map(property => property.customName);
|
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
|
// Extract custom values from the front matter based on the names
|
||||||
customPropertyValues.forEach( propertyName => {
|
customPropertyNames.forEach(propertyName => {
|
||||||
if (FileCache.frontmatter[propertyName] !== undefined) {
|
if (FileCache.frontmatter && FileCache.frontmatter[propertyName] !== undefined) {
|
||||||
customValues[propertyName] = FileCache.frontmatter[propertyName];
|
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) {
|
} catch (error) {
|
||||||
new Notice(i18nConfig["set-tags-fail"]);
|
new Notice(i18nConfig["set-tags-fail"]);
|
||||||
|
|||||||
Reference in New Issue
Block a user