Added directory source to database. Fix wip/publish for subfolders articles

This commit is contained in:
Cyrille L 2023-03-06 17:00:37 +01:00
parent 8c313d3366
commit 06946a5c46
4 changed files with 22 additions and 20 deletions

View File

@ -63,12 +63,14 @@ def manage_check(target):
ext_src = os.path.splitext(target) ext_src = os.path.splitext(target)
# Get uri after articles/ (no starting / in value) # Get uri after articles/ (no starting / in value)
global src_post_short_uri, srv_post_short_uri global src_post_short_uri, srv_post_short_uri, direc_src
global srv_post_wip_uri, srv_post_www_uri global srv_post_wip_uri, srv_post_www_uri
src_post_short_uri = db.uri_file.rsplit(db.domain_articles)[1] src_post_short_uri = db.uri_file.rsplit(db.domain_articles)[1]
srv_post_short_uri = src_post_short_uri.replace(ext_src[1], '.html') srv_post_short_uri = src_post_short_uri.replace(ext_src[1], '.html')
srv_post_wip_uri = db.srv_wip + srv_post_short_uri srv_post_wip_uri = db.srv_wip + srv_post_short_uri
srv_post_www_uri = db.srv_www + srv_post_short_uri srv_post_www_uri = db.srv_www + srv_post_short_uri
direc_src = src_post_short_uri.split("/")[-1]
direc_src = src_post_short_uri.rsplit(direc_src)[0]
# Get sub_uri for HTML # Get sub_uri for HTML
global sub_uri global sub_uri
@ -80,11 +82,11 @@ def manage_check(target):
# Set HTTP link for wip and www # Set HTTP link for wip and www
global http_www, http_wip global http_www, http_wip
if srv_post_short_uri.endswith('index.html'): if srv_post_short_uri.endswith('index.html'):
http_www = "%s/"%db.domain_www_url http_www = "%s/%s"%(db.domain_www_url, direc_src)
http_wip = '%s/'%db.domain_wip_url http_wip = '%s/%s'%(db.domain_wip_url, direc_src)
else: else:
http_www = "%s%s"%(db.domain_www_url, srv_post_short_uri) http_www = "%s/%s"%(db.domain_www_url, srv_post_short_uri)
http_wip = '%s%s'%(db.domain_wip_url, srv_post_short_uri) http_wip = '%s/%s'%(db.domain_wip_url, srv_post_short_uri)
# Start checking processes # Start checking processes
#------------------------- #-------------------------
@ -665,6 +667,7 @@ def create_database():
'post_wip = "%s"\n'%srv_post_wip_uri + \ 'post_wip = "%s"\n'%srv_post_wip_uri + \
'post_www = "%s"\n'%srv_post_www_uri + \ 'post_www = "%s"\n'%srv_post_www_uri + \
'\n' + \ '\n' + \
'direc_src = "%s"\n'%direc_src + \
'short_src = "%s"\n'%src_post_short_uri + \ 'short_src = "%s"\n'%src_post_short_uri + \
'short_srv = "%s"\n'%srv_post_short_uri + \ 'short_srv = "%s"\n'%srv_post_short_uri + \
'sub_uri = "%s"\n'%sub_uri + \ 'sub_uri = "%s"\n'%sub_uri + \

View File

