added metas manager files (load, wip, publish)

This commit is contained in:
Cyrille L 2023-02-15 23:47:14 +01:00
parent 4de6d51ea3
commit 50baaf14f2
5 changed files with 130 additions and 135 deletions

View File

@ -38,6 +38,17 @@ def manage_domain(target):
else: logs.out("255", '', True)
#==============================================#
# When an active and complete domain is needed #
#----------------------------------------------#
def domain_needed():
# Check if can process
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
sys.exit(1)
#=====================#
# Create a new domain #
#---------------------#
@ -502,22 +513,16 @@ def create_domain(target):
#------------------------------#
def create_sidebar(option):
# Check if can process
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
return
domain_needed()
# Create an empty html file in wip server if not exists
try:
if not os.path.exists(db.wip_sidebar):
tyto.set_file(db.wip_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_sidebar)
if not os.path.exists(db.www_sidebar):
tyto.set_file(db.www_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.www_sidebar)
except:
logs.out("4", db.wip_sidebar, True)
# Create an empty html file in wip/www server if not exists
if not os.path.exists(db.wip_sidebar):
tyto.set_file(db.wip_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_sidebar)
if not os.path.exists(db.www_sidebar):
tyto.set_file(db.www_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.www_sidebar)
# Create new file, or ask if exists with option = 'reset'
ask = ' ├ Reset sidebar configuration file ? '
log = ' ├ Create source file: %s'%db.sidebar_load
@ -575,21 +580,15 @@ def create_sidebar(option):
#-----------------------------#
def create_navbar(option):
# Check if can process
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
return
domain_needed()
# Create an empty html file in wip server if not exists
try:
if not os.path.exists(db.wip_navbar):
tyto.set_file(db.wip_navbar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_navbar)
if not os.path.exists(db.www_navbar):
tyto.set_file(db.www_navbar, 'new', '')
print(' ├ Create empty file: %s'%db.www_navbar)
except:
logs.out("4", db.wip_navbar, True)
# Create an empty html file in wip/www server if not exists
if not os.path.exists(db.wip_navbar):
tyto.set_file(db.wip_navbar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_navbar)
if not os.path.exists(db.www_navbar):
tyto.set_file(db.www_navbar, 'new', '')
print(' ├ Create empty file: %s'%db.www_navbar)
# Create new file, or ask if exists
ask = ' ├ Reset navbar configuration file ? '
@ -654,3 +653,82 @@ def create_navbar(option):
tyto.set_file(db.navbar_load, 'new', nvb_load)
print(log)
#========================#
# metas_load source file #
#------------------------#
def create_metas(option):
# Check if can process
domain_needed()
# Set metas_load default content
#-------------------------------
metas_tags = \
'<!-- Custom HTML metas for all pages\n' + \
'# You can add/edit HTML tags\n' + \
'# ! Only <meta > and <link > lines are used !\n' + \
'# After editing, use "tyto metas -n"\n' + \
'# (You should not copy this file to template)' + \
'\n' + \
'# Already set metas with values:\n' + \
'# <meta charset="UTF-8">\n' + \
'# <meta name="viewport" ...>\n' + \
'# <meta name=”url” ...>\n' + \
'# <meta name="language" ...>\n' + \
'# <meta name="reply-to" ...>\n' + \
'# <meta name="copyright" ...>\n' + \
'# <meta name="generator" ...>\n' + \
'# <meta name="title" ...>\n' + \
'# <meta name="author" ...>\n' + \
'# <meta name="description" ...>\n' + \
'# <meta name="keywords" ...>\n' + \
'# <meta name="search_date" ...>\n' + \
'# <link rel="canonical" ..." />\n' + \
'# <link rel="alternate" ..." /> # RSS\n' + \
'# <link rel="stylesheet" ... />\n' + \
'# <link rel="shortcut icon" ... />\n' + \
'# <link rel="me" ... > # if profile url in config\n' + \
'# Open Graph data\n' + \
'# <meta property="og:site_name" ... />\n' + \
'# <meta property="og:title" ... />\n' + \
'# <meta property="og:type" ... />\n' + \
'# <meta property="og:url" ... />\n' + \
'# <meta property="og:description" ... />\n' + \
'# <meta property="og:image" ... />\n' + \
'-->\n' + \
'<meta name="robots" content="all">\n' + \
'<meta name="medium" content="website">\n' + \
'<meta name="revisit-after" content="3 days">'
metas_srvs = \
' <meta name="robots" content="all">\n' + \
' <meta name="medium" content="website">\n' + \
' <meta name="revisit-after" content="3 days">'
# Create an empty html file in wip/www server if not exists
if not os.path.exists(db.wip_metas):
tyto.set_file(db.wip_metas, 'new', metas_srvs)
print(' ├ Create empty file: %s'%db.wip_metas)
if not os.path.exists(db.www_metas):
tyto.set_file(db.www_metas, 'new', metas_srvs)
print(' ├ Create empty file: %s'%db.www_metas)
# Create new file, or ask if exists
ask = ' ├ Reset metas configuration file ? '
log = ' ├ Create source file: %s'%db.metas_load
res = ''
if os.path.exists(db.metas_load):
try:
res = input(ask)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return
tyto.set_file(db.metas_load, 'new', metas_tags)
print(log)

View File

@ -475,112 +475,27 @@ def create_navbar(option):
# Create DB file with hash from _configs/tyto.metas.html #
# To manage new creation if changes #
#--------------------------------------------------------#
def create_user_metas(option):
if not db.domain_exists: return
def create_user_metas(option):
# Check if can process
domain.domain_needed()
create_load = False # file in _configs
create_html = False # file in template/
# Get metas_load hash or create metas db file if not exists
#----------------------------------------------------------
if os.path.exists(db.metas_load):
create_db_load(db.metas_load, db.metas_load_db)
if option == 'wip': target = db.wip_navbar
elif option == 'www': target = db.www_navbar
# Manage option
#--------------
if not os.path.exists(db.metas_load):
create_load = True
elif option == 'New':
create_load = True
create_html = True
elif option == 'Create':
create_html = True
elif option == 'Edit':
hash_load_old = tyto.get_filesum(db.metas_load, True)
tyto.edit_file(db.metas_load)
hash_load_new = tyto.get_filesum(db.metas_load, True)
if not hash_load_old == hash_load_new:
create_db_load(db.metas_load, db.metas_load_db)
create_html = True
elif option == 'Force':
create_load = True
create_html = True
# Set metas_load default content
#-------------------------------
metas_tags = \
'<!-- Custom HTML metas for all pages\n' + \
'# You can add/edit HTML tags\n' + \
'# ! Only <meta > and <link > lines are used !\n' + \
'# After editing, use "tyto metas -n"\n' + \
'# (You should not copy this file to template)' + \
'\n' + \
'# Already set metas with values:\n' + \
'# <meta charset="UTF-8">\n' + \
'# <meta name="viewport" ...>\n' + \
'# <meta name=”url” ...>\n' + \
'# <meta name="language" ...>\n' + \
'# <meta name="reply-to" ...>\n' + \
'# <meta name="copyright" ...>\n' + \
'# <meta name="generator" ...>\n' + \
'# <meta name="title" ...>\n' + \
'# <meta name="author" ...>\n' + \
'# <meta name="description" ...>\n' + \
'# <meta name="keywords" ...>\n' + \
'# <meta name="search_date" ...>\n' + \
'# <link rel="canonical" ..." />\n' + \
'# <link rel="alternate" ..." /> # RSS\n' + \
'# <link rel="stylesheet" ... />\n' + \
'# <link rel="shortcut icon" ... />\n' + \
'# <link rel="me" ... > # if profile url in config\n' + \
'# Open Graph data\n' + \
'# <meta property="og:site_name" ... />\n' + \
'# <meta property="og:title" ... />\n' + \
'# <meta property="og:type" ... />\n' + \
'# <meta property="og:url" ... />\n' + \
'# <meta property="og:description" ... />\n' + \
'# <meta property="og:image" ... />\n' + \
'-->\n' + \
'<meta name="robots" content="all">\n' + \
'<meta name="medium" content="website">\n' + \
'<meta name="revisit-after" content="3 days">'
# Create metas_load file according to option
#-------------------------------------------
if create_load:
ask_load = ' ├ Reset metas configuration file ? '
log_load = ' ├ Create file: %s'%db.metas_load
res = ''
if os.path.exists(db.metas_load):
try:
res = input(ask_load)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return
tyto.set_file(db.metas_load, True, metas_tags)
create_html = True
create_db_load(db.metas_load, db.metas_load_db)
print(log_load)
# Create wip metas.html file according to option
#-----------------------------------------------
if create_html:
ask_html = ' ├ Replace %s ? '%db.wip_metas
log_html = ' ├ Create file: %s'%db.wip_metas
user_metas = ''
metas_used = ('<meta ', '<link ')
res = ''
if os.path.exists(db.wip_metas):
try:
res = input(ask_html)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return
ask_html = ' ├ Replace %s ? '%target
log_html = ' ├ Create file: %s'%target
user_metas = ''
metas_used = ('<meta ', '<link ')
res = ''
if os.path.exists(target):
try:
res = input(ask_html)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return
user_file = open(db.metas_load, 'r').read()
@ -589,7 +504,7 @@ def create_user_metas(option):
if user_metas: user_metas = "%s\n %s"%(user_metas, line)
else: user_metas = ' %s'%line
tyto.set_file(db.wip_metas, True, user_metas)
tyto.set_file(target, True, user_metas)
print(log_html)

View File

@ -36,7 +36,8 @@ def manage_publish(target):
if target in args.pass_targets:
do = {
'sidebar' : html.create_sidebar,
'navbar' : html.create_navbar
'navbar' : html.create_navbar,
'metas' : html.create_user_metas
}
do[target]('www')

View File

@ -196,7 +196,7 @@ def set_file(path, new, text):
file.write(text + '\n')
file.close()
except:
logs.out("4", db.domain_conf, True)
logs.out("4", path, True)
#==========================#

View File

@ -37,7 +37,8 @@ def manage_wip(target):
if target in args.pass_targets:
do = {
'sidebar' : html.create_sidebar,
'navbar' : html.create_navbar
'navbar' : html.create_navbar,
'metas' : html.create_user_metas
}
do[target]('wip')