mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
feat: Enable first-time auto-upload for new documents and update documentation.
This commit is contained in:
23
src/main.ts
23
src/main.ts
@@ -371,7 +371,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
dbByShortName.set(dbDetails.abName.toLowerCase(), dbDetails);
|
dbByShortName.set(dbDetails.abName.toLowerCase(), dbDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundDatabases: Array<{ dbDetails: DatabaseDetails, notionId: string }> = [];
|
const foundDatabases: Array<{ dbDetails: DatabaseDetails, notionId: string | undefined }> = [];
|
||||||
const unresolvedTargets: string[] = [];
|
const unresolvedTargets: string[] = [];
|
||||||
|
|
||||||
for (const target of autoSyncTargets) {
|
for (const target of autoSyncTargets) {
|
||||||
@@ -384,22 +384,20 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const notionIDKey = `NotionID-${dbDetails.abName}`;
|
const notionIDKey = `NotionID-${dbDetails.abName}`;
|
||||||
if (frontMatter[notionIDKey]) {
|
// Include database even if no NotionID exists (for first-time upload)
|
||||||
foundDatabases.push({
|
foundDatabases.push({
|
||||||
dbDetails,
|
dbDetails,
|
||||||
notionId: String(frontMatter[notionIDKey])
|
notionId: frontMatter[notionIDKey] ? String(frontMatter[notionIDKey]) : undefined
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unresolvedTargets.length > 0) {
|
if (unresolvedTargets.length > 0) {
|
||||||
console.log(`[AutoSync] Frontmatter auto sync targets not found in settings: ${unresolvedTargets.join(", ")}`);
|
console.log(`[AutoSync] Frontmatter auto sync targets not found in settings: ${unresolvedTargets.join(", ")}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no NotionID found, notify user to upload manually first
|
// If no valid databases found in settings, skip
|
||||||
if (foundDatabases.length === 0) {
|
if (foundDatabases.length === 0) {
|
||||||
console.log(`[AutoSync] No NotionID found in ${file.path}, skipping auto sync`);
|
console.log(`[AutoSync] No matching databases found in settings for ${file.path}, skipping auto sync`);
|
||||||
new Notice(i18nConfig.AutoSyncNoNotionID, 4000);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,12 +405,13 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
if (foundDatabases.length > 1) {
|
if (foundDatabases.length > 1) {
|
||||||
const message = i18nConfig.AutoSyncMultipleSync.replace('{count}', String(foundDatabases.length));
|
const message = i18nConfig.AutoSyncMultipleSync.replace('{count}', String(foundDatabases.length));
|
||||||
new Notice(message, 3000);
|
new Notice(message, 3000);
|
||||||
console.log(`[AutoSync] Found ${foundDatabases.length} NotionIDs in ${file.path}`);
|
console.log(`[AutoSync] Found ${foundDatabases.length} database targets in ${file.path}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync to all found databases
|
// Sync to all found databases
|
||||||
for (const { dbDetails, notionId } of foundDatabases) {
|
for (const { dbDetails, notionId } of foundDatabases) {
|
||||||
console.log(`[AutoSync] ${new Date().toISOString()} Auto syncing ${file.basename} to ${dbDetails.fullName} (${dbDetails.abName})`);
|
const isFirstSync = !notionId;
|
||||||
|
console.log(`[AutoSync] ${new Date().toISOString()} Auto syncing ${file.basename} to ${dbDetails.fullName} (${dbDetails.abName})${isFirstSync ? ' [First Upload]' : ''}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Trigger appropriate upload command based on database format
|
// Trigger appropriate upload command based on database format
|
||||||
|
|||||||
Reference in New Issue
Block a user