@ -218,6 +218,7 @@ def create_sidebar(option):
except: except:
logs.out("1", 'Sidebar load file', True) logs.out("1", 'Sidebar load file', True)
pub_opts = ('www', 'pub')
if option == 'wip': target = db.wip_sidebar if option == 'wip': target = db.wip_sidebar
elif option == 'www': target = db.www_sidebar elif option == 'www': target = db.www_sidebar
elif option == 'pub': target = db.www_sidebar elif option == 'pub': target = db.www_sidebar
@ -272,7 +273,7 @@ def create_sidebar(option):
if not os.path.exists(post_wip): if not os.path.exists(post_wip):
logs.out("24", 'in wip: %s'%post_wip, False) logs.out("24", 'in wip: %s'%post_wip, False)
continue continue
elif option == 'www': elif option in pub_opts:
if not hash_www == hash_chk: if not hash_www == hash_chk:
logs.out("30", '%s "%s"'%(line, title), False) logs.out("30", '%s "%s"'%(line, title), False)
continue continue
@ -296,12 +297,12 @@ def create_sidebar(option):
logs.out("35", '"%s": %s'%(title, line), False) logs.out("35", '"%s": %s'%(title, line), False)
# Create HTML list for this article # Create HTML list for this article
link_title = '%s [@%s]'%(about, author) link_title = '%s [%s]'%(about, author)
sidebar_list = sidebar_list + \ sidebar_list = sidebar_list + \
' <li class="sidebar_item">\n' + \ ' <li class="sidebar_item">\n' + \
' <a class="sidebar_item_link"\n' + \ ' <a class="sidebar_item_link"\n' + \
' href="%s">\n' + \ ' href="/%s"\n'%short_srv + \
' title="%s">\n'%(link_title) + \ ' title="%s">\n'%link_title + \
' <h2 class="sidebar_item_title">%s</h2>\n'%title + \ ' <h2 class="sidebar_item_title">%s</h2>\n'%title + \
' <p class="sidebar_item_about">%s [%s] - %s</p>\n'%( ' <p class="sidebar_item_about">%s [%s] - %s</p>\n'%(
date[0], author, about) + \ date[0], author, about) + \
@ -313,8 +314,7 @@ def create_sidebar(option):
if not sidebar_has: if not sidebar_has:
logs.out('29', '(sidebar): %s'%db.sidebar_load, False) logs.out('29', '(sidebar): %s'%db.sidebar_load, False)
return return
# Some items, but no one is valid else: # Some items, but no one is valid
else:
logs.out('28', '(sidebar)', False) logs.out('28', '(sidebar)', False)
return return

View File

@ -81,9 +81,11 @@ def manage_publish(target):
# #
def publish_article(): def publish_article():
# Copy wip page to www page # Copy wip page to www page
os.makedirs('%s%s'%(db.srv_www, db.direc_src), exist_ok=True)
shutil.copy2(db.post_wip, db.post_www) shutil.copy2(db.post_wip, db.post_www)
logs.out("33", db.post_www, False) logs.out("33", db.post_www, False)
# Copy files registred in article # Copy files registred in article
for uri in db.uris: for uri in db.uris:
f_src = '%s%s'%(db.srv_wip, uri) f_src = '%s%s'%(db.srv_wip, uri)

View File

@ -86,15 +86,11 @@ def manage_wip(target):
if db.hash_wip != db.hash_chk: # Article has changed if db.hash_wip != db.hash_chk: # Article has changed
wip_article(db.uri_file) wip_article(db.uri_file)
else: else:
if not os.path.exists(db.post_wip): logs.out("19", db.date_wip, False)
logs.out("24", '(wip article): %s'%db.post_wip, False) ask = ''
wip_article(db.uri_file) ask = input(' ├ Create new wip page ? ')
else: if not ask in ['y', 'Y']: return
logs.out("19", db.date_wip, False) wip_article(db.uri_file)
ask = ''
ask = input(' ├ Create new wip page ? ')
if not ask in ['y', 'Y']: return
wip_article(db.uri_file)
#===================# #===================#
@ -142,6 +138,7 @@ def wip_article(target):
#print(html.main_page) #print(html.main_page)
# Create wip file # Create wip file
os.makedirs('%s%s'%(db.srv_wip, db.direc_src), exist_ok=True)
tyto.set_file(db.post_wip, 'New', html.main_page) tyto.set_file(db.post_wip, 'New', html.main_page)
logs.out("33", db.post_wip, False) logs.out("33", db.post_wip, False)