[www] Initial Fake Parsing Documents from Markdown. Added documents to Article
This commit is contained in:
1 parent
2630dfd1a2
commit
14954c2b71
3 files changed
+22
-12
No files matched your search
@@ -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)
|
html = markdown(text)
|
||||||
post_html = lxml.html.fromstring(html)
|
post_html = lxml.html.fromstring(html)
|
||||||
|
|
||||||
images = post_html.cssselect('img')
|
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:
|
def create_tree(text: str) -> str:
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ async def create_post(provider: Provider, folder: str, md: str, sizes):
|
|||||||
post = kazimir.html_from_tree(html)
|
post = kazimir.html_from_tree(html)
|
||||||
post = await kazimir.typo(post)
|
post = await kazimir.typo(post)
|
||||||
|
|
||||||
return post, images
|
return post, images, []
|
||||||
|
|
||||||
|
|
||||||
def images_from_html(md):
|
def images_from_html(md):
|
||||||
|
|||||||
@@ -70,15 +70,18 @@ class Article(Model):
|
|||||||
self.post = None
|
self.post = None
|
||||||
self.preview = None
|
self.preview = None
|
||||||
self.images = None
|
self.images = None
|
||||||
|
self.documents = None
|
||||||
super().__init__(provider, store, file, params=params)
|
super().__init__(provider, store, file, params=params)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if self.has_param('content'):
|
if self.has_param('content'):
|
||||||
images = kazimir.get_images_src(self.get_param('content'))
|
images, documents = kazimir.extract_files(self.get_param('content'))
|
||||||
else:
|
else:
|
||||||
images = list_images(self.provider, self.file)
|
images = list_images(self.provider, self.file)
|
||||||
images = [os.path.relpath(i, self.file) for i in images]
|
images = [os.path.relpath(i, self.file) for i in images]
|
||||||
|
documents = []
|
||||||
self.params['images'] = images
|
self.params['images'] = images
|
||||||
|
self.params['documents'] = documents
|
||||||
|
|
||||||
self.__set_id()
|
self.__set_id()
|
||||||
self.__set_hash()
|
self.__set_hash()
|
||||||
@@ -99,9 +102,10 @@ class Article(Model):
|
|||||||
else:
|
else:
|
||||||
markdown_post = create_post_from_image_list(self.get_param('images'))
|
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.post = post
|
||||||
self.images = images
|
self.images = images
|
||||||
|
self.documents = documents
|
||||||
|
|
||||||
if self.has_param('preview'):
|
if self.has_param('preview'):
|
||||||
preview = self.get_param('preview')
|
preview = self.get_param('preview')
|
||||||
@@ -112,7 +116,8 @@ class Article(Model):
|
|||||||
def bake(self):
|
def bake(self):
|
||||||
return {
|
return {
|
||||||
**self.params,
|
**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,
|
'post': self.post,
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
'hash': self.hash,
|
'hash': self.hash,
|
||||||
@@ -129,15 +134,18 @@ class Article(Model):
|
|||||||
self.id = url_encode_text(self.params['title'])
|
self.id = url_encode_text(self.params['title'])
|
||||||
|
|
||||||
def __set_hash(self):
|
def __set_hash(self):
|
||||||
f = self.params['folder']
|
files = []
|
||||||
images = sorted(self.params['images'])
|
files += sorted(self.get_param('images'))
|
||||||
|
files += sorted(self.get_param('documents'))
|
||||||
if self.has_param('preview'):
|
if self.has_param('preview'):
|
||||||
images.append(self.get_param('preview'))
|
files.append(self.get_param('preview'))
|
||||||
images = [os.path.join(f, i) for i in images]
|
|
||||||
images = [self.provider.hash(i) for i in images]
|
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(
|
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):
|
def __str__(self):
|
||||||
|
|||||||
Reference in new issue
Block a user