[Sync] base create_post function moved to Album model
This commit is contained in:
1 parent
dfef6d1e0f
commit
096848a3d1
2 files changed
+16
-17
No files matched your search
@@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from lxml import etree
|
|
||||||
|
|
||||||
import lxml.html
|
import lxml.html
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
@@ -79,20 +78,6 @@ def create_date_and_title_from_folder_name(folder_name, date_formats=None):
|
|||||||
return date, title
|
return date, title
|
||||||
|
|
||||||
|
|
||||||
async def create_post(md, image_path_fn):
|
|
||||||
html = lxml.html.fromstring(md)
|
|
||||||
|
|
||||||
for img in html.cssselect('img'):
|
|
||||||
src = img.get('src')
|
|
||||||
path = await image_path_fn(src)
|
|
||||||
|
|
||||||
if path:
|
|
||||||
img.set('src', path)
|
|
||||||
img.set('class', settings.album_html_img_class)
|
|
||||||
img.set('data-file', src)
|
|
||||||
return etree.tounicode(html)
|
|
||||||
|
|
||||||
|
|
||||||
def images_from_html(md):
|
def images_from_html(md):
|
||||||
if not md:
|
if not md:
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
import lxml.html
|
import lxml.html
|
||||||
|
|
||||||
import kazimir
|
import kazimir
|
||||||
import settings
|
import settings
|
||||||
from db import collection
|
from db import collection
|
||||||
from sync import create_date_and_title_from_folder_name, images_from_html, create_post_from_image_list, create_date, \
|
from sync import create_date_and_title_from_folder_name, images_from_html, create_post_from_image_list, create_date
|
||||||
create_post
|
|
||||||
from sync.data import Provider, list_images
|
from sync.data import Provider, list_images
|
||||||
from sync.models import Model
|
from sync.models import Model
|
||||||
from sync.models.Image import Image
|
from sync.models.Image import Image
|
||||||
@@ -247,3 +247,17 @@ def id_from_file(i):
|
|||||||
return url_encode_text(
|
return url_encode_text(
|
||||||
os.path.splitext(i)[0]
|
os.path.splitext(i)[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def create_post(md, image_path_fn):
|
||||||
|
html = lxml.html.fromstring(md)
|
||||||
|
|
||||||
|
for img in html.cssselect('img'):
|
||||||
|
src = img.get('src')
|
||||||
|
path = await image_path_fn(src)
|
||||||
|
|
||||||
|
if path:
|
||||||
|
img.set('src', path)
|
||||||
|
img.set('class', settings.album_html_img_class)
|
||||||
|
img.set('data-file', src)
|
||||||
|
return etree.tounicode(html)
|
||||||
Reference in new issue
Block a user