[www] Initial Fake Parsing Documents from Markdown. Added documents to Article

This commit is contained in:
Roman Timashev committed 2017-10-15 22:27:48 +03:00
1 parent 2630dfd1a2
commit 14954c2b71
3 files changed
+22 -12

No files matched your search

+4 -2
View File
@@ -19,12 +19,14 @@ def markdown_to_html(text):
])
def get_images_src(text: str) -> [str]:
def extract_files(text: str) -> [str]:
html = markdown(text)
post_html = lxml.html.fromstring(html)
images = post_html.cssselect('img')
return [img.get('src') for img in images]
images = [img.get('src') for img in images]
return images, []
def create_tree(text: str) -> str:
+1 -1
View File
@@ -101,7 +101,7 @@ async def create_post(provider: Provider, folder: str, md: str, sizes):
post = kazimir.html_from_tree(html)
post = await kazimir.typo(post)
return post, images
return post, images, []
def images_from_html(md):
+17 -9
View File
@@ -70,15 +70,18 @@ class Article(Model):
self.post = None
self.preview = None
self.images = None
self.documents = None
super().__init__(provider, store, file, params=params)
def init(self):
if self.has_param('content'):
images = kazimir.get_images_src(self.get_param('content'))
images, documents = kazimir.extract_files(self.get_param('content'))
else:
images = list_images(self.provider, self.file)
images = [os.path.relpath(i, self.file) for i in images]
documents = []
self.params['images'] = images
self.params['documents'] = documents
self.__set_id()
self.__set_hash()
@@ -99,9 +102,10 @@ class Article(Model):
else:
markdown_post = create_post_from_image_list(self.get_param('images'))
post, images = await create_post(self.provider, self.get_param('folder'), markdown_post, sizes)
post, images, documents = await create_post(self.provider, self.get_param('folder'), markdown_post, sizes)
self.post = post
self.images = images
self.documents = documents
if self.has_param('preview'):
preview = self.get_param('preview')
@@ -112,7 +116,8 @@ class Article(Model):
def bake(self):
return {
**self.params,
'images': [i.ref for i in self.images],
'images': [x.ref for x in self.images],
'documents': [x.ref for x in self.documents],
'post': self.post,
'id': self.id,
'hash': self.hash,
@@ -129,15 +134,18 @@ class Article(Model):
self.id = url_encode_text(self.params['title'])
def __set_hash(self):
f = self.params['folder']
images = sorted(self.params['images'])
files = []
files += sorted(self.get_param('images'))
files += sorted(self.get_param('documents'))
if self.has_param('preview'):
images.append(self.get_param('preview'))
images = [os.path.join(f, i) for i in images]
images = [self.provider.hash(i) for i in images]
files.append(self.get_param('preview'))
folder = self.get_param('folder')
files = [os.path.join(folder, x) for x in files]
files = [self.provider.hash(x) for x in files]
self.hash = hash_str(
combine([self.hash_salt] + [hash_str(self.params)] + images)
combine([self.hash_salt] + [hash_str(self.params)] + files)
)
def __str__(self):