migration-fixes-2

This commit is contained in:
tonyrewin 2022-06-25 22:14:16 +03:00
parent e14a2c4d03
commit 04912c6c1e
4 changed files with 32 additions and 20 deletions

View File

@ -166,8 +166,8 @@ def export_body(article, content_dict):
article = extract_images(article)
metadata = get_metadata(article)
content = frontmatter.dumps(frontmatter.Post(article['body'], **metadata))
open('../content/discours.io/'+slug+'.md', 'w').write(content)
open('../content/discours.io/'+slug+'.html', 'w').write(content_dict[article['old_id']]['body'])
open('../discoursio-web/content/' + article['layout'].lower() + '/' + slug + '.mdx', 'w').write(content)
# open('../content/discours.io/'+slug+'.html', 'w').write(content_dict[article['old_id']]['body'])
def export_slug(slug, export_articles, export_authors, content_dict):
print('exporting %s ' % slug)

View File

@ -385,7 +385,7 @@ class HTML2Text(html.parser.HTMLParser):
elif self.current_class == 'lead' and \
self.inheader == False and \
self.span_highlight == False:
self.o('==') # NOTE: but CriticMarkup uses {== ==}
self.o("==") # NOTE: but CriticMarkup uses {== ==}
self.span_lead = True
else:
if self.span_highlight:
@ -478,6 +478,7 @@ class HTML2Text(html.parser.HTMLParser):
else:
strong = self.strong_mark
if not self.span_lead and not self.span_highlight:
self.o(strong)
if start:
self.stressed = True

View File

@ -12,6 +12,7 @@ from datetime import datetime
from sqlalchemy.exc import IntegrityError
from orm.base import local_session
from orm.community import Community
import os
DISCOURS_USER = {
'id': 9999999,
@ -124,30 +125,37 @@ def migrate(entry, users_by_oid, topics_by_oid):
yt = m.get('youtubeId', '')
vm = m.get('vimeoId', '')
video_url = 'https://www.youtube.com/watch?v=' + yt if yt else '#'
therestof = html2text(m.get('body', entry.get('body', '')))
r['body'] = 'import { YouTube } from \"solid-social\"\n' + \
'<YouTube youtubeId=\"''' + yt + '\" />\n\n' + therestof
if video_url == '#':
video_url = 'https://vimeo.com/' + vm if vm else '#'
r['body'] = 'import { Vimeo } from \"solid-social\"\n' + \
'<Vimeo vimeoId=\"''' + vm + '\" />\n\n' + therestof
if video_url == '#':
print(entry.get('media', 'UNKNOWN MEDIA PROVIDER!'))
# raise Exception
therestof = html2text(m.get('body', ''))
r['body'] = 'import VideoPlayer from \"src/components/Article/VideoPlayer\"\n' + \
'<VideoPlayer src=\"''' + video_url + '\" />\n\n' + therestof
elif entry.get('type') == 'Music':
r['body'] = 'import MusicPlayer from \"src/components/MusicPlayer\"\n'
r['body'] = ''
for m in entry['media']:
if m == { 'main': 'true' } or m == { 'main': True } or m == {}:
continue
else:
# TODO: mark highlighted track isMain == True
try: r['body'] += '<MusicPlayer src=\"' + m['fileUrl'] + '\"'
except: print(m)
try: r['body'] += ' title=\"' + m['title'] + '\"'
except: print(m)
r['body'] += ' />\n\n'
r['body'] += html2text(m.get('body', ''))
fileUrl = m.get('fileUrl', '')
if not fileUrl:
print(m)
continue
else:
r['body'] = 'import MusicPlayer from \"src/components/MusicPlayer\"\n\n'
r['body'] += '<MusicPlayer src=\"' + fileUrl + '\" title=\"' + m.get('title','') + '\" />\n'
r['body'] += html2text(entry.get('body', ''))
elif entry.get('type') == 'Image':
m = r.get('media')
try: r['body'] = '<img src=\"' + r['cover'] + '\" />'
except: print(entry)
r['body'] = ''
if 'cover' in r: r['body'] = '<img src=\"' + r.get('cover', '') + '\" />'
r['body'] += entry.get('body', '')
if r['body'] == '': print(entry)
if r.get('body') is None:
body_orig = entry.get('body', '')
body_html = str(BeautifulSoup(body_orig, features="html.parser"))
@ -191,7 +199,10 @@ def migrate(entry, users_by_oid, topics_by_oid):
metadata = get_metadata(shout_dict)
content = frontmatter.dumps(frontmatter.Post(body, **metadata))
ext = 'mdx'
open('../discoursio-web/content/' + r['layout'] + '/' + r['slug'] + '.' + ext, 'w').write(content)
parentDir = '/'.join(os.getcwd().split('/')[:-1])
filepath = parentDir + '/discoursio-web/content/' + r['layout'] + '/' + r['slug'] + '.' + ext
# print(filepath)
open(filepath, 'w').write(content)
try:
shout_dict['createdAt'] = date_parse(r.get('createdAt')) if entry.get('createdAt') else ts
shout_dict['publishedAt'] = date_parse(entry.get('publishedAt')) if entry.get('published') else None

View File

@ -57,7 +57,7 @@ class GitTask:
#output = subprocess.check_output(cmd, shell=True)
#print(output)
shout_filename = "%s.md" % (self.slug)
shout_filename = "%s.mdx" % (self.slug)
shout_full_filename = "%s/%s" % (repo_path, shout_filename)
with open(shout_full_filename, mode='w', encoding='utf-8') as shout_file:
shout_file.write(self.shout_body)