mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
fix: clean up formatting in auto sync logic for better readability
This commit is contained in:
16
src/main.ts
16
src/main.ts
@@ -220,9 +220,9 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
|
|
||||||
// Filter out NotionID-related keys and Obsidian internal keys
|
// Filter out NotionID-related keys and Obsidian internal keys
|
||||||
const isIgnoredKey = (key: string) => {
|
const isIgnoredKey = (key: string) => {
|
||||||
return key.startsWith('NotionID-') ||
|
return key.startsWith('NotionID-') ||
|
||||||
key === 'NotionID' ||
|
key === 'NotionID' ||
|
||||||
key === 'position'; // Obsidian's internal metadata
|
key === 'position'; // Obsidian's internal metadata
|
||||||
};
|
};
|
||||||
const oldNonNotionKeys = oldKeys.filter(k => !isIgnoredKey(k)).sort();
|
const oldNonNotionKeys = oldKeys.filter(k => !isIgnoredKey(k)).sort();
|
||||||
const newNonNotionKeys = newKeys.filter(k => !isIgnoredKey(k)).sort();
|
const newNonNotionKeys = newKeys.filter(k => !isIgnoredKey(k)).sort();
|
||||||
@@ -296,11 +296,11 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
|
|
||||||
// Check if only NotionID fields changed (to avoid sync loops)
|
// Check if only NotionID fields changed (to avoid sync loops)
|
||||||
const lastFrontmatter = this.lastFrontmatterCache.get(file.path);
|
const lastFrontmatter = this.lastFrontmatterCache.get(file.path);
|
||||||
|
|
||||||
if (lastFrontmatter && lastContentHash) {
|
if (lastFrontmatter && lastContentHash) {
|
||||||
const frontmatterOnlyNotionIDChanged = this.onlyNotionIDChanged(lastFrontmatter, frontMatter);
|
const frontmatterOnlyNotionIDChanged = this.onlyNotionIDChanged(lastFrontmatter, frontMatter);
|
||||||
const contentUnchanged = contentHash === lastContentHash;
|
const contentUnchanged = contentHash === lastContentHash;
|
||||||
|
|
||||||
console.log(`[AutoSync] Change analysis for ${file.basename}:`, {
|
console.log(`[AutoSync] Change analysis for ${file.basename}:`, {
|
||||||
frontmatterOnlyNotionIDChanged,
|
frontmatterOnlyNotionIDChanged,
|
||||||
contentUnchanged,
|
contentUnchanged,
|
||||||
@@ -308,7 +308,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
contentChanged: !contentUnchanged,
|
contentChanged: !contentUnchanged,
|
||||||
willSync: !(frontmatterOnlyNotionIDChanged && contentUnchanged)
|
willSync: !(frontmatterOnlyNotionIDChanged && contentUnchanged)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Only skip sync if BOTH conditions are true:
|
// Only skip sync if BOTH conditions are true:
|
||||||
// 1. Frontmatter only has NotionID changes (no real user changes)
|
// 1. Frontmatter only has NotionID changes (no real user changes)
|
||||||
// 2. Content is completely unchanged
|
// 2. Content is completely unchanged
|
||||||
@@ -319,7 +319,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
this.lastContentHashCache.set(file.path, contentHash);
|
this.lastContentHashCache.set(file.path, contentHash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contentUnchanged) {
|
if (!contentUnchanged) {
|
||||||
console.log(`[AutoSync] Content changed - will sync`);
|
console.log(`[AutoSync] Content changed - will sync`);
|
||||||
} else if (!frontmatterOnlyNotionIDChanged) {
|
} else if (!frontmatterOnlyNotionIDChanged) {
|
||||||
@@ -384,7 +384,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
const updatedFrontmatter = this.app.metadataCache.getFileCache(file)?.frontmatter;
|
const updatedFrontmatter = this.app.metadataCache.getFileCache(file)?.frontmatter;
|
||||||
const updatedContent = await this.app.vault.read(file);
|
const updatedContent = await this.app.vault.read(file);
|
||||||
const updatedHash = this.simpleHash(updatedContent);
|
const updatedHash = this.simpleHash(updatedContent);
|
||||||
|
|
||||||
if (updatedFrontmatter) {
|
if (updatedFrontmatter) {
|
||||||
this.lastFrontmatterCache.set(file.path, { ...updatedFrontmatter });
|
this.lastFrontmatterCache.set(file.path, { ...updatedFrontmatter });
|
||||||
this.lastContentHashCache.set(file.path, updatedHash);
|
this.lastContentHashCache.set(file.path, updatedHash);
|
||||||
|
|||||||
Reference in New Issue
Block a user