From 8041c02878b0b51c9b03f3a0c776f7a4d2d919ed Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sat, 25 Jun 2022 09:31:44 +0300 Subject: [PATCH 1/3] migration-fixes --- migrate.py | 1 + migration/content/.gitkeep | 0 migration/content/article/.gitkeep | 0 migration/content/image/.gitkeep | 0 migration/content/music/.gitkeep | 0 migration/content/prose/.gitkeep | 0 migration/content/video/.gitkeep | 0 migration/tables/users.py | 2 +- 8 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 migration/content/.gitkeep create mode 100644 migration/content/article/.gitkeep create mode 100644 migration/content/image/.gitkeep create mode 100644 migration/content/music/.gitkeep create mode 100644 migration/content/prose/.gitkeep create mode 100644 migration/content/video/.gitkeep diff --git a/migrate.py b/migrate.py index 5f381715..92e3f21e 100644 --- a/migrate.py +++ b/migrate.py @@ -83,6 +83,7 @@ def topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data): if len(sys.argv) > 2: limit = int(sys.argv[2]) print('migrating %d topics...' % limit) counter = 0 + topics_by_title = {} for tag in tags_data: old_id = tag["createdBy"] tag["createdBy"] = user_id_map.get(old_id, 0) diff --git a/migration/content/.gitkeep b/migration/content/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/migration/content/article/.gitkeep b/migration/content/article/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/migration/content/image/.gitkeep b/migration/content/image/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/migration/content/music/.gitkeep b/migration/content/music/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/migration/content/prose/.gitkeep b/migration/content/prose/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/migration/content/video/.gitkeep b/migration/content/video/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/migration/tables/users.py b/migration/tables/users.py index 69ee89d1..287d7814 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -34,7 +34,7 @@ def migrate(entry): res['old_id'] = entry['_id'] res['password'] = entry['services']['password'].get('bcrypt', '') del entry['services'] - del entry['subscribedTo'] + if entry.get('subscribedTo', '') != '': del entry['subscribedTo'] res['username'] = entry['emails'][0]['address'] res['email'] = res['username'] res['wasOnlineAt'] = parse(entry.get('loggedInAt', entry['createdAt'])) From 8990cc2aecf0d80c36d26bfd7e22f66fba14bf38 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sat, 25 Jun 2022 09:38:50 +0300 Subject: [PATCH 2/3] fix md metadata --- migration/tables/content_items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index f024fe2b..42d4ef9e 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -174,7 +174,7 @@ def migrate(entry, users_by_oid, topics_by_oid): shout_dict['authors'] = [ author, ] if entry['published']: - metadata = get_metadata(r) + metadata = get_metadata(shout_dict) content = frontmatter.dumps(frontmatter.Post(body, **metadata)) ext = 'md' open('migration/content/' + r['layout'] + '/' + r['slug'] + '.' + ext, 'w').write(content) From fddabada617eefb6bb09c89df22f617891860772 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sat, 25 Jun 2022 10:02:11 +0300 Subject: [PATCH 3/3] html2md fix --- migration/aaronsw-html2text.py | 10 ++++++---- migration/html2text/__init__.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/migration/aaronsw-html2text.py b/migration/aaronsw-html2text.py index 6766cf89..12f994da 100644 --- a/migration/aaronsw-html2text.py +++ b/migration/aaronsw-html2text.py @@ -417,15 +417,17 @@ class HTML2Text(HTMLParser.HTMLParser): self.o('`') # NOTE: same as self.span_hightlight = True elif attrs['class'] == 'lead': - self.o('==') # NOTE: but CriticMarkup uses {== ==} - self.span_lead = True + if self.span_lead == False: + self.o('==\n') # NOTE: but CriticMarkup uses {== ==} + self.span_lead = True else: if self.span_hightlight: self.o('`') self.span_hightlight = False elif self.span_lead: - self.o('==') - self.span_lead = False + if self.span_lead == True: + self.o('\n==') + self.span_lead = False if tag in ['p', 'div']: if self.google_doc: diff --git a/migration/html2text/__init__.py b/migration/html2text/__init__.py index 85c664c8..4643a4e2 100644 --- a/migration/html2text/__init__.py +++ b/migration/html2text/__init__.py @@ -369,15 +369,17 @@ class HTML2Text(html.parser.HTMLParser): self.o('`') # NOTE: same as self.span_hightlight = True elif attrs['class'] == 'lead': - self.o('==') # NOTE: but CriticMarkup uses {== ==} - self.span_lead = True + if self.span_lead == False: + self.o('==\n') # NOTE: but CriticMarkup uses {== ==} + self.span_lead = True else: if self.span_hightlight: self.o('`') self.span_hightlight = False elif self.span_lead: - self.o('==') - self.span_lead = False + if self.span_lead == True: + self.o('\n==') + self.span_lead = False if tag in ["p", "div"]: if self.google_doc: