diff --git a/src/main/engine/WxrParser.ts b/src/main/engine/WxrParser.ts index a94b792..b885f2b 100644 --- a/src/main/engine/WxrParser.ts +++ b/src/main/engine/WxrParser.ts @@ -15,6 +15,8 @@ export interface WxrPost { content: string; excerpt: string; pubDate: Date | null; + postDate: Date | null; + postModified: Date | null; creator: string; status: string; postType: string; @@ -197,6 +199,26 @@ export class WxrParser { } } + // Parse WordPress local post date (wp:post_date) + const postDateStr = this.getElementText(item, 'post_date', NS.wp); + let postDate: Date | null = null; + if (postDateStr) { + const parsed = new Date(postDateStr.replace(' ', 'T') + 'Z'); + if (!isNaN(parsed.getTime())) { + postDate = parsed; + } + } + + // Parse WordPress local modification date (wp:post_modified) + const postModifiedStr = this.getElementText(item, 'post_modified', NS.wp); + let postModified: Date | null = null; + if (postModifiedStr) { + const parsed = new Date(postModifiedStr.replace(' ', 'T') + 'Z'); + if (!isNaN(parsed.getTime())) { + postModified = parsed; + } + } + return { wpId: parseInt(this.getElementText(item, 'post_id', NS.wp) || '0', 10), title: this.getDirectChildText(item, 'title'), @@ -204,6 +226,8 @@ export class WxrParser { content: this.getElementText(item, 'encoded', NS.content), excerpt: this.getElementText(item, 'encoded', NS.excerpt), pubDate, + postDate, + postModified, creator: this.getElementText(item, 'creator', NS.dc), status: this.getElementText(item, 'status', NS.wp), postType: this.getElementText(item, 'post_type', NS.wp), diff --git a/src/renderer/components/ImportAnalysisView/ImportAnalysisView.tsx b/src/renderer/components/ImportAnalysisView/ImportAnalysisView.tsx index 4d9afdb..aea8d5a 100644 --- a/src/renderer/components/ImportAnalysisView/ImportAnalysisView.tsx +++ b/src/renderer/components/ImportAnalysisView/ImportAnalysisView.tsx @@ -44,6 +44,8 @@ interface AnalyzedPostItem { status: string; excerpt: string; pubDate: string | null; + postDate: string | null; + postModified: string | null; creator: string; postType: string; categories: string[]; diff --git a/tests/engine/WxrParser.test.ts b/tests/engine/WxrParser.test.ts index 005b656..087ceb5 100644 --- a/tests/engine/WxrParser.test.ts +++ b/tests/engine/WxrParser.test.ts @@ -90,6 +90,9 @@ const WXR_WITH_POST = ` 42 2024-01-15 10:30:00 + 2024-01-15 10:30:00 + 2024-01-20 15:45:30 + 2024-01-20 15:45:30 hello-world publish post @@ -351,6 +354,28 @@ describe('WxrParser', () => { expect(post.pubDate).toBeInstanceOf(Date); }); + it('should extract postDate and postModified from WXR', () => { + const result = parser.parseXml(WXR_WITH_POST); + const post = result.posts[0]; + + // postDate is the WordPress local creation date + expect(post.postDate).toBeInstanceOf(Date); + expect(post.postDate?.toISOString()).toBe('2024-01-15T10:30:00.000Z'); + + // postModified is the WordPress local modification date + expect(post.postModified).toBeInstanceOf(Date); + expect(post.postModified?.toISOString()).toBe('2024-01-20T15:45:30.000Z'); + }); + + it('should handle missing postDate and postModified gracefully', () => { + const result = parser.parseXml(WXR_WITH_PAGE); + const page = result.pages[0]; + + // Page test data doesn't have post_date/post_modified + expect(page.postDate).toBeNull(); + expect(page.postModified).toBeNull(); + }); + it('should parse a page and put it in pages array', () => { const result = parser.parseXml(WXR_WITH_PAGE);