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) article = extract_images(article)
metadata = get_metadata(article) metadata = get_metadata(article)
content = frontmatter.dumps(frontmatter.Post(article['body'], **metadata)) content = frontmatter.dumps(frontmatter.Post(article['body'], **metadata))
open('../content/discours.io/'+slug+'.md', 'w').write(content) 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']) # open('../content/discours.io/'+slug+'.html', 'w').write(content_dict[article['old_id']]['body'])
def export_slug(slug, export_articles, export_authors, content_dict): def export_slug(slug, export_articles, export_authors, content_dict):
print('exporting %s ' % slug) print('exporting %s ' % slug)

View File

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

View File

@ -12,7 +12,8 @@ from datetime import datetime
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
from orm.base import local_session from orm.base import local_session
from orm.community import Community from orm.community import Community
import os
DISCOURS_USER = { DISCOURS_USER = {
'id': 9999999, 'id': 9999999,
'slug': 'discours', 'slug': 'discours',
@ -124,30 +125,37 @@ def migrate(entry, users_by_oid, topics_by_oid):
yt = m.get('youtubeId', '') yt = m.get('youtubeId', '')
vm = m.get('vimeoId', '') vm = m.get('vimeoId', '')
video_url = 'https://www.youtube.com/watch?v=' + yt if yt else '#' 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 == '#': if video_url == '#':
video_url = 'https://vimeo.com/' + vm if vm else '#' 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 == '#': if video_url == '#':
print(entry.get('media', 'UNKNOWN MEDIA PROVIDER!')) print(entry.get('media', 'UNKNOWN MEDIA PROVIDER!'))
# raise Exception # 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': elif entry.get('type') == 'Music':
r['body'] = 'import MusicPlayer from \"src/components/MusicPlayer\"\n' r['body'] = ''
for m in entry['media']: for m in entry['media']:
if m == { 'main': 'true' } or m == { 'main': True } or m == {}: if m == { 'main': 'true' } or m == { 'main': True } or m == {}:
continue continue
# TODO: mark highlighted track isMain == True else:
try: r['body'] += '<MusicPlayer src=\"' + m['fileUrl'] + '\"' # TODO: mark highlighted track isMain == True
except: print(m) fileUrl = m.get('fileUrl', '')
try: r['body'] += ' title=\"' + m['title'] + '\"' if not fileUrl:
except: print(m) print(m)
r['body'] += ' />\n\n' continue
r['body'] += html2text(m.get('body', '')) 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': elif entry.get('type') == 'Image':
m = r.get('media') m = r.get('media')
try: r['body'] = '<img src=\"' + r['cover'] + '\" />' r['body'] = ''
except: print(entry) 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: if r.get('body') is None:
body_orig = entry.get('body', '') body_orig = entry.get('body', '')
body_html = str(BeautifulSoup(body_orig, features="html.parser")) 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) metadata = get_metadata(shout_dict)
content = frontmatter.dumps(frontmatter.Post(body, **metadata)) content = frontmatter.dumps(frontmatter.Post(body, **metadata))
ext = 'mdx' 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: try:
shout_dict['createdAt'] = date_parse(r.get('createdAt')) if entry.get('createdAt') else ts 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 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) #output = subprocess.check_output(cmd, shell=True)
#print(output) #print(output)
shout_filename = "%s.md" % (self.slug) shout_filename = "%s.mdx" % (self.slug)
shout_full_filename = "%s/%s" % (repo_path, shout_filename) shout_full_filename = "%s/%s" % (repo_path, shout_filename)
with open(shout_full_filename, mode='w', encoding='utf-8') as shout_file: with open(shout_full_filename, mode='w', encoding='utf-8') as shout_file:
shout_file.write(self.shout_body) shout_file.write(self.shout_body)