Fix: new domain_conf check. HTML: indev, created some metas tags
This commit is contained in:
parent
9a407e8e61
commit
e3908df489
|
@ -41,7 +41,7 @@ def manage_check(target, option):
|
|||
|
||||
# target needed
|
||||
if not target: tyto.exiting("5", '', True)
|
||||
|
||||
|
||||
# Article exists + has DB ?
|
||||
db_exists = tyto.get_db_post(target)
|
||||
|
||||
|
@ -70,7 +70,13 @@ def manage_check(target, option):
|
|||
tyto.exiting("20", date_chk, True)
|
||||
except: pass
|
||||
except: pass
|
||||
|
||||
|
||||
# Get sub_uri for HTML
|
||||
global sub_uri
|
||||
sub_uri = tyto.uri_post.rsplit('articles/')[1]
|
||||
sub_nbr = sub_uri.count('/')
|
||||
if sub_nbr == 0 : sub_uri = './'
|
||||
else: sub_uri = sub_nbr * '../'
|
||||
|
||||
# Start processes
|
||||
file_to_string(tyto.uri_root)
|
||||
|
@ -96,7 +102,6 @@ def manage_check(target, option):
|
|||
post_bottom = article_bottom.rsplit('\n')
|
||||
|
||||
check_headers(post_header)
|
||||
|
||||
|
||||
# Exit if unused needed tags
|
||||
if post_err: tyto.exiting("7", '', True)
|
||||
|
@ -623,6 +628,7 @@ def create_database():
|
|||
'wip_uri = "%s%s"\n'%(srv_wip, web_uri) + \
|
||||
'www_uri = "%s%s"\n'%(srv_www, web_uri) + \
|
||||
'http_uri = "%s"\n'%tyto.web_uri + \
|
||||
'sub_uri = "%s"\n'%sub_uri + \
|
||||
'\n' + \
|
||||
'date_chk = "%s"\n'%tyto.nowdate() + \
|
||||
'hash_chk = "%s"\n'%tyto.hash_post + \
|
||||
|
|
|
@ -31,11 +31,11 @@ def manage_domain(target, option):
|
|||
|
||||
elif option == 'New':
|
||||
if not tyto.domain_exists:
|
||||
create_domain(target)
|
||||
create_domain(target, option)
|
||||
else:
|
||||
print(':) A domain exists in this directory')
|
||||
ask = input('-> Edit it with the form ? ')
|
||||
if ask in ['y', 'Y']: create_domain(target)
|
||||
if ask in ['y', 'Y']: create_domain(target, option)
|
||||
else: tyto.exiting("255", '', True)
|
||||
|
||||
elif option == 'DB' or option == 'Show':
|
||||
|
@ -58,7 +58,7 @@ def isurl(target):
|
|||
#=====================#
|
||||
# Create a new domain #
|
||||
#---------------------#
|
||||
def create_domain(target):
|
||||
def create_domain(target, option):
|
||||
if target: isurl(target)
|
||||
|
||||
print('\n'
|
||||
|
@ -105,13 +105,13 @@ def create_domain(target):
|
|||
domain_wipurl = ask
|
||||
|
||||
|
||||
db_dir = '%s/.local/tyto/'%tyto.home_dir
|
||||
conf_domain = 'domain_conf = "%s"\n'%tyto.domain_conf + \
|
||||
'domain_db = "%s/%s/articles/"\n'%(db_dir, target) + \
|
||||
'domain_dir = "%s/"\n'%tyto.in_dir + \
|
||||
'domain_articles = "%s/articles/"\n'%tyto.in_dir + \
|
||||
'domain_files = "%s/articles/files/"\n'%tyto.in_dir + \
|
||||
'domain_images = "%s/articles/images/"\n'%tyto.in_dir + \
|
||||
db_dir = '%s/.local/tyto/%s/'%(tyto.home_dir, domain_short)
|
||||
conf_domain = 'domain_dir = "%s"\n'%tyto.conf_dir + \
|
||||
'domain_conf = "%s"\n'%tyto.domain_conf + \
|
||||
'domain_articles = "%sarticles/"\n'%tyto.conf_dir + \
|
||||
'domain_files = "%sarticles/files/"\n'%tyto.conf_dir + \
|
||||
'domain_images = "%sarticles/images/"\n'%tyto.conf_dir + \
|
||||
'domain_db = "%sarticles/"\n'%(db_dir) + \
|
||||
'\ndomain_short = "%s"\n'%domain_short + \
|
||||
'domain_url = "%s"\n'%domain_url + \
|
||||
'domain_wipurl = "%s"\n'%domain_wipurl
|
||||
|
@ -128,7 +128,8 @@ def create_domain(target):
|
|||
ask = input(' ├ Domain title ? ("%s") '%domain_title)
|
||||
if ask: domain_title = ask
|
||||
elif not domain_title: tyto.exit("255")
|
||||
if '"' in domain_title: domain_title=domain_title.replace('"', '\\"')
|
||||
if '"' in domain_title:
|
||||
domain_title = domain_title.replace('"', '')
|
||||
|
||||
tyto.set_file(tyto.domain_conf, False,
|
||||
'domain_title = "%s"'%domain_title)
|
||||
|
@ -143,7 +144,8 @@ def create_domain(target):
|
|||
ask = input(' ├ Domain Description ? ("%s") '%domain_about)
|
||||
if ask: domain_about = ask
|
||||
elif not domain_about: tyto.exit("255")
|
||||
if '"' in domain_about: domain_about=domain_about.replace('"', '\\"')
|
||||
if '"' in domain_about:
|
||||
domain_about = domain_about.replace('"', '')
|
||||
|
||||
tyto.set_file(tyto.domain_conf, False,
|
||||
'domain_about = "%s"'%domain_about)
|
||||
|
@ -205,7 +207,7 @@ def create_domain(target):
|
|||
if ask: domain_license = ask
|
||||
elif not domain_license: tyto.exiting("255", '', True)
|
||||
if '"' in domain_license:
|
||||
domain_license=domain_license.replace('"', '\\"')
|
||||
domain_license = domain_license.replace('"', '')
|
||||
|
||||
tyto.set_file(tyto.domain_conf, False,
|
||||
'domain_license = "%s"'%domain_license)
|
||||
|
@ -265,9 +267,9 @@ def create_domain(target):
|
|||
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title)
|
||||
if ask: sidebar_title = ask
|
||||
if '"' in sidebar_title:
|
||||
sidebar_title = sidebar_title.replace('"', '\\"')
|
||||
sidebar_title = sidebar_title.replace('"', '')
|
||||
|
||||
sidebar_conf = '%s/articles/sidebar/'%tyto.in_dir
|
||||
sidebar_conf = '%sarticles/sidebar/'%tyto.conf_dir
|
||||
sidebar_datas = '\nsidebar_dir = "%s"\n'%sidebar_conf + \
|
||||
'sidebar_load = "%styto.sidebar"\n'%sidebar_conf + \
|
||||
'sidebar_title = "%s"'%sidebar_title
|
||||
|
@ -290,7 +292,6 @@ def create_domain(target):
|
|||
'sidebar_items = "%s"'%int(sidebar_items))
|
||||
|
||||
|
||||
|
||||
# Get srv root
|
||||
#-------------
|
||||
try: domain_srv = tyto.domain_srv
|
||||
|
@ -347,7 +348,7 @@ def create_domain(target):
|
|||
exec(open(tyto.domain_conf).read(),globals())
|
||||
|
||||
# Create sidebar
|
||||
create_sidebar(opt, sidebar_dir)
|
||||
create_sidebar(option, sidebar_dir)
|
||||
|
||||
# Create folders from configuration file
|
||||
folders = (
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: HTML template
|
||||
# Description: Create raw HTML template
|
||||
# file: html.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
#------------
|
||||
# lines:
|
||||
# functions:
|
||||
# comments:
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#**********************************************************************
|
||||
|
||||
import tyto
|
||||
|
||||
# Load domain configuration DB
|
||||
exec(open(tyto.domain_conf).read(),globals())
|
||||
|
||||
Tyto = 'Tyto - Littérateur'
|
||||
tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur'
|
||||
tytoweb = 'https://tyto.echolib.re'
|
||||
|
||||
#==========================#
|
||||
# Load article DB #
|
||||
# Start HTML page sections #
|
||||
#--------------------------#
|
||||
def set_page(post_db):
|
||||
exec(open(post_db).read(),globals())
|
||||
|
||||
create_metas_page() # Include metas tags
|
||||
create_main_page() # At last, create main page
|
||||
|
||||
|
||||
#============================================#
|
||||
# Set metas_page to be included in main page #
|
||||
#--------------------------------------------#
|
||||
def create_metas_page():
|
||||
global metas_page
|
||||
|
||||
# Settings for metas
|
||||
#-------------------
|
||||
metas_page = ''
|
||||
tab = 4
|
||||
scale = 'width=device-width, initial-scale=1.0'
|
||||
visit = '3 days'
|
||||
all_tags = domain_tags + ',' + tags
|
||||
post_url = domain_url + http_uri
|
||||
css_file = 'template/style.css'
|
||||
css_ref = 'media="screen" href="%s%s" />'%(sub_uri, css_file)
|
||||
rss_file = 'rss.xml'
|
||||
rss_ref = 'type="application/rss+xml" ' + \
|
||||
'href="%s%s" title="RSS 2.0. %s %s %s'%(
|
||||
sub_uri, rss_file, domain_title, domain_sep, domain_short
|
||||
)
|
||||
icon_file = 'favicon.png'
|
||||
icon_ref = 'type="image/png" href="%s%s"'%(sub_uri, icon_file)
|
||||
en_date = tyto.set_en_date(date[0])
|
||||
|
||||
|
||||
# Set all raw HTML metas
|
||||
#-----------------------
|
||||
metas = '<meta charset="utf-8">\n' + \
|
||||
'<meta name="viewport" content="%s">\n'%scale + \
|
||||
'<meta name="robots" content="all">\n' + \
|
||||
'<meta name="medium" content="website">\n' + \
|
||||
'<meta name="revisit-after" content="%s">\n'%visit + \
|
||||
'<meta name="language" content="%s">\n'%domain_lang + \
|
||||
'<meta name="reply-to" content="%s">\n'%domain_mail + \
|
||||
'<meta name="copyright" content="%s">\n'%domain_license + \
|
||||
'<meta name="generator" content="%s">\n'%Tyto + \
|
||||
'<meta name="title" content="%s">\n'%title + \
|
||||
'<meta name="author" content="%s">\n'%author + \
|
||||
'<meta name="description" content="%s">\n'%about + \
|
||||
'<meta name="keywords" content="%s">\n'%all_tags + \
|
||||
'<meta name="search_date" content="%s">\n'%en_date + \
|
||||
'<link rel="canonical" href="%s" />\n'%post_url + \
|
||||
'<link rel="alternate" %s />\n'%(rss_ref) + \
|
||||
'<link rel="stylesheet" %s\n'%css_ref + \
|
||||
'<link rel="shortcut icon" %s />\n'%icon_ref
|
||||
|
||||
|
||||
# Create HTML tabulation for metas
|
||||
#---------------------------------
|
||||
for line in metas.rsplit('\n'):
|
||||
if metas_page: metas_page = '%s\n%s%s'%(metas_page, tab * ' ', line)
|
||||
else: metas_page = '%s%s'%(tab * ' ', line)
|
||||
|
||||
|
||||
#=======================================#
|
||||
# Set main page, with all HTML sections #
|
||||
#---------------------------------------#
|
||||
def create_main_page():
|
||||
global main_page
|
||||
|
||||
main_page = '<!doctype html>\n' + \
|
||||
'<html lang="%s">\n'%domain_lang + \
|
||||
' <head>\n' + \
|
||||
'%s\n'%metas_page + \
|
||||
' </head>\n\n' + \
|
||||
' <body>\n' + \
|
||||
'%s\n' + \
|
||||
' </body>\n' + \
|
||||
'</html>'
|
|
@ -27,7 +27,8 @@ arguments = (
|
|||
'-R', 'remove',
|
||||
'-e', 'edit',
|
||||
'-n', 'new',
|
||||
'-F', 'force'
|
||||
'-F', 'force',
|
||||
'-d'
|
||||
)
|
||||
|
||||
# Settings
|
||||
|
@ -35,20 +36,21 @@ arguments = (
|
|||
domain_active = False
|
||||
home_dir = os.path.expanduser('~')
|
||||
in_dir = os.getcwd()
|
||||
domain_conf = in_dir
|
||||
|
||||
# Set uri for configuration domain file
|
||||
try:
|
||||
sys.argv[2]
|
||||
if not sys.argv[2] in arguments:
|
||||
conf_dir = '%s/%s'%(in_dir,sys.argv[2])
|
||||
conf_dir = conf_dir.rsplit('articles')[0]
|
||||
else:
|
||||
conf_dir = in_dir.rsplit('articles')[0] + '/'
|
||||
except:
|
||||
conf_dir = in_dir.rsplit('articles')[0] + '/'
|
||||
if '/articles' in in_dir:
|
||||
domain_conf = in_dir.rsplit('/articles')[0]
|
||||
else:
|
||||
try:
|
||||
sys.argv[2]
|
||||
if not sys.argv[2] in arguments:
|
||||
if 'articles/' in sys.argv[2]:
|
||||
domain_conf = in_dir.rsplit('articles/')[0]
|
||||
except:
|
||||
domain_conf = in_dir
|
||||
|
||||
domain_conf = '%styto_domain.conf'%conf_dir
|
||||
db_dir = '%s/.local/tyto/'%home_dir
|
||||
conf_dir = domain_conf + "/"
|
||||
domain_conf = '%s/tyto_domain.conf'%domain_conf
|
||||
|
||||
|
||||
# Check if domain config file
|
||||
|
@ -63,18 +65,18 @@ if os.path.exists(domain_conf):
|
|||
smiley = ':D'; status = 'Active'
|
||||
domain_active = True
|
||||
else:
|
||||
smiley = ':/'; status = 'Inactive'
|
||||
smiley = ':|'; status = 'Inactive'
|
||||
domain_active = False
|
||||
print(stdout%(
|
||||
smiley, status, domain_short, domain_conf
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(':| No domain configured in this directory: %s'%domain_conf)
|
||||
print(':? No domain configured in this directory: %s'%domain_conf)
|
||||
domain_exists = domain_active = False
|
||||
|
||||
if domain_exists:
|
||||
db_dir = '%s%s/articles'%(db_dir, domain_short)
|
||||
db_dir = domain_db
|
||||
|
||||
|
||||
# Basic translations: french, english
|
||||
|
@ -84,11 +86,13 @@ except: lang = locale.getdefaultlocale()[0].split('_')[0]
|
|||
if lang.lower() == 'fr': n = 0
|
||||
else: n = 1
|
||||
|
||||
|
||||
# Translations French/English
|
||||
trans = [
|
||||
['À l\'affiche !', 'Featured !' ]
|
||||
]
|
||||
|
||||
|
||||
# Set all tags used in article's header
|
||||
headers = (
|
||||
'title:',
|
||||
|
@ -103,13 +107,15 @@ headers = (
|
|||
'raw:',
|
||||
'#'
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Colors
|
||||
CS = '\033[0;0m'
|
||||
CR = '\033[1;31m'
|
||||
CY = '\033[1;33m'
|
||||
CG = '\033[1;32m'
|
||||
|
||||
|
||||
# Words and template Tags (paragraphs, lists, bold, strong...)
|
||||
# Used to check, and replace (wip) tags
|
||||
# As base64 is used, do NOT set marker: =_ _=
|
||||
|
@ -190,13 +196,21 @@ def get_filesum(path, src):
|
|||
|
||||
#==============================#
|
||||
# Set and return date and time #
|
||||
# (especially for logs) #
|
||||
#------------------------------#
|
||||
def nowdate():
|
||||
now = datetime.datetime.now()
|
||||
return(now.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
|
||||
#=======================================#
|
||||
# Convert date DD/MM/YYYY to YYYY-MM-DD #
|
||||
#---------------------------------------#
|
||||
def set_en_date(date):
|
||||
if domain_lang.lower() == 'fr':
|
||||
udate = date.rsplit('/')
|
||||
return('%s-%s-%s'%(udate[2], udate[1], udate[0]))
|
||||
|
||||
|
||||
#=======================#
|
||||
# Check if article file #
|
||||
# Check if article DB #
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#**********************************************************************
|
||||
import os, re
|
||||
import tyto
|
||||
import tyto, html
|
||||
|
||||
def manage_wip(target, option):
|
||||
# target needed
|
||||
|
@ -89,6 +89,12 @@ def wip_article(target):
|
|||
|
||||
# Result (temp display)
|
||||
print(article_bottom)
|
||||
|
||||
# Get article DB in html.py
|
||||
html.set_page(tyto.post_db)
|
||||
print(html.main_page)
|
||||
|
||||
# Replace in DB hash_wip and date_wip
|
||||
tyto.replace_in_db(tyto.post_db, 'wip', tyto.hash_post)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